diff --git a/src/Rules.cpp b/src/Rules.cpp index 73d6dc64..3e4ce1ad 100644 --- a/src/Rules.cpp +++ b/src/Rules.cpp @@ -149,13 +149,17 @@ std::string Rules::get (const std::string& key) const } //////////////////////////////////////////////////////////////////////////////// -int Rules::getInteger (const std::string& key) const +int Rules::getInteger (const std::string& key, int defaultValue) const { auto found = _settings.find (key); - if (found != _settings.end ()) - return strtoimax (found->second.c_str (), nullptr, 10); + if (found != _settings.end ()) { + int tmp = strtoimax (found->second.c_str (), nullptr, 10); + // If conversion has performed, return the conversion. + if (tmp != 0) + return tmp; + } - return 0; + return defaultValue; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Rules.h b/src/Rules.h index cd07b568..9669c5dc 100644 --- a/src/Rules.h +++ b/src/Rules.h @@ -41,7 +41,7 @@ public: bool has (const std::string&) const; std::string get (const std::string&) const; - int getInteger (const std::string&) const; + int getInteger (const std::string&, int defaultValue = 0) const; double getReal (const std::string&) const; bool getBoolean (const std::string&) const;