diff options
author | Chris Wilson <chris+github@qwirx.com> | 2010-06-06 15:12:20 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2010-06-06 15:12:20 +0000 |
commit | 03c09a7085382693f80a91aebb09b8ada429e704 (patch) | |
tree | 15aaee6f7b068f58016af2770a06bd4e81bb6df7 /lib/common | |
parent | 90ce1105466ef4f09c3370344c55ae9710d38f9f (diff) |
Add support for account numbers greater than 0x7fffffff without wrapping.
Diffstat (limited to 'lib/common')
-rw-r--r-- | lib/common/Configuration.cpp | 48 | ||||
-rw-r--r-- | lib/common/Configuration.h | 6 |
2 files changed, 51 insertions, 3 deletions
diff --git a/lib/common/Configuration.cpp b/lib/common/Configuration.cpp index 2eb5fbca..f49f3c6e 100644 --- a/lib/common/Configuration.cpp +++ b/lib/common/Configuration.cpp @@ -453,7 +453,8 @@ int Configuration::GetKeyValueInt(const std::string& rKeyName) const } else { - long value = ::strtol((i->second).c_str(), NULL, 0 /* C style handling */); + long value = ::strtol((i->second).c_str(), NULL, + 0 /* C style handling */); if(value == LONG_MAX || value == LONG_MIN) { THROW_EXCEPTION(CommonException, ConfigBadIntValue) @@ -466,6 +467,36 @@ int Configuration::GetKeyValueInt(const std::string& rKeyName) const // -------------------------------------------------------------------------- // // Function +// Name: Configuration::GetKeyValueUint32(const std::string& rKeyName) +// Purpose: Gets a key value as a 32-bit unsigned integer +// Created: 2003/07/23 +// +// -------------------------------------------------------------------------- +uint32_t Configuration::GetKeyValueUint32(const std::string& rKeyName) const +{ + std::map<std::string, std::string>::const_iterator i(mKeys.find(rKeyName)); + + if(i == mKeys.end()) + { + THROW_EXCEPTION(CommonException, ConfigNoKey) + } + else + { + errno = 0; + long value = ::strtoul((i->second).c_str(), NULL, + 0 /* C style handling */); + if(errno != 0) + { + THROW_EXCEPTION(CommonException, ConfigBadIntValue) + } + return (int)value; + } +} + + +// -------------------------------------------------------------------------- +// +// Function // Name: Configuration::GetKeyValueBool(const std::string&) // Purpose: Gets a key value as a boolean // Created: 17/2/04 @@ -680,6 +711,21 @@ bool Configuration::Verify(const ConfigurationVerify &rVerify, rErrorMsg += rLevel + mName + "." + pvkey->Name() + " (key) is not a valid integer.\n"; } } + + // Check it's a number? + if(pvkey->Flags() & ConfigTest_IsUint32) + { + // Test it... + char *end; + errno = 0; + uint32_t r = ::strtoul(val, &end, 0); + if(errno != 0 || end != (val + rval.size())) + { + // not a good value + ok = false; + rErrorMsg += rLevel + mName + "." + pvkey->Name() + " (key) is not a valid unsigned 32-bit integer.\n"; + } + } // Check it's a bool? if((pvkey->Flags() & ConfigTest_IsBool) == ConfigTest_IsBool) diff --git a/lib/common/Configuration.h b/lib/common/Configuration.h index 2babd753..4828b315 100644 --- a/lib/common/Configuration.h +++ b/lib/common/Configuration.h @@ -22,8 +22,9 @@ enum ConfigTest_LastEntry = 1, ConfigTest_Exists = 2, ConfigTest_IsInt = 4, - ConfigTest_MultiValueAllowed = 8, - ConfigTest_IsBool = 16 + ConfigTest_IsUint32 = 8, + ConfigTest_MultiValueAllowed = 16, + ConfigTest_IsBool = 32 }; class ConfigurationVerifyKey @@ -112,6 +113,7 @@ public: bool KeyExists(const std::string& rKeyName) const; const std::string &GetKeyValue(const std::string& rKeyName) const; int GetKeyValueInt(const std::string& rKeyName) const; + uint32_t GetKeyValueUint32(const std::string& rKeyName) const; bool GetKeyValueBool(const std::string& rKeyName) const; std::vector<std::string> GetKeyNames() const; |