diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2012-02-06 12:37:49 -0500 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2012-02-07 09:14:31 -0500 |
commit | 3ae0735553e078bcedffd0a657bee106ab79a5d4 (patch) | |
tree | aae8ef122e0956fa200c9c1a6f8adf3ef1673e37 /src/util.h | |
parent | 0b452dff5e9f1401343b6c52ef739014d81fa8c6 (diff) |
Unit tests for the GetArg() methods
Diffstat (limited to 'src/util.h')
-rw-r--r-- | src/util.h | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/util.h b/src/util.h index 8f86ba0180..20fdb36fe6 100644 --- a/src/util.h +++ b/src/util.h @@ -143,7 +143,7 @@ std::vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid = NULL); std::string DecodeBase64(const std::string& str); std::string EncodeBase64(const unsigned char* pch, size_t len); std::string EncodeBase64(const std::string& str); -void ParseParameters(int argc, char* argv[]); +void ParseParameters(int argc, const char*const argv[]); bool WildcardMatch(const char* psz, const char* mask); bool WildcardMatch(const std::string& str, const std::string& mask); int GetFilesize(FILE* file); @@ -401,30 +401,32 @@ inline bool IsSwitchChar(char c) #endif } -inline std::string GetArg(const std::string& strArg, const std::string& strDefault) -{ - if (mapArgs.count(strArg)) - return mapArgs[strArg]; - return strDefault; -} +/** + * Return string argument or default value + * + * @param strArg Argument to get (e.g. "-foo") + * @param default (e.g. "1") + * @return command-line argument or default value + */ +std::string GetArg(const std::string& strArg, const std::string& strDefault); -inline int64 GetArg(const std::string& strArg, int64 nDefault) -{ - if (mapArgs.count(strArg)) - return atoi64(mapArgs[strArg]); - return nDefault; -} +/** + * Return integer argument or default value + * + * @param strArg Argument to get (e.g. "-foo") + * @param default (e.g. 1) + * @return command-line argument (0 if invalid number) or default value + */ +int64 GetArg(const std::string& strArg, int64 nDefault); -inline bool GetBoolArg(const std::string& strArg, bool fDefault=false) -{ - if (mapArgs.count(strArg)) - { - if (mapArgs[strArg].empty()) - return true; - return (atoi(mapArgs[strArg]) != 0); - } - return fDefault; -} +/** + * Return boolean argument or default value + * + * @param strArg Argument to get (e.g. "-foo") + * @param default (true or false) + * @return command-line argument or default value + */ +bool GetBoolArg(const std::string& strArg, bool fDefault=false); /** * Set an argument if it doesn't already have a value |