120 AutoVal::operator std::string()
const {
124 AutoVal::operator double()
const {
125 return atof(m_value.c_str());
128 AutoVal::operator int()
const {
129 return atoi(m_value.c_str());
132 AutoVal::operator
unsigned int()
const {
133 return (
unsigned int) atoi(m_value.c_str());
136 AutoVal::operator bool()
const {
138 if (toLower(m_value)==
"on" || atoi(m_value.c_str()) == 1)
144 std::string result(source);
146 for (
unsigned int i=0; i<result.length(); i++) {
169 return read(std::string(configFile));
173 std::ifstream file(configFile.c_str());
175 if (!file || file.eof())
181 std::string inSection;
182 while (std::getline(file,line)) {
184 if (! line.length())
continue;
186 if (line[0] ==
'#')
continue;
187 line = truncate(line,
"#");
189 if (! line.length())
continue;
191 if (line[0] ==
'[') {
192 inSection=trim(line.substr(1,line.find(
']')-1));
196 istringstream lineStream(line);
199 insertValue(inSection,name,val);
205 m_content[toLower(section)+
'/'+toLower(entry)]=
AutoVal(thevalue);
210 std::map<std::string,AutoVal>::const_iterator ci =
211 m_content.find(toLower(section) +
'/' + toLower(entry));
212 if (ci == m_content.end())
throw "entry does not exist";
219 return value(section, entry);
220 }
catch(
const char *) {
221 return m_content.insert(std::make_pair(section+
'/'+entry,
AutoVal(def))).first->second;
227 return value(section, entry);
228 }
catch(
const char *) {
229 return m_content.insert(std::make_pair(section+
'/'+entry,
AutoVal(def))).first->second;
235 return value(section, entry);
236 }
catch(
const char *) {
237 return m_content.insert(std::make_pair(section+
'/'+entry,
AutoVal(def))).first->second;
243 return value(section, entry);
244 }
catch(
const char *) {
245 return m_content.insert(std::make_pair(section+
'/'+entry,
AutoVal(def))).first->second;
251 return value(section, entry);
252 }
catch(
const char *) {
253 return m_content.insert(std::make_pair(section+
'/'+entry,
AutoVal(def))).first->second;
259 return value(section, entry);
260 }
catch(
const char *) {
261 return m_content.insert(std::make_pair(section+
'/'+entry,
AutoVal(def))).first->second;
267 for (std::map<std::string,AutoVal>::const_iterator it = m_content.begin();
268 it != m_content.end(); it++) {
269 out << (std::string) it->first <<
" " << (std::string)it->second << std::endl;
275 std::string result(source);
276 std::string::size_type index = result.find_last_not_of(delims);
277 if(index != std::string::npos)
278 result.erase(++index);
280 index = result.find_first_not_of(delims);
281 if(index != std::string::npos)
282 result.erase(0, index);
289 std::string::size_type index = source.find_first_of(atChar);
293 else if(index == std::string::npos) {
297 source.substr(0,index);
301 std::string result(source);
303 for (
unsigned int i=0; i<result.length(); i++) {
std::string toLower(const std::string &source) const
std::string trim(const std::string &source, char const *delims=" \\) const
void dumpValues(std::ostream &out)
const AutoVal & value(const std::string §ion, const std::string &entry) const
std::string truncate(const std::string &source, const char *atChar) const
std::string toLower(const std::string &source) const
AutoVal & operator=(const AutoVal &)
bool read(const std::string &configFile)
void insertValue(const std::string §ion, const std::string &entry, const std::string &thevalue)