base_config_file.hh

Go to the documentation of this file.
00001 /*
00009  * LEGAL:   COPYRIGHT (C) 2004 JIM E. BROOKS
00010  *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
00011  *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
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 /*OUT*/ );
00114     bool        Read( const string& key, double& val /*OUT*/ );
00115     bool        Read( const string& key, string& val /*OUT*/ );
00116     enum        eAccess { eAccess_WRITE, eAccess_READ };
00117     bool        Access( ConfigFile::eAccess acc, const string& key, int&    val /*IN/OUT*/ );
00118     bool        Access( ConfigFile::eAccess acc, const string& key, double& val /*IN/OUT*/ );
00119     bool        Access( ConfigFile::eAccess acc, const string& key, string& val /*IN/OUT*/ );
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 } // namespace base
00167 
00168 #endif // BASE_CONFIG_FILE_HH
Palomino 3D Engine documents generated by doxygen 1.5.3 on Fri Nov 23 11:26:06 2007