diff options
author | MarcoFalke <falke.marco@gmail.com> | 2017-08-16 15:59:26 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2017-08-16 16:09:27 +0200 |
commit | 22e301a3d56dc9e6878380ee92c7d19ca43119d2 (patch) | |
tree | 4cca907c6b5a338a4952054909e47f50dedf5dc4 /src/util.h | |
parent | c484ec6c9b85ca4e331e395c564ae232fd0681dd (diff) | |
parent | a622a1768325d01eeb16f42340cdd36e722a3fa8 (diff) |
Merge #10901: Fix constness of ArgsManager methods
a622a1768 Fix constness of ArgsManager methods (João Barbosa)
Pull request description:
Make `cs_args` mutex mutable so that const methods can acquire it.
There's also tiny performance improvement by avoiding two map lookups when retrieving an argument value.
Tree-SHA512: ece58469745f2743b4b643242b51889a3d9c5b76492ed70bb74d4e5b378fff59da79fc129e499da779bf9f488c9435dda17ad1f3a804c1c30f56af422389e8bd
Diffstat (limited to 'src/util.h')
-rw-r--r-- | src/util.h | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/util.h b/src/util.h index ead3d3d935..480a80c0a3 100644 --- a/src/util.h +++ b/src/util.h @@ -195,13 +195,20 @@ inline bool IsSwitchChar(char c) class ArgsManager { protected: - CCriticalSection cs_args; + mutable CCriticalSection cs_args; std::map<std::string, std::string> mapArgs; - std::map<std::string, std::vector<std::string> > mapMultiArgs; + std::map<std::string, std::vector<std::string>> mapMultiArgs; public: void ParseParameters(int argc, const char*const argv[]); void ReadConfigFile(const std::string& confPath); - std::vector<std::string> GetArgs(const std::string& strArg); + + /** + * Return a vector of strings of the given argument + * + * @param strArg Argument to get (e.g. "-foo") + * @return command-line arguments + */ + std::vector<std::string> GetArgs(const std::string& strArg) const; /** * Return true if the given argument has been manually set @@ -209,7 +216,7 @@ public: * @param strArg Argument to get (e.g. "-foo") * @return true if the argument has been set */ - bool IsArgSet(const std::string& strArg); + bool IsArgSet(const std::string& strArg) const; /** * Return string argument or default value @@ -218,7 +225,7 @@ public: * @param strDefault (e.g. "1") * @return command-line argument or default value */ - std::string GetArg(const std::string& strArg, const std::string& strDefault); + std::string GetArg(const std::string& strArg, const std::string& strDefault) const; /** * Return integer argument or default value @@ -227,7 +234,7 @@ public: * @param nDefault (e.g. 1) * @return command-line argument (0 if invalid number) or default value */ - int64_t GetArg(const std::string& strArg, int64_t nDefault); + int64_t GetArg(const std::string& strArg, int64_t nDefault) const; /** * Return boolean argument or default value @@ -236,7 +243,7 @@ public: * @param fDefault (true or false) * @return command-line argument or default value */ - bool GetBoolArg(const std::string& strArg, bool fDefault); + bool GetBoolArg(const std::string& strArg, bool fDefault) const; /** * Set an argument if it doesn't already have a value |