00001 #ifndef _MY_ConfigFile_ 00002 #define _MY_ConfigFile_ 00003 #include <fstream> 00004 #include <ext/hash_map> 00005 #include "stringhashfun.h" 00006 00007 using std::string; 00008 00014 #define TOKEN_SIZE 10000 00015 class ConfigFile 00016 { 00017 private: 00018 char strToken[TOKEN_SIZE]; 00019 int numLines; 00021 enum TokenId {STRING,KEY,ASSIGN_OPERATOR,COMMENT,INVALID_TOKEN,NUMBER,END_OF_FILE}; 00022 00023 00024 TokenId getToken(std::ifstream &file); 00030 struct TokenValue 00031 { 00032 int tokenId; 00033 std::string value; 00034 00035 }; 00036 typedef __gnu_cxx::hash_map<string,struct TokenValue,StringHashFun,struct eqstr> KeysMap; 00037 00038 KeysMap keysMap; 00039 00040 std::string m_currFile; 00041 protected: 00042 00043 public: 00044 00045 00046 ConfigFile(); 00047 ~ConfigFile(); 00048 void readFile(string fileName); 00049 std::string getCurrentFile(){return m_currFile;} 00050 string getString(string key); 00051 double getDouble(string key); 00052 double getDouble(string key,double def); 00053 00054 int getInt(string key); 00055 int getInt(string key,int def); 00056 00057 unsigned getUnsigned(string key); 00058 bool isDefined(string key); 00059 00060 }; 00061 00062 #endif