00001
00009
00010
00011
00012
00013
00014 #ifndef BASE_CONFIG_FILE_HH
00015 #define BASE_CONFIG_FILE_HH 1
00016
00017 #include "base_common.hh"
00018
00019 namespace base {
00020
00102 class ConfigFile : private NonThreadable
00103 {
00104
00105 public:
00106 ConfigFile( const string& programName, const string& fname = "", bool autoflush = true );
00107 ~ConfigFile() { }
00108 bool IfValid( void ) { return mValid; }
00109 bool IfEmpty( void ) { return mTupleMap.empty(); }
00110 bool Write( const string& key, const int& val );
00111 bool Write( const string& key, const double& val );
00112 bool Write( const string& key, const string& val );
00113 bool Read( const string& key, int& val );
00114 bool Read( const string& key, double& val );
00115 bool Read( const string& key, string& val );
00116 enum eAccess { eAccess_WRITE, eAccess_READ };
00117 bool Access( ConfigFile::eAccess acc, const string& key, int& val );
00118 bool Access( ConfigFile::eAccess acc, const string& key, double& val );
00119 bool Access( ConfigFile::eAccess acc, const string& key, string& val );
00120 bool Remove( const string& key );
00121 bool Flush( void );
00122
00123 private:
00124 bool Parse( void );
00125
00126 private:
00130 class ConfigTuple
00131 {
00132
00133 public:
00134 ConfigTuple( void );
00135 ~ConfigTuple();
00136 void Clear( void );
00137 bool Write( fstream& fs );
00138 bool Read( fstream& fs, const string& type );
00139 enum eType
00140 {
00141 eType_INVALID,
00142 eType_INT,
00143 eType_DOUBLE,
00144 eType_STRING
00145 };
00146 ConfigTuple::eType mType;
00147 string mKey;
00148 int mValInt;
00149 double mValDouble;
00150 string mValString;
00151
00152 };
00153
00154 private:
00155 bool mValid;
00156 bool mAutoflush;
00157 string mProgramName;
00158 fstream mStream;
00159 map<string,ConfigTuple> mTupleMap;
00160
00161 friend bool CompareTuples( const ConfigFile::ConfigTuple& t1, const ConfigFile::ConfigTuple& t2 );
00162 };
00163
00164 bool CompareTuples( const ConfigFile::ConfigTuple& t1, const ConfigFile::ConfigTuple& t2 );
00165
00166 }
00167
00168 #endif // BASE_CONFIG_FILE_HH