Main Page   Class Hierarchy   Compound List   File List   Compound Members  

ConfigFile.h

00001 
00007 #ifndef CONFIGFILE_H_LWVK123
00008 #define CONFIGFILE_H_LWVK123
00009 
00010 #include "global.h"
00011 
00062 class ConfigFile {
00063 public:
00067     explicit ConfigFile( const std::string& fileName );
00068 
00072     bool varExists( const std::string& section, const std::string& varName );
00073 
00087     template< class T >
00088     void getVar( const std::string& section, const std::string& varName,
00089                  T& retVal, const T& defVal ) const {
00090         SectionMapCIter sIter = sections.find( section );
00091         if ( sIter == sections.end() ) {
00092             retVal = defVal;
00093             return;
00094         }
00095 
00096         const VariableMap& varMap = (*sIter).second;
00097         VariableMapCIter vIter = varMap.find( varName );
00098         if ( vIter == varMap.end() ) {
00099             retVal = defVal;
00100             return;
00101         }
00102 
00103         std::istringstream conv( (*vIter).second );
00104         conv >> retVal;
00105     }
00106 
00107 
00112     template<>
00113     void getVar( const std::string& section, const std::string& varName,
00114                  std::string& retVal, const std::string& defVal ) const {
00115         SectionMapCIter sIter = sections.find( section );
00116         if ( sIter == sections.end() ) {
00117             retVal = defVal;
00118             return;
00119         }
00120 
00121         const VariableMap& varMap = (*sIter).second;
00122         VariableMapCIter vIter = varMap.find( varName );
00123         if ( vIter == varMap.end() ) {
00124             retVal = defVal;
00125             return;
00126         }
00127 
00128         retVal = (*vIter).second;
00129     }
00130 
00136     void getVar( const std::string& section, const std::string& varName,
00137                  std::string& retVal, const char* defVal ) const {
00138         getVar( section, varName, retVal, std::string( defVal ) );
00139     }
00140 
00141 #ifdef _DEBUG
00142     //Runs a test of the ConfigFile class.
00143     static void doTest();
00144 #endif
00145 
00146 private:
00151     ConfigFile();
00152 
00153     typedef std::map<std::string, std::string> VariableMap;
00154     typedef std::map<std::string, VariableMap> SectionMap;
00155 
00156     typedef VariableMap::iterator VariableMapIter;
00157     typedef VariableMap::const_iterator VariableMapCIter;
00158 
00159     typedef SectionMap::iterator SectionMapIter;
00160     typedef SectionMap::const_iterator SectionMapCIter;
00161 
00162     SectionMap sections;
00163 };
00164 
00165 #endif

Generated on Wed May 14 01:38:07 2003 for CG Skeletal Animation Project by doxygen1.2.18