62 typedef std::map<string,string>::iterator
mapi;
63 typedef std::map<string,string>::const_iterator
mapci;
71 string delimiter =
"=",
72 string comment =
"##",
73 string sentry =
"EndConfigFile" 78 template<
class T> T
read(
const string& key )
const;
79 template<
class T> T
read(
const string& key,
const T& value )
const;
80 template<
class T>
bool readInto( T& var,
const string& key )
const;
82 bool readInto( T& var,
const string& key,
const T& value )
const;
85 template<
class T>
void add(
string key,
const T& value ,
bool store=
false);
86 template<
class T>
void add(
const T& key ,
bool store=
false);
87 void remove(
const string& key );
88 template<
class T>
void remove(
const T& key );
91 bool keyExists(
const string& key )
const;
92 template<
class T>
bool keyExists(
const T & key)
const;
99 {
string old =
myDelimiter; myDelimiter = s;
return old; }
101 {
string old =
myComment; myComment = s;
return old; }
107 void load(
string filename,
bool isList=
false);
111 template<
class T>
static string T_as_string(
const T& t );
112 template<
class T>
static T
string_as_T(
const string& s );
113 static void trim(
string& s );
121 : filename(filename_) {} };
135 std::ostringstream ost;
148 std::istringstream ist(s);
156 inline string ConfigFile::string_as_T<string>(
const string& s )
166 inline bool ConfigFile::string_as_T<bool>(
const string& s )
173 for( string::iterator p = sup.begin(); p != sup.end(); ++p )
175 if( sup==
string(
"FALSE") || sup==string(
"F") ||
176 sup==string(
"NO") || sup==string(
"N") ||
177 sup==string(
"0") || sup==string(
"NONE") )
187 mapci p = myContents.find(key);
189 return string_as_T<T>( p->second );
198 mapci p = myContents.find(key);
199 if( p == myContents.end() )
return value;
200 return string_as_T<T>( p->second );
210 mapci p = myContents.find(key);
211 bool found = ( p != myContents.end() );
212 if( found ) var = string_as_T<T>( p->second );
223 mapci p = myContents.find(key);
224 bool found = ( p != myContents.end() );
226 var = string_as_T<T>( p->second );
244 std::ofstream os(file.c_str(),std::ios::app);
245 os << key <<
" " << myDelimiter <<
" ";
246 os << v << std::endl;
262 std::ofstream os(file.c_str(),std::ios::app);
263 os << v << std::endl;
276 myContents.erase( myContents.find( v ) );
285 mapci p = myContents.find( v );
286 return ( p != myContents.end() );
289 #endif // CONFIGFILE_H
friend std::istream & operator>>(std::istream &is, ConfigFile &cf)
std::map< string, string >::const_iterator mapci
file_not_found(const string &filename_=string())
static void trim(string &s)
bool keyExists(const string &key) const
friend std::ostream & operator<<(std::ostream &os, const ConfigFile &cf)
void remove(const string &key)
string getComment() const
std::map< string, string >::iterator mapi
std::map< string, string > myContents
string getDelimiter() const
string setComment(const string &s)
T read(const string &key) const
void add(string key, const T &value, bool store=false)
key_not_found(const string &key_=string())
void load(string filename, bool isList=false)
static string T_as_string(const T &t)
bool readInto(T &var, const string &key) const
static T string_as_T(const string &s)
string setDelimiter(const string &s)