Browse Source

Add Cfg::getIntOption method

Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/slim/trunk@204 7c53e7cc-98ea-0310-8f1f-a0b24da60408
iwamatsu 12 years ago
parent
commit
c2145c7444
2 changed files with 6 additions and 0 deletions
  1. 5 0
      cfg.cpp
  2. 1 0
      cfg.h

+ 5 - 0
cfg.cpp

@@ -229,6 +229,11 @@ int Cfg::string2int(const char* string, bool* ok) {
     return (*err == 0) ? l : 0;
 }
 
+int Cfg::getIntOption(std::string option, int defaultVal) {
+    int l = string2int(options[option].c_str());
+    return (l > 0) ? l : defaultVal;
+}
+
 // Get absolute position
 int Cfg::absolutepos(const string& position, int max, int width) {
     int n = -1;

+ 1 - 0
cfg.h

@@ -31,6 +31,7 @@ public:
     std::string parseOption(std::string line, std::string option);
     const std::string& getError() const;
     std::string& getOption(std::string option);
+    int getIntOption(std::string option, int defaultVal = 0);
     std::string getWelcomeMessage();
 
     static int absolutepos(const std::string& position, int max, int width);