17 void config::Configuration::Clear()
22 bool config::Configuration::Load(
const string& file)
24 ifstream inFile(file.c_str());
28 cout <<
"Cannot read configuration file " << file << endl;
32 while (inFile.good() && ! inFile.eof())
35 getline(inFile, line);
40 int pos = line.find(
'#');
42 if (pos != string::npos)
44 line = line.substr(0, pos);
51 int pos = line.find(
'=');
53 if (pos != string::npos)
55 string key = Trim(line.substr(0, pos));
56 string value = Trim(line.substr(pos + 1));
58 if (!key.empty() && !value.empty())
69 bool config::Configuration::Contains(
const string& key)
const 71 return data.find(key) != data.end();
74 bool config::Configuration::Get(
const string& key,
string& value)
const 76 map<string,string>::const_iterator iter = data.find(key);
78 if (iter != data.end())
89 bool config::Configuration::Get(
const string& key,
int& value)
const 95 value = atoi(str.c_str());
104 bool config::Configuration::Get(
const string& key,
long& value)
const 110 value = atol(str.c_str());
119 bool config::Configuration::Get(
const string& key,
double& value)
const 125 value = atof(str.c_str());
134 bool config::Configuration::Get(
const string& key,
bool& value)
const 140 value = (str ==
"true");
149 string config::Configuration::Trim(
const string& str)
151 int first = str.find_first_not_of(
" \t");
153 if (first != string::npos)
155 int last = str.find_last_not_of(
" \t");
157 return str.substr(first, last - first + 1);
Implementation of the Configuration class used to parse the configuration file and the sConfig struct...