/[projects]/smsdaemon/ConfigFile.cpp
ViewVC logotype

Diff of /smsdaemon/ConfigFile.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 146 by torben, Sun Dec 7 20:06:12 2008 UTC revision 202 by torben, Thu Dec 18 23:29:23 2008 UTC
# Line 1  Line 1 
1  #include "ConfigFile.h"  #include "ConfigFile.h"
2    
3  #include <fstream>  #include <fstream>
4    #include <sstream>
5    
6  const char SEPERATOR = '/';  const char SEPERATOR = '/';
7    
# Line 61  bool ConfigFile::Open(std::string const& Line 62  bool ConfigFile::Open(std::string const&
62                  name  = trim(line.substr(0,posEqual));                  name  = trim(line.substr(0,posEqual));
63                  value = trim(line.substr(posEqual+1));                  value = trim(line.substr(posEqual+1));
64    
65                    content_.insert(std::make_pair(inSection+SEPERATOR+name,Value(value)));
                 content_[inSection+SEPERATOR+name]=Value(value);  
66          }          }
67          return true;          return true;
68  }  }
# Line 70  bool ConfigFile::Open(std::string const& Line 70  bool ConfigFile::Open(std::string const&
70  Value const& ConfigFile::GetValue(std::string const& section, std::string const& entry) const  Value const& ConfigFile::GetValue(std::string const& section, std::string const& entry) const
71  {  {
72    
73          std::map<std::string,Value>::const_iterator ci = content_.find(section + SEPERATOR + entry);          content_iterator ci = content_.find(section + SEPERATOR + entry);
74    
75          if (ci == content_.end()) throw "does not exist";          if (ci == content_.end()) throw "does not exist";
76    
77          return ci->second;          return ci->second;
78  }  }
79    
80    std::vector<Value> ConfigFile::GetValues(std::string const& section, std::string const& entry) const
81    {
82            std::vector<Value> values;
83            std::string search = section + SEPERATOR + entry;
84            std::pair<content_iterator, content_iterator> range = content_.equal_range(search);
85    
86            for (content_iterator it=range.first; it != range.second; ++it)
87            {
88                    values.push_back( it->second );
89            }
90            return values;
91    }
92    
93  Value const& ConfigFile::GetValue(std::string const& section, std::string const& entry, double value)  Value const& ConfigFile::GetValue(std::string const& section, std::string const& entry, double value)
94  {  {
95          try          try
# Line 85  Value const& ConfigFile::GetValue(std::s Line 98  Value const& ConfigFile::GetValue(std::s
98          }          }
99          catch (const char *)          catch (const char *)
100          {          {
101                  return content_.insert(std::make_pair(section+SEPERATOR+entry, Value(value))).first->second;                  return content_.insert(std::make_pair(section+SEPERATOR+entry, Value(value)))->second;
102          }          }
103  }  }
104    
# Line 97  Value const& ConfigFile::GetValue(std::s Line 110  Value const& ConfigFile::GetValue(std::s
110          }          }
111          catch (const char *)          catch (const char *)
112          {          {
113                  return content_.insert(std::make_pair(section+SEPERATOR+entry, Value(value))).first->second;                  return content_.insert(std::make_pair(section+SEPERATOR+entry, Value(value)))->second;
114          }          }
115  }  }
116    
117    std::string ConfigFile::DumpConfig() const
118    {
119            std::ostringstream ss;  
120            for (content_iterator it=content_.begin(); it!=content_.end(); ++it)
121            {
122                    ss << it->first << "=" << it->second.StringValue() << std::endl;
123            }
124            return ss.str();
125    }

Legend:
Removed from v.146  
changed lines
  Added in v.202

  ViewVC Help
Powered by ViewVC 1.1.20