00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _WSET_CONFIG_H_
00013 #define _WSET_CONFIG_H_
00014
00015 #include <string>
00016 #include <sstream>
00017 #include <iostream>
00018 #include <map>
00019
00020 using namespace std;
00021
00023 struct ltstr
00024 {
00025 bool operator()(const string& s1, const string& s2) const
00026 {
00027 return strcmp(s1.c_str(), s2.c_str()) < 0;
00028 }
00029 };
00030
00031
00033
00037 class Value
00038 {
00039 public:
00041 Value() {}
00043
00046 Value( const char* v) : theValue(v) { }
00048
00051 Value( int n ) {
00052 stringstream s;
00053 s << n << '\0' << flush;
00054 theValue = string(s.str());
00055 }
00056
00058
00061 operator int( ) const { return atoi(theValue.c_str()); }
00063
00066 operator double( ) const { return atof(theValue.c_str()); }
00068
00071 operator string( ) const { return theValue; }
00073 friend istream& operator >> (istream& in, Value& v){
00074 in >> v.theValue;
00075 return in;
00076 }
00077
00078 private:
00079 string theValue;
00080 };
00081
00082
00084 typedef map<string, Value, ltstr> ParameterType;
00085
00086
00087
00088
00089
00091
00110 class ConfigFile
00111 {
00112
00113 public:
00114
00116
00117
00118
00120
00122 ConfigFile();
00124
00129 ConfigFile(const string& f_name);
00130
00131
00132
00133
00134
00136
00137
00138
00140
00142
00149 void setVariable( const char* p_name, const Value& p_value );
00150
00151
00152
00154
00163 const Value& getValue(const char* p_name);
00164
00165
00167
00168
00169
00171
00172
00173
00175
00178 friend ostream& operator << ( ostream& ostr, const ConfigFile& C )
00179 {
00180 C.printOn(ostr);
00181 return ostr;
00182 }
00183
00184
00185 private:
00186
00188
00189
00190
00192
00193 void readFrom( istream& istr );
00194
00195 void printOn( ostream& ostr ) const;
00196
00197 void rtrim(char* ch);
00198 void ltrim(char* ch);
00199 void trim(char* ch);
00200
00202
00203
00204
00206
00207 ParameterType parameters;
00208
00209
00210 };
00211 #endif