From 0c782c61b8daacd0c8fa00de899780cc7bca6c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Kubern=C3=A1t?= Date: Mon, 25 Nov 2024 16:47:45 +0100 Subject: [PATCH] Pass arguments by reference --- .../cli/minimalshvclient/src/application.cpp | 4 ++-- .../cli/minimalshvclient/src/application.h | 4 ++-- libshvbroker/include/shv/broker/brokerapp.h | 2 +- libshvbroker/src/brokeraclnode.cpp | 2 +- libshvbroker/src/brokeraclnode.h | 2 +- libshvbroker/src/brokerapp.cpp | 2 +- .../include/shv/chainpack/irpcconnection.h | 20 ++++++++-------- .../include/shv/chainpack/metamethod.h | 10 ++++---- .../include/shv/chainpack/rpcmessage.h | 2 +- libshvchainpack/src/irpcconnection.cpp | 24 +++++++++---------- libshvchainpack/src/metamethod.cpp | 10 ++++---- libshvchainpack/src/rpcmessage.cpp | 2 +- .../include/shv/core/utils/clioptions.h | 4 ++-- libshvcore/include/shv/core/utils/crypt.h | 4 ++-- .../include/shv/core/utils/shvfilejournal.h | 2 +- .../include/shv/core/utils/shvjournalentry.h | 12 +++++----- .../include/shv/core/utils/shvtypeinfo.h | 4 ++-- libshvcore/src/utils/clioptions.cpp | 4 ++-- libshvcore/src/utils/crypt.cpp | 4 ++-- libshvcore/src/utils/shvfilejournal.cpp | 2 +- libshvcore/src/utils/shvjournalentry.cpp | 18 +++++++------- libshvcore/src/utils/shvtypeinfo.cpp | 4 ++-- libshviotqt/include/shv/iotqt/node/shvnode.h | 6 ++--- libshviotqt/include/shv/iotqt/rpc/rpccall.h | 8 +++---- libshviotqt/src/acl/aclroleaccessrules.cpp | 2 +- libshviotqt/src/node/shvnode.cpp | 6 ++--- libshviotqt/src/rpc/rpccall.cpp | 8 +++---- .../shv/visu/logview/dlgloginspector.h | 4 ++-- .../shv/visu/svgscene/simpletextitem.h | 2 +- .../include/shv/visu/timeline/graphmodel.h | 2 +- libshvvisu/src/logview/dlgloginspector.cpp | 4 ++-- libshvvisu/src/svgscene/simpletextitem.cpp | 2 +- libshvvisu/src/timeline/graphmodel.cpp | 2 +- 33 files changed, 94 insertions(+), 94 deletions(-) diff --git a/examples/cli/minimalshvclient/src/application.cpp b/examples/cli/minimalshvclient/src/application.cpp index 71d2d2963..e333e6cef 100644 --- a/examples/cli/minimalshvclient/src/application.cpp +++ b/examples/cli/minimalshvclient/src/application.cpp @@ -76,8 +76,8 @@ void Application::unsubscribeChanges(const string &shv_path) } void Application::callShvMethod(const std::string &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const QObject *context - , std::function success_callback - , std::function error_callback) + , const std::function& success_callback + , const std::function& error_callback) { auto *rpcc = RpcCall::create(m_rpcConnection) ->setShvPath(shv_path) diff --git a/examples/cli/minimalshvclient/src/application.h b/examples/cli/minimalshvclient/src/application.h index c4447ace7..5f729a880 100644 --- a/examples/cli/minimalshvclient/src/application.h +++ b/examples/cli/minimalshvclient/src/application.h @@ -15,8 +15,8 @@ class Application : public QCoreApplication private: void callShvMethod(const std::string &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const QObject *context = nullptr, - std::function success_callback = nullptr, - std::function error_callback = nullptr); + const std::function& success_callback = nullptr, + const std::function& error_callback = nullptr); void subscribeChanges(const std::string &shv_path); void unsubscribeChanges(const std::string &shv_path); void onRpcMessageReceived(const shv::chainpack::RpcMessage &msg); diff --git a/libshvbroker/include/shv/broker/brokerapp.h b/libshvbroker/include/shv/broker/brokerapp.h index c518dc47d..dc17fc54b 100644 --- a/libshvbroker/include/shv/broker/brokerapp.h +++ b/libshvbroker/include/shv/broker/brokerapp.h @@ -98,7 +98,7 @@ class SHVBROKER_DECL_EXPORT BrokerApp : public QCoreApplication void reloadConfigRemountDevices(); bool checkTunnelSecret(const std::string &s); - void checkLogin(const chainpack::UserLoginContext &ctx, const QObject* connection_ctx, const std::function cb); + void checkLogin(const chainpack::UserLoginContext &ctx, const QObject* connection_ctx, const std::function& cb); void sendNewLogEntryNotify(const std::string &msg); diff --git a/libshvbroker/src/brokeraclnode.cpp b/libshvbroker/src/brokeraclnode.cpp index 56858f826..eed0bcf02 100644 --- a/libshvbroker/src/brokeraclnode.cpp +++ b/libshvbroker/src/brokeraclnode.cpp @@ -138,7 +138,7 @@ const chainpack::MetaMethod *BrokerAclNode::metaMethod(const iotqt::node::ShvNod SHV_EXCEPTION("Invalid method index: " + std::to_string(ix) + " on shv path: " + shv_path.join('/')); } -std::string BrokerAclNode::saveConfigFile(const std::string &file_name, const chainpack::RpcValue val) +std::string BrokerAclNode::saveConfigFile(const std::string &file_name, const chainpack::RpcValue& val) { BrokerApp *app = BrokerApp::instance(); std::string fn = app->cliOptions()->configDir() + '/' + file_name; diff --git a/libshvbroker/src/brokeraclnode.h b/libshvbroker/src/brokeraclnode.h index 337d2afcd..686a37f26 100644 --- a/libshvbroker/src/brokeraclnode.h +++ b/libshvbroker/src/brokeraclnode.h @@ -31,7 +31,7 @@ class BrokerAclNode : public shv::iotqt::node::MethodsTableNode size_t methodCount(const StringViewList &shv_path) override; const shv::chainpack::MetaMethod* metaMethod(const StringViewList &shv_path, size_t ix) override; - std::string saveConfigFile(const std::string &file_name, const shv::chainpack::RpcValue val); + std::string saveConfigFile(const std::string &file_name, const shv::chainpack::RpcValue& val); }; class MountsAclNode : public BrokerAclNode diff --git a/libshvbroker/src/brokerapp.cpp b/libshvbroker/src/brokerapp.cpp index 17e164ffa..ec13a67e7 100644 --- a/libshvbroker/src/brokerapp.cpp +++ b/libshvbroker/src/brokerapp.cpp @@ -816,7 +816,7 @@ class AzureAuth : public QObject { }; #endif -void BrokerApp::checkLogin(const chainpack::UserLoginContext &ctx, const QObject* connection_ctx, const std::function cb) +void BrokerApp::checkLogin(const chainpack::UserLoginContext &ctx, const QObject* connection_ctx, const std::function& cb) { if (ctx.userLogin().loginType == chainpack::UserLogin::LoginType::AzureAccessToken && m_azureConfig) { #if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) diff --git a/libshvchainpack/include/shv/chainpack/irpcconnection.h b/libshvchainpack/include/shv/chainpack/irpcconnection.h index d842fa4be..f669ec016 100644 --- a/libshvchainpack/include/shv/chainpack/irpcconnection.h +++ b/libshvchainpack/include/shv/chainpack/irpcconnection.h @@ -38,16 +38,16 @@ class SHVCHAINPACK_DECL_EXPORT IRpcConnection void sendResponse(const shv::chainpack::RpcValue &request_id, const shv::chainpack::RpcValue &result); void sendError(const shv::chainpack::RpcValue &request_id, const shv::chainpack::RpcResponse::Error &error); int callMethod(const shv::chainpack::RpcRequest &rq); - int callShvMethod(const std::string &shv_path, std::string method, const shv::chainpack::RpcValue ¶ms = shv::chainpack::RpcValue()); - int callShvMethod(const std::string &shv_path, std::string method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id); - int callShvMethod(int rq_id, const std::string &shv_path, std::string method, const shv::chainpack::RpcValue ¶ms = shv::chainpack::RpcValue()); - int callShvMethod(int rq_id, const std::string &shv_path, std::string method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id); - - int callMethodSubscribeGlob(std::string glob); - int callMethodSubscribe(const std::string &shv_path, std::string method, const std::string& source = ""); - int callMethodSubscribe(int rq_id, const std::string &shv_path, std::string method, const std::string& source = ""); - int callMethodUnsubscribe(const std::string &shv_path, std::string method, const std::string& source = ""); - int callMethodUnsubscribe(int rq_id, const std::string &shv_path, std::string method, const std::string& source = ""); + int callShvMethod(const std::string &shv_path, const std::string& method, const shv::chainpack::RpcValue ¶ms = shv::chainpack::RpcValue()); + int callShvMethod(const std::string &shv_path, const std::string& method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id); + int callShvMethod(int rq_id, const std::string &shv_path, const std::string& method, const shv::chainpack::RpcValue ¶ms = shv::chainpack::RpcValue()); + int callShvMethod(int rq_id, const std::string &shv_path, const std::string& method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id); + + int callMethodSubscribeGlob(const std::string& glob); + int callMethodSubscribe(const std::string &shv_path, const std::string& method, const std::string& source = ""); + int callMethodSubscribe(int rq_id, const std::string &shv_path, const std::string& method, const std::string& source = ""); + int callMethodUnsubscribe(const std::string &shv_path, const std::string& method, const std::string& source = ""); + int callMethodUnsubscribe(int rq_id, const std::string &shv_path, const std::string& method, const std::string& source = ""); protected: static int nextConnectionId(); protected: diff --git a/libshvchainpack/include/shv/chainpack/metamethod.h b/libshvchainpack/include/shv/chainpack/metamethod.h index 3ab32e90f..c685f50db 100644 --- a/libshvchainpack/include/shv/chainpack/metamethod.h +++ b/libshvchainpack/include/shv/chainpack/metamethod.h @@ -35,17 +35,17 @@ class SHVCHAINPACK_DECL_EXPORT MetaMethod static constexpr auto KEY_SIGNALS = "signals"; public: struct SHVCHAINPACK_DECL_EXPORT Signal { - Signal(std::string name, std::optional param_type = {}); + Signal(const std::string& name, const std::optional& param_type = {}); std::string name; std::optional param_type; }; MetaMethod(); MetaMethod( - std::string name, + const std::string& name, unsigned flags = 0, - std::optional param = {}, - std::optional result = {}, + const std::optional& param = {}, + const std::optional& result = {}, AccessLevel access_level = AccessLevel::Browse, const std::vector& signal_definitions = {}, const std::string& description = {}, @@ -53,7 +53,7 @@ class SHVCHAINPACK_DECL_EXPORT MetaMethod const RpcValue::Map& extra = {}); // SHV 2 compatibility constructor - MetaMethod(std::string name, + MetaMethod(const std::string& name, Signature signature, unsigned flags, const std::string &access_grant, diff --git a/libshvchainpack/include/shv/chainpack/rpcmessage.h b/libshvchainpack/include/shv/chainpack/rpcmessage.h index 79b8bc0bb..58082a18d 100644 --- a/libshvchainpack/include/shv/chainpack/rpcmessage.h +++ b/libshvchainpack/include/shv/chainpack/rpcmessage.h @@ -197,7 +197,7 @@ class SHVCHAINPACK_DECL_EXPORT RpcSignal : public RpcRequest public: RpcRequest& setRequestId(const RpcValue::Int requestId) = delete; - static void write(AbstractStreamWriter &wr, const std::string &method, std::function write_params_callback); + static void write(AbstractStreamWriter &wr, const std::string &method, const std::function& write_params_callback); }; class SHVCHAINPACK_DECL_EXPORT RpcException : public Exception diff --git a/libshvchainpack/src/irpcconnection.cpp b/libshvchainpack/src/irpcconnection.cpp index e20f871c6..b2117ad19 100644 --- a/libshvchainpack/src/irpcconnection.cpp +++ b/libshvchainpack/src/irpcconnection.cpp @@ -73,27 +73,27 @@ int IRpcConnection::callMethod(const RpcRequest &rq) return id; } -int IRpcConnection::callShvMethod(const std::string &shv_path, std::string method, const RpcValue ¶ms) +int IRpcConnection::callShvMethod(const std::string &shv_path, const std::string& method, const RpcValue ¶ms) { return callShvMethod(shv_path, method, params, {}); } -int IRpcConnection::callShvMethod(const std::string &shv_path, std::string method, const RpcValue ¶ms, const RpcValue &user_id) +int IRpcConnection::callShvMethod(const std::string &shv_path, const std::string& method, const RpcValue ¶ms, const RpcValue &user_id) { int id = nextRequestId(); return callShvMethod(id, shv_path, method, params, user_id); } -int IRpcConnection::callShvMethod(int rq_id, const std::string &shv_path, std::string method, const RpcValue ¶ms) +int IRpcConnection::callShvMethod(int rq_id, const std::string &shv_path, const std::string& method, const RpcValue ¶ms) { return callShvMethod(rq_id, shv_path, method, params, {}); } -int IRpcConnection::callShvMethod(int rq_id, const std::string &shv_path, std::string method, const RpcValue ¶ms, const RpcValue &user_id) +int IRpcConnection::callShvMethod(int rq_id, const std::string &shv_path, const std::string& method, const RpcValue ¶ms, const RpcValue &user_id) { RpcRequest rq; rq.setRequestId(rq_id); - rq.setMethod(std::move(method)); + rq.setMethod(method); if(params.isValid()) rq.setParams(params); if(user_id.isValid()) @@ -104,7 +104,7 @@ int IRpcConnection::callShvMethod(int rq_id, const std::string &shv_path, std::s return rq_id; } -int IRpcConnection::callMethodSubscribeGlob(std::string glob) +int IRpcConnection::callMethodSubscribeGlob(const std::string& glob) { logSubscriptionsD() << "call subscribe for connection id:" << connectionId() << "glob:" << glob; int rq_id = nextRequestId(); @@ -119,13 +119,13 @@ int IRpcConnection::callMethodSubscribeGlob(std::string glob) return 0; } -int IRpcConnection::callMethodSubscribe(const std::string &shv_path, std::string method, const std::string& source) +int IRpcConnection::callMethodSubscribe(const std::string &shv_path, const std::string& method, const std::string& source) { int rq_id = nextRequestId(); return callMethodSubscribe(rq_id, shv_path, method, source); } -int IRpcConnection::callMethodSubscribe(int rq_id, const std::string &shv_path, std::string method, const std::string& source) +int IRpcConnection::callMethodSubscribe(int rq_id, const std::string &shv_path, const std::string& method, const std::string& source) { logSubscriptionsD() << "call subscribe for connection id:" << connectionId() << "path:" << shv_path << "method:" << method << "source:" << source; if(m_shvApiVersion == ShvApiVersion::V3) { @@ -142,18 +142,18 @@ int IRpcConnection::callMethodSubscribe(int rq_id, const std::string &shv_path, , Rpc::METH_SUBSCRIBE , RpcValue::Map{ {Rpc::PAR_PATH, shv_path}, - {Rpc::PAR_METHOD, std::move(method)}, + {Rpc::PAR_METHOD, method}, {Rpc::PAR_SOURCE, source}, }); } -int IRpcConnection::callMethodUnsubscribe(const std::string &shv_path, std::string method, const std::string& source) +int IRpcConnection::callMethodUnsubscribe(const std::string &shv_path, const std::string& method, const std::string& source) { int rq_id = nextRequestId(); return callMethodUnsubscribe(rq_id, shv_path, method, source); } -int IRpcConnection::callMethodUnsubscribe(int rq_id, const std::string &shv_path, std::string method, const std::string& source) +int IRpcConnection::callMethodUnsubscribe(int rq_id, const std::string &shv_path, const std::string& method, const std::string& source) { logSubscriptionsD() << "call unsubscribe for connection id:" << connectionId() << "path:" << shv_path << "method:" << method << "source:" << source; if(m_shvApiVersion == ShvApiVersion::V3) { @@ -170,7 +170,7 @@ int IRpcConnection::callMethodUnsubscribe(int rq_id, const std::string &shv_path , Rpc::METH_UNSUBSCRIBE , RpcValue::Map{ {Rpc::PAR_PATH, shv_path}, - {Rpc::PAR_METHOD, std::move(method)}, + {Rpc::PAR_METHOD, method}, {Rpc::PAR_SOURCE, source}, }); } diff --git a/libshvchainpack/src/metamethod.cpp b/libshvchainpack/src/metamethod.cpp index b761d08b8..ad10e50ca 100644 --- a/libshvchainpack/src/metamethod.cpp +++ b/libshvchainpack/src/metamethod.cpp @@ -9,7 +9,7 @@ constexpr auto KEY_ACCESSGRANT = "accessGrant"; constexpr auto VOID_TYPE_NAME = "Null"; } -MetaMethod::Signal::Signal(std::string _name, std::optional _param_type) +MetaMethod::Signal::Signal(const std::string& _name, const std::optional& _param_type) : name(_name) , param_type(_param_type) { @@ -17,10 +17,10 @@ MetaMethod::Signal::Signal(std::string _name, std::optional _param_ MetaMethod::MetaMethod() = default; -MetaMethod::MetaMethod(std::string name, +MetaMethod::MetaMethod(const std::string& name, unsigned flags, - std::optional param, - std::optional result, + const std::optional& param, + const std::optional& result, AccessLevel access_level, const std::vector& signal_definitions, const std::string& description, @@ -41,7 +41,7 @@ MetaMethod::MetaMethod(std::string name, } } -MetaMethod::MetaMethod(std::string name, +MetaMethod::MetaMethod(const std::string& name, Signature signature, unsigned int flags, const std::string &access_grant, diff --git a/libshvchainpack/src/rpcmessage.cpp b/libshvchainpack/src/rpcmessage.cpp index 27e44354b..5ea656c38 100644 --- a/libshvchainpack/src/rpcmessage.cpp +++ b/libshvchainpack/src/rpcmessage.cpp @@ -718,7 +718,7 @@ RpcSignal::RpcSignal(const RpcMessage &msg) RpcSignal::~RpcSignal() = default; -void RpcSignal::write(AbstractStreamWriter &wr, const std::string &method, std::function write_params_callback) +void RpcSignal::write(AbstractStreamWriter &wr, const std::string &method, const std::function& write_params_callback) { RpcValue::MetaData md; md.setMetaTypeId(RpcMessage::MetaType::ID); diff --git a/libshvcore/include/shv/core/utils/clioptions.h b/libshvcore/include/shv/core/utils/clioptions.h index d64e2abcd..1de591305 100644 --- a/libshvcore/include/shv/core/utils/clioptions.h +++ b/libshvcore/include/shv/core/utils/clioptions.h @@ -95,11 +95,11 @@ class SHVCORE_DECL_EXPORT CLIOptions bool optionExists(const std::string &name) const; chainpack::RpcValue::Map values() const; chainpack::RpcValue value(const std::string &name) const; - chainpack::RpcValue value(const std::string &name, const chainpack::RpcValue default_value) const; + chainpack::RpcValue value(const std::string &name, const chainpack::RpcValue& default_value) const; /// value is explicitly set from command line or in config file /// defaultValue is not considered to be an explicitly set value bool isValueSet(const std::string &name) const; - bool setValue(const std::string &name, const chainpack::RpcValue val, bool throw_exc = true); + bool setValue(const std::string &name, const chainpack::RpcValue& val, bool throw_exc = true); protected: chainpack::RpcValue value_helper(const std::string &name, bool throw_exception) const; std::tuple applicationDirAndName() const; diff --git a/libshvcore/include/shv/core/utils/crypt.h b/libshvcore/include/shv/core/utils/crypt.h index f0e54571c..ca665048a 100644 --- a/libshvcore/include/shv/core/utils/crypt.h +++ b/libshvcore/include/shv/core/utils/crypt.h @@ -16,12 +16,12 @@ class SHVCORE_DECL_EXPORT Crypt public: using Generator = std::function< uint32_t (uint32_t) >; public: - Crypt(Generator gen = nullptr); + Crypt(const Generator& gen = nullptr); public: static Generator createGenerator(uint32_t a, uint32_t b, uint32_t max_rand); /// any of function, functor or lambda can be set as a random number generator - void setGenerator(Generator gen); + void setGenerator(const Generator& gen); /// @a min_length minimal length of digest /// @return string crypted by 0-9, A-Z, a-z characters diff --git a/libshvcore/include/shv/core/utils/shvfilejournal.h b/libshvcore/include/shv/core/utils/shvfilejournal.h index 714ab724f..1488d5336 100644 --- a/libshvcore/include/shv/core/utils/shvfilejournal.h +++ b/libshvcore/include/shv/core/utils/shvfilejournal.h @@ -20,7 +20,7 @@ class SHVCORE_DECL_EXPORT ShvFileJournal : public AbstractShvJournal static const std::string FILE_EXT; public: ShvFileJournal(); - ShvFileJournal(std::string device_id); + ShvFileJournal(const std::string& device_id); void setJournalDir(std::string s); const std::string& journalDir(); diff --git a/libshvcore/include/shv/core/utils/shvjournalentry.h b/libshvcore/include/shv/core/utils/shvjournalentry.h index 7db8dac88..58935d1fe 100644 --- a/libshvcore/include/shv/core/utils/shvjournalentry.h +++ b/libshvcore/include/shv/core/utils/shvjournalentry.h @@ -51,10 +51,10 @@ class SHVCORE_DECL_EXPORT ShvJournalEntry std::string userId; ShvJournalEntry(); - ShvJournalEntry(std::string path_, shv::chainpack::RpcValue value_, std::string domain_, int short_time, ValueFlags flags, int64_t epoch_msec = 0); - ShvJournalEntry(std::string path_, shv::chainpack::RpcValue value_); - ShvJournalEntry(std::string path_, shv::chainpack::RpcValue value_, int short_time); - ShvJournalEntry(std::string path_, shv::chainpack::RpcValue value_, std::string domain_); + ShvJournalEntry(const std::string& path_, const shv::chainpack::RpcValue& value_, const std::string& domain_, int short_time, ValueFlags flags, int64_t epoch_msec = 0); + ShvJournalEntry(const std::string& path_, const shv::chainpack::RpcValue& value_); + ShvJournalEntry(const std::string& path_, const shv::chainpack::RpcValue& value_, int short_time); + ShvJournalEntry(const std::string& path_, const shv::chainpack::RpcValue& value_, const std::string& domain_); bool isValid() const; bool isSpontaneous() const; @@ -65,13 +65,13 @@ class SHVCORE_DECL_EXPORT ShvJournalEntry void setShortTime(int short_time); shv::chainpack::RpcValue::DateTime dateTime() const; shv::chainpack::RpcValue toRpcValueMap() const; - shv::chainpack::RpcValue toRpcValueList(std::function< chainpack::RpcValue (const std::string &)> map_path = nullptr) const; + shv::chainpack::RpcValue toRpcValueList(const std::function< chainpack::RpcValue (const std::string &)>& map_path = nullptr) const; static bool isShvJournalEntry(const shv::chainpack::RpcValue &rv); shv::chainpack::RpcValue toRpcValue() const; static ShvJournalEntry fromRpcValue(const shv::chainpack::RpcValue &rv); static ShvJournalEntry fromRpcValueMap(const shv::chainpack::RpcValue::Map &m); - static ShvJournalEntry fromRpcValueList(const shv::chainpack::RpcList &row, std::function< std::string (const chainpack::RpcValue &)> unmap_path = nullptr, std::string *err = nullptr); + static ShvJournalEntry fromRpcValueList(const shv::chainpack::RpcList &row, const std::function< std::string (const chainpack::RpcValue &)>& unmap_path = nullptr, std::string *err = nullptr); shv::chainpack::DataChange toDataChange() const; }; diff --git a/libshvcore/include/shv/core/utils/shvtypeinfo.h b/libshvcore/include/shv/core/utils/shvtypeinfo.h index ab314c284..007de4f08 100644 --- a/libshvcore/include/shv/core/utils/shvtypeinfo.h +++ b/libshvcore/include/shv/core/utils/shvtypeinfo.h @@ -245,8 +245,8 @@ class SHVCORE_DECL_EXPORT ShvTypeInfo shv::chainpack::RpcValue applyTypeDescription(const shv::chainpack::RpcValue &val, const std::string &type_name, bool translate_enums = true, bool recursive_bitfields = true) const; shv::chainpack::RpcValue applyTypeDescription(const shv::chainpack::RpcValue &val, const ShvTypeDescr &type_descr, bool translate_enums = true, bool recursive_bitfields = true) const; - void forEachDeviceProperty(const std::string &device_type, std::function fn) const; - void forEachProperty(std::function fn) const; + void forEachDeviceProperty(const std::string &device_type, const std::function& fn) const; + void forEachProperty(const std::function& fn) const; private: static ShvTypeInfo fromNodesTree(const chainpack::RpcValue &v); void fromNodesTree_helper(const shv::chainpack::RpcValue::Map &node_types, diff --git a/libshvcore/src/utils/clioptions.cpp b/libshvcore/src/utils/clioptions.cpp index 6fc7ef41f..5178e4b1a 100644 --- a/libshvcore/src/utils/clioptions.cpp +++ b/libshvcore/src/utils/clioptions.cpp @@ -223,7 +223,7 @@ RpcValue CLIOptions::value(const std::string &name) const return ret; } -RpcValue CLIOptions::value(const std::string& name, const RpcValue default_value) const +RpcValue CLIOptions::value(const std::string& name, const RpcValue& default_value) const { RpcValue ret = value_helper(name, !shv::core::Exception::Throw); if(!ret.isValid()) @@ -254,7 +254,7 @@ bool CLIOptions::optionExists(const std::string &name) const return option(name, !shv::core::Exception::Throw).isValid(); } -bool CLIOptions::setValue(const std::string& name, const RpcValue val, bool throw_exc) +bool CLIOptions::setValue(const std::string& name, const RpcValue& val, bool throw_exc) { Option o = option(name, false); if(optionExists(name)) { diff --git a/libshvcore/src/utils/crypt.cpp b/libshvcore/src/utils/crypt.cpp index b3cacfc15..02a95811d 100644 --- a/libshvcore/src/utils/crypt.cpp +++ b/libshvcore/src/utils/crypt.cpp @@ -12,7 +12,7 @@ namespace shv::core::utils { // Crypt //=================================================================== /// http://www.math.utah.edu/~pa/Random/Random.html -Crypt::Crypt(Crypt::Generator gen) +Crypt::Crypt(const Crypt::Generator& gen) : m_generator(gen) { if(m_generator == nullptr) @@ -31,7 +31,7 @@ Crypt::Generator Crypt::createGenerator(uint32_t a, uint32_t b, uint32_t max_ran return ret; } -void Crypt::setGenerator(Generator gen) +void Crypt::setGenerator(const Generator& gen) { m_generator = gen; } diff --git a/libshvcore/src/utils/shvfilejournal.cpp b/libshvcore/src/utils/shvfilejournal.cpp index 25efaadf4..1e3e2f8b4 100644 --- a/libshvcore/src/utils/shvfilejournal.cpp +++ b/libshvcore/src/utils/shvfilejournal.cpp @@ -102,7 +102,7 @@ const std::string ShvFileJournal::FILE_EXT = ".log2"; ShvFileJournal::ShvFileJournal() = default; -ShvFileJournal::ShvFileJournal(std::string device_id) +ShvFileJournal::ShvFileJournal(const std::string& device_id) { setDeviceId(device_id); } diff --git a/libshvcore/src/utils/shvjournalentry.cpp b/libshvcore/src/utils/shvjournalentry.cpp index d119a77c0..5ba551d9d 100644 --- a/libshvcore/src/utils/shvjournalentry.cpp +++ b/libshvcore/src/utils/shvjournalentry.cpp @@ -13,26 +13,26 @@ ShvJournalEntry::MetaType::MetaType() //============================================================== ShvJournalEntry::ShvJournalEntry() = default; -ShvJournalEntry::ShvJournalEntry(std::string path_, shv::chainpack::RpcValue value_, std::string domain_, int short_time, ValueFlags flags, int64_t epoch_msec) +ShvJournalEntry::ShvJournalEntry(const std::string& path_, const shv::chainpack::RpcValue& value_, const std::string& domain_, int short_time, ValueFlags flags, int64_t epoch_msec) : epochMsec(epoch_msec) - , path(std::move(path_)) + , path(path_) , value{value_} , shortTime(short_time) - , domain(std::move(domain_)) + , domain(domain_) , valueFlags(flags) { } -ShvJournalEntry::ShvJournalEntry(std::string path_, shv::chainpack::RpcValue value_) +ShvJournalEntry::ShvJournalEntry(const std::string& path_, const shv::chainpack::RpcValue& value_) : ShvJournalEntry(path_, value_, DOMAIN_VAL_CHANGE, NO_SHORT_TIME, NO_VALUE_FLAGS) { } -ShvJournalEntry::ShvJournalEntry(std::string path_, shv::chainpack::RpcValue value_, int short_time) +ShvJournalEntry::ShvJournalEntry(const std::string& path_, const shv::chainpack::RpcValue& value_, int short_time) : ShvJournalEntry(path_, value_, DOMAIN_VAL_FASTCHANGE, short_time, NO_VALUE_FLAGS) { } -ShvJournalEntry::ShvJournalEntry(std::string path_, shv::chainpack::RpcValue value_, std::string domain_) - : ShvJournalEntry(path_, value_, std::move(domain_), NO_SHORT_TIME, NO_VALUE_FLAGS) +ShvJournalEntry::ShvJournalEntry(const std::string& path_, const shv::chainpack::RpcValue& value_, const std::string& domain_) + : ShvJournalEntry(path_, value_, domain_, NO_SHORT_TIME, NO_VALUE_FLAGS) { } @@ -67,7 +67,7 @@ chainpack::RpcValue ShvJournalEntry::toRpcValueMap() const return m; } -chainpack::RpcValue ShvJournalEntry::toRpcValueList(std::function< chainpack::RpcValue (const std::string &)> map_path) const +chainpack::RpcValue ShvJournalEntry::toRpcValueList(const std::function< chainpack::RpcValue (const std::string &)>& map_path) const { using namespace shv::chainpack; RpcList rec; @@ -122,7 +122,7 @@ ShvJournalEntry ShvJournalEntry::fromRpcValueMap(const chainpack::RpcValue::Map return ret; } -ShvJournalEntry ShvJournalEntry::fromRpcValueList(const chainpack::RpcList &row, std::function unmap_path, std::string *err) +ShvJournalEntry ShvJournalEntry::fromRpcValueList(const chainpack::RpcList &row, const std::function& unmap_path, std::string *err) { using Column = ShvLogHeader::Column; chainpack::RpcValue dt = row.value(Column::Timestamp); diff --git a/libshvcore/src/utils/shvtypeinfo.cpp b/libshvcore/src/utils/shvtypeinfo.cpp index a0453aa50..3765639de 100644 --- a/libshvcore/src/utils/shvtypeinfo.cpp +++ b/libshvcore/src/utils/shvtypeinfo.cpp @@ -1237,7 +1237,7 @@ RpcValue ShvTypeInfo::applyTypeDescription(const chainpack::RpcValue &val, const return val; } -void ShvTypeInfo::forEachDeviceProperty(const std::string &device_type, std::function fn) const +void ShvTypeInfo::forEachDeviceProperty(const std::string &device_type, const std::function& fn) const { auto it = m_deviceDescriptions.find(device_type); if( it == m_deviceDescriptions.end()) { @@ -1250,7 +1250,7 @@ void ShvTypeInfo::forEachDeviceProperty(const std::string &device_type, std::fun }; } -void ShvTypeInfo::forEachProperty(std::function fn) const +void ShvTypeInfo::forEachProperty(const std::function& fn) const { for(const auto& [device_path, device_type] : m_devicePaths) { if(auto it = m_deviceDescriptions.find(device_type); it != m_deviceDescriptions.end()) { diff --git a/libshviotqt/include/shv/iotqt/node/shvnode.h b/libshviotqt/include/shv/iotqt/node/shvnode.h index 81ab9882a..eed33a4ed 100644 --- a/libshviotqt/include/shv/iotqt/node/shvnode.h +++ b/libshviotqt/include/shv/iotqt/node/shvnode.h @@ -68,9 +68,9 @@ class SHVIOTQT_DECL_EXPORT ShvNode : public QObject static chainpack::AccessLevel basicGrantToAccessLevel(const chainpack::RpcValue &acces_grant); virtual chainpack::AccessLevel grantToAccessLevel(const chainpack::RpcValue &acces_grant) const; - void treeWalk(std::function callback); + void treeWalk(const std::function& callback); private: - static void treeWalk_helper(std::function callback, ShvNode *parent_nd, const StringViewList &shv_path); + static void treeWalk_helper(const std::function& callback, ShvNode *parent_nd, const StringViewList &shv_path); public: virtual size_t methodCount(const StringViewList &shv_path); virtual const shv::chainpack::MetaMethod* metaMethod(const StringViewList &shv_path, size_t ix); @@ -234,7 +234,7 @@ class SHVIOTQT_DECL_EXPORT ValueProxyShvNode : public shv::iotqt::node::ShvNode bool isReadable(); bool isSignal(); - Q_SLOT void onShvValueChanged(int value_id, shv::chainpack::RpcValue val); + Q_SLOT void onShvValueChanged(int value_id, const shv::chainpack::RpcValue& val); protected: int m_valueId; Type m_type; diff --git a/libshviotqt/include/shv/iotqt/rpc/rpccall.h b/libshviotqt/include/shv/iotqt/rpc/rpccall.h index 43155e635..04949a0a0 100644 --- a/libshviotqt/include/shv/iotqt/rpc/rpccall.h +++ b/libshviotqt/include/shv/iotqt/rpc/rpccall.h @@ -39,10 +39,10 @@ class SHVIOTQT_DECL_EXPORT RpcResponseCallBack : public QObject void start(); void start(int time_out); - void start(CallBackFunction cb); - void start(int time_out, CallBackFunction cb); - void start(QObject *context, CallBackFunction cb); - void start(int time_out_msec, QObject *context, CallBackFunction cb); + void start(const CallBackFunction& cb); + void start(int time_out, const CallBackFunction& cb); + void start(QObject *context, const CallBackFunction& cb); + void start(int time_out_msec, QObject *context, const CallBackFunction& cb); void abort(); virtual void onRpcMessageReceived(const shv::chainpack::RpcMessage &msg); private: diff --git a/libshviotqt/src/acl/aclroleaccessrules.cpp b/libshviotqt/src/acl/aclroleaccessrules.cpp index 03ed7a746..778006735 100644 --- a/libshviotqt/src/acl/aclroleaccessrules.cpp +++ b/libshviotqt/src/acl/aclroleaccessrules.cpp @@ -44,7 +44,7 @@ AclAccessRule AclAccessRule::fromRpcValue(const RpcValue &rpcval) } namespace { -bool is_wild_card_pattern(const string path) +bool is_wild_card_pattern(const string& path) { static const string ASTERISKS = "**"; static const string SLASH_ASTERISKS = "/**"; diff --git a/libshviotqt/src/node/shvnode.cpp b/libshviotqt/src/node/shvnode.cpp index 549f8aa87..d144e2b2d 100644 --- a/libshviotqt/src/node/shvnode.cpp +++ b/libshviotqt/src/node/shvnode.cpp @@ -367,12 +367,12 @@ AccessLevel ShvNode::grantToAccessLevel(const RpcValue &acces_grant) const return basicGrantToAccessLevel(acces_grant); } -void ShvNode::treeWalk(std::function callback) +void ShvNode::treeWalk(const std::function& callback) { treeWalk_helper(callback, this, {}); } -void ShvNode::treeWalk_helper(std::function callback, ShvNode *parent_nd, const ShvNode::StringViewList &shv_path) +void ShvNode::treeWalk_helper(const std::function& callback, ShvNode *parent_nd, const ShvNode::StringViewList &shv_path) { callback(parent_nd, shv_path); const auto child_names = parent_nd->childNames(shv_path); @@ -1024,7 +1024,7 @@ ValueProxyShvNode::ValueProxyShvNode(const std::string &node_id, int value_id, V } } -void ValueProxyShvNode::onShvValueChanged(int value_id, chainpack::RpcValue val) +void ValueProxyShvNode::onShvValueChanged(int value_id, const chainpack::RpcValue& val) { if(value_id == m_valueId && isSignal()) { RpcSignal sig; diff --git a/libshviotqt/src/rpc/rpccall.cpp b/libshviotqt/src/rpc/rpccall.cpp index a79f983ba..053aa098d 100644 --- a/libshviotqt/src/rpc/rpccall.cpp +++ b/libshviotqt/src/rpc/rpccall.cpp @@ -49,24 +49,24 @@ void RpcResponseCallBack::start(int time_out) start(); } -void RpcResponseCallBack::start(RpcResponseCallBack::CallBackFunction cb) +void RpcResponseCallBack::start(const RpcResponseCallBack::CallBackFunction& cb) { m_callBackFunction = cb; start(); } -void RpcResponseCallBack::start(int time_out, RpcResponseCallBack::CallBackFunction cb) +void RpcResponseCallBack::start(int time_out, const RpcResponseCallBack::CallBackFunction& cb) { setTimeout(time_out); start(cb); } -void RpcResponseCallBack::start(QObject *context, RpcResponseCallBack::CallBackFunction cb) +void RpcResponseCallBack::start(QObject *context, const RpcResponseCallBack::CallBackFunction& cb) { start(timeout(), context, cb); } -void RpcResponseCallBack::start(int time_out_msec, QObject *context, RpcResponseCallBack::CallBackFunction cb) +void RpcResponseCallBack::start(int time_out_msec, QObject *context, const RpcResponseCallBack::CallBackFunction& cb) { if(context) { connect(context, &QObject::destroyed, this, [this]() { diff --git a/libshvvisu/include/shv/visu/logview/dlgloginspector.h b/libshvvisu/include/shv/visu/logview/dlgloginspector.h index 642d2696f..d361873f4 100644 --- a/libshvvisu/include/shv/visu/logview/dlgloginspector.h +++ b/libshvvisu/include/shv/visu/logview/dlgloginspector.h @@ -42,10 +42,10 @@ class SHVVISU_DECL_EXPORT DlgLogInspector : public QDialog void saveSettings(); shv::chainpack::RpcValue getLogParams(); - void parseLog(shv::chainpack::RpcValue log); + void parseLog(const shv::chainpack::RpcValue& log); void showInfo(const QString &msg = QString(), bool is_error = false); - void saveData(const std::string &data, QString ext); + void saveData(const std::string &data, const QString& ext); std::string loadData(const QString &ext); #if SHVVISU_HAS_TIMEZONE diff --git a/libshvvisu/include/shv/visu/svgscene/simpletextitem.h b/libshvvisu/include/shv/visu/svgscene/simpletextitem.h index c83739638..420bdcb6b 100644 --- a/libshvvisu/include/shv/visu/svgscene/simpletextitem.h +++ b/libshvvisu/include/shv/visu/svgscene/simpletextitem.h @@ -12,7 +12,7 @@ class SHVVISU_DECL_EXPORT SimpleTextItem : public QGraphicsSimpleTextItem public: SimpleTextItem(const CssAttributes &css, QGraphicsItem *parent = nullptr); - void setText(const QString text); + void setText(const QString& text); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; private: int m_alignment = Qt::AlignLeft; diff --git a/libshvvisu/include/shv/visu/timeline/graphmodel.h b/libshvvisu/include/shv/visu/timeline/graphmodel.h index 2bceaa298..1ddc5ec89 100644 --- a/libshvvisu/include/shv/visu/timeline/graphmodel.h +++ b/libshvvisu/include/shv/visu/timeline/graphmodel.h @@ -77,7 +77,7 @@ class SHVVISU_DECL_EXPORT GraphModel : public QObject Q_SIGNAL void xRangeChanged(XRange range); Q_SIGNAL void channelCountChanged(qsizetype cnt); public: - static double valueToDouble(const QVariant v, core::utils::ShvTypeDescr::Type type_id = core::utils::ShvTypeDescr::Type::Invalid, bool *ok = nullptr); + static double valueToDouble(const QVariant& v, core::utils::ShvTypeDescr::Type type_id = core::utils::ShvTypeDescr::Type::Invalid, bool *ok = nullptr); protected: QString guessTypeName(qsizetype channel_ix) const; protected: diff --git a/libshvvisu/src/logview/dlgloginspector.cpp b/libshvvisu/src/logview/dlgloginspector.cpp index be85a2af3..b96847da0 100644 --- a/libshvvisu/src/logview/dlgloginspector.cpp +++ b/libshvvisu/src/logview/dlgloginspector.cpp @@ -354,7 +354,7 @@ void DlgLogInspector::downloadLog() conn->callShvMethod(rq_id, shv_path, cp::Rpc::METH_GET_LOG, params); } -void DlgLogInspector::parseLog(shv::chainpack::RpcValue log) +void DlgLogInspector::parseLog(const shv::chainpack::RpcValue& log) { { std::string str = log.metaData().toString("\t"); @@ -462,7 +462,7 @@ std::string DlgLogInspector::loadData(const QString &ext) return ""; } -void DlgLogInspector::saveData(const std::string &data_to_be_saved, QString ext) +void DlgLogInspector::saveData(const std::string &data_to_be_saved, const QString& ext) { QString fn = QFileDialog::getSaveFileName(this, tr("Savefile"), QString(), "*" + ext); if(fn.isEmpty()) diff --git a/libshvvisu/src/svgscene/simpletextitem.cpp b/libshvvisu/src/svgscene/simpletextitem.cpp index 715aa99bc..751266f25 100644 --- a/libshvvisu/src/svgscene/simpletextitem.cpp +++ b/libshvvisu/src/svgscene/simpletextitem.cpp @@ -16,7 +16,7 @@ SimpleTextItem::SimpleTextItem(const CssAttributes &css, QGraphicsItem *parent) m_alignment = Qt::AlignLeft; } -void SimpleTextItem::setText(const QString text) +void SimpleTextItem::setText(const QString& text) { if(!m_origTransformLoaded) { m_origTransformLoaded = true; diff --git a/libshvvisu/src/timeline/graphmodel.cpp b/libshvvisu/src/timeline/graphmodel.cpp index f5219d68e..092296222 100644 --- a/libshvvisu/src/timeline/graphmodel.cpp +++ b/libshvvisu/src/timeline/graphmodel.cpp @@ -106,7 +106,7 @@ shv::core::utils::ShvTypeDescr::Type qt_to_shv_type(int meta_type_id) } } -double GraphModel::valueToDouble(const QVariant v, shv::core::utils::ShvTypeDescr::Type type_id, bool *ok) +double GraphModel::valueToDouble(const QVariant& v, shv::core::utils::ShvTypeDescr::Type type_id, bool *ok) { using Type = shv::core::utils::ShvTypeDescr::Type; if(ok)