64 #ifndef CONFIGFILE_HPP 65 #define CONFIGFILE_HPP 94 if (myKey.empty())
return "";
96 if (myKey.size() > 0) {
114 mySortVector = vVector;
141 typedef std::map<string, string>::iterator
mapi;
142 typedef std::map<string, string>::const_iterator
mapci;
143 typedef std::map<string, map<string, string> >::const_iterator
mapciSect;
149 string filepath =
"../config/",
150 string delimiter =
"=",
151 string comment =
"#",
152 string sectionStartTag =
"[",
153 string sectionEndTag =
"]",
154 string sentry =
"EndConfigFile");
160 template<
class T> T read(
const string& key,
const T& value)
const;
163 template<
class T> T read(
const string& key)
const;
166 template<
class T> T read(
const string& sectionKey,
const string& key);
170 template<
class T>
bool readInto(T& var,
const string& key)
const;
172 template<
class T>
bool readInto(T& var,
const string& sectionKey,
const string& key);
175 bool readInto(T& var,
const string& key,
const T& value)
const;
178 template<
class T>
void add(
string key,
const T& value);
181 template<
class T>
void add(
string sectionKey,
string key,
const T& value);
185 void remove(
const string& key);
187 void remove(
const string& sectionKey,
const string& key);
196 bool keyExists(
const string& key)
const;
198 bool keyExists(
const string& sectionKey,
const string& key);
201 bool sectionExists(
const string& sectionKey);
220 string old = myDelimiter;
226 string old = myComment;
236 template<
class T>
static string T_as_string(
const T& t);
237 template<
class T>
static T string_as_T(
const string&
s);
238 static void trim(
string& s);
247 std::ostringstream ost;
258 std::istringstream ist(s);
265 inline string ConfigFile::string_as_T<string>(
const string&
s) {
273 inline bool ConfigFile::string_as_T<bool>(
const string&
s) {
279 for (string::iterator p = sup.begin(); p != sup.end(); ++p)
281 if (sup ==
string(
"FALSE") || sup == string(
"F") ||
282 sup == string(
"NO") || sup == string(
"N") ||
283 sup == string(
"0") || sup == string(
"NONE"))
290 mapci p = myContents.find(key);
292 return string_as_T<T > (p->second);
298 mapciSect sp = mySectionRelatedContents.find(sectionKey);
301 myContents = sp->second;
302 mapci p = myContents.find(key);
304 return string_as_T<T > (p->second);
311 mapci p = myContents.find(key);
312 if (p == myContents.end())
return value;
313 return string_as_T<T > (p->second);
322 mapci p = myContents.find(key);
323 bool found = (p != myContents.end());
325 var = string_as_T<T > (p->second);
338 mapciSect sp = mySectionRelatedContents.find(sectionKey);
342 myContents = sp->second;
344 mapci p = myContents.find(key);
345 bool found = (p != myContents.end());
347 var = string_as_T<T > (p->second);
357 string v = T_as_string(value);
361 mapi p = myContents.find(key);
362 if (p != myContents.end()) {
374 string v = T_as_string(value);
378 mapciSect sp = mySectionRelatedContents.find(sectionKey);
381 if (sp == mySectionRelatedContents.end()) {
383 vector<string> vNewVal;
384 map<string, string> newMap;
387 vNewVal.push_back(key);
389 mySectionRelatedContents[sectionKey] = newMap;
394 myContents = sp->second;
397 mapi p = myContents.find(key);
398 if (p != myContents.end()) {
403 mySectionRelatedContents[sectionKey] = myContents;
405 for (
unsigned int i = 0; i <
mySortVector.size(); i++) {
409 sortVec.push_back(key);
423 #endif // CONFIGFILE_HPP std::istream & operator>>(std::istream &is, ConfigFile &cf)
void setKey(const string &sKey)
vector< string > mySortVector
std::ostream & operator<<(std::ostream &os, ConfigFile &cf)
std::map< string, std::map< string, string > > mySectionRelatedContents
T read(const string &key, const T &value) const
static T string_as_T(const string &s)
Reads and writes a configuration file.
std::vector< SortTreeVector > mySortVector
string getComment() const
std::map< string, string >::const_iterator mapci
void add(string key, const T &value)
Keep track of sortorder from original configfile.
string setComment(const string &s)
std::vector< string > getVector() const
bool readInto(T &var, const string &key) const
SortTreeVector * mySortVectorObj
string getDelimiter() const
Key in configuration file not found exception.
string setDelimiter(const string &s)
std::map< string, string > myContents
void setVector(const std::vector< string > &vVector)
std::map< string, string >::iterator mapi
static string T_as_string(const T &t)
std::map< string, map< string, string > >::const_iterator mapciSect