62 typedef std::map<string,string>::iterator
mapi;
63 typedef std::map<string,string>::const_iterator
mapci;
68 string delimiter =
"=",
70 string sentry =
"EndConfigFile" );
74 template<
class T> T
read(
const string& key )
const;
75 template<
class T> T
read(
const string& key,
const T& value )
const;
76 template<
class T>
bool readInto( T& var,
const string& key )
const;
78 bool readInto( T& var,
const string& key,
const T& value )
const;
81 template<
class T>
void add(
string key,
const T& value );
82 void remove(
const string& key );
85 bool keyExists(
const string& key )
const;
92 {
string old =
myDelimiter; myDelimiter = s;
return old; }
94 {
string old =
myComment; myComment = s;
return old; }
101 template<
class T>
static string T_as_string(
const T& t );
102 template<
class T>
static T
string_as_T(
const string& s );
103 static void trim(
string& s );
111 : filename(filename_) {} };
125 std::ostringstream ost;
138 std::istringstream ist(s);
146 inline string ConfigFile::string_as_T<string>(
const string& s )
156 inline bool ConfigFile::string_as_T<bool>(
const string& s )
163 for( string::iterator p = sup.begin(); p != sup.end(); ++p )
165 if( sup==
string(
"FALSE") || sup==string(
"F") ||
166 sup==string(
"NO") || sup==string(
"N") ||
167 sup==string(
"0") || sup==string(
"NONE") )
177 mapci p = myContents.find(key);
179 return string_as_T<T>( p->second );
188 mapci p = myContents.find(key);
189 if( p == myContents.end() )
return value;
190 return string_as_T<T>( p->second );
200 mapci p = myContents.find(key);
201 bool found = ( p != myContents.end() );
202 if( found ) var = string_as_T<T>( p->second );
213 mapci p = myContents.find(key);
214 bool found = ( p != myContents.end() );
216 var = string_as_T<T>( p->second );
234 #endif // CONFIGFILE_H
T read(const string &key) const
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)
string getDelimiter() const
friend std::ostream & operator<<(std::ostream &os, const ConfigFile &cf)
string getComment() const
void add(string key, const T &value)
std::map< string, string >::iterator mapi
std::map< string, string > myContents
string setComment(const string &s)
key_not_found(const string &key_=string())
bool readInto(T &var, const string &key) const
static string T_as_string(const T &t)
static T string_as_T(const string &s)
bool keyExists(const string &key) const
string setDelimiter(const string &s)