Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

ConfigFile.h

Go to the documentation of this file.
00001 #include "IsoBomb.h"
00002 
00009 #ifndef CONFIGFILE_H_LWVK123
00010 #define CONFIGFILE_H_LWVK123
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 ) {
00090         SectionMapIter sIter = sections.find( section );
00091         if ( sIter == sections.end() ) {
00092             retVal = defVal;
00093             return;
00094         }
00095 
00096         VariableMap& varMap = (*sIter).second;
00097         VariableMapIter vIter = varMap.find( varName );
00098         if ( vIter == varMap.end() ) {
00099             retVal = defVal;
00100             return;
00101         }
00102 
00103         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 ) {
00115         SectionMapIter sIter = sections.find( section );
00116         if ( sIter == sections.end() ) {
00117             retVal = defVal;
00118             return;
00119         }
00120 
00121         VariableMap& varMap = (*sIter).second;
00122         VariableMapIter 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 ) {
00138         getVar( section, varName, retVal, 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 SectionMap::iterator SectionMapIter;
00158 
00159     SectionMap sections;
00160 };
00161 
00162 #endif

Generated on Tue Mar 4 02:29:25 2003 for SuperIsoBomb by doxygen1.2.18