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.cpp | |
parent | 0b452dff5e9f1401343b6c52ef739014d81fa8c6 (diff) |
Unit tests for the GetArg() methods
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/util.cpp b/src/util.cpp index 049297706c..b4f8543566 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -454,7 +454,7 @@ vector<unsigned char> ParseHex(const string& str) return ParseHex(str.c_str()); } -void ParseParameters(int argc, char* argv[]) +void ParseParameters(int argc, const char*const argv[]) { mapArgs.clear(); mapMultiArgs.clear(); @@ -480,6 +480,31 @@ void ParseParameters(int argc, char* argv[]) } } +std::string GetArg(const std::string& strArg, const std::string& strDefault) +{ + if (mapArgs.count(strArg)) + return mapArgs[strArg]; + return strDefault; +} + +int64 GetArg(const std::string& strArg, int64 nDefault) +{ + if (mapArgs.count(strArg)) + return atoi64(mapArgs[strArg]); + return nDefault; +} + +bool GetBoolArg(const std::string& strArg, bool fDefault) +{ + if (mapArgs.count(strArg)) + { + if (mapArgs[strArg].empty()) + return true; + return (atoi(mapArgs[strArg]) != 0); + } + return fDefault; +} + bool SoftSetArg(const std::string& strArg, const std::string& strValue) { if (mapArgs.count(strArg)) |