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

Diff of /smsdaemon/ConfigFile.cpp

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

revision 202 by torben, Thu Dec 18 23:29:23 2008 UTC revision 205 by torben, Fri Dec 19 22:29:25 2008 UTC
# Line 1  Line 1 
1  #include "ConfigFile.h"  #include "ConfigFile.h"
2    #include "Util.h"
3    
4  #include <fstream>  #include <fstream>
5  #include <sstream>  #include <sstream>
6    #include <stdexcept>
7    
8    #include <stdlib.h>
9    
10  const char SEPERATOR = '/';  const char SEPERATOR = '/';
11    
# Line 123  std::string ConfigFile::DumpConfig() con Line 127  std::string ConfigFile::DumpConfig() con
127          }          }
128          return ss.str();          return ss.str();
129  }  }
130    
131    
132    namespace ConfigHelper
133    {
134        std::map<std::string, std::string> ParseArguments(const std::string& args)
135            {
136                    std::map<std::string, std::string> config;
137    
138                    std::vector<std::string> sections = Util::str_split(args, ";");
139    
140                    for (unsigned i=0; i<sections.size(); i++)
141                    {
142                            std::string current = Util::str_trim(sections[i]);
143                            std::vector<std::string> params = Util::str_split( current, "=");
144                            if (params.size() != 2)
145                                    throw std::runtime_error(std::string("syntax error in config line: ") + args);
146    
147                            std::string key = Util::str_tolower(Util::str_trim(params[0]));
148                            std::string val = Util::str_trim(params[1]);
149                            config[key] = val;
150                    }
151            
152                    return config;
153            }
154    
155            int StringToInt(const std::string& input)
156            {
157                    char* endptr = (char*) input.c_str();
158                    int retval = strtol(input.c_str(), &endptr, 10);
159    
160                    if ( *endptr != 0)
161                            throw std::runtime_error( std::string("Error: can not convert this to a number: ") + input);
162    
163                    return retval;
164            }
165    }

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

  ViewVC Help
Powered by ViewVC 1.1.20