00001 #ifndef _ZAKCONFIGFILE_H_
00002 #define _ZAKCONFIGFILE_H_
00003
00004 #include <fstream>
00005 #include <string.h>
00006 #include <stdlib.h>
00007
00008 #include "defines.h"
00009
00010 using namespace std;
00011
00012 #define ZAK_CFG_MAX_CHARACTERS 256
00013
00014 #define ZAK_CFG_START_SECTION_NAME '['
00015 #define ZAK_CFG_END_SECTION_NAME ']'
00016 #define ZAK_CFG_EQUAL '='
00017 #define ZAK_CFG_COMMENT ';'
00018 #define ZAK_CFG_STRING '"'
00019
00020
00021 namespace zak {
00022
00051 class ZAKENGINE_API ConfigFile : protected SupportScriptReferences
00052 {
00053 public:
00054
00060 bool Load(const char* szFilename);
00061
00069 int ReadInteger(const char *pszSection,
00070 const char *pszOption,
00071 int iDefaultValue);
00072
00080 long ReadLong (const char *pszSection,
00081 const char *pszOption,
00082 long lDefaultValue);
00083
00091 DWORD ReadDWord (const char *pszSection,
00092 const char *pszOption,
00093 DWORD DefaultValue);
00094
00102 bool ReadBoolean(const char *pszSection,
00103 const char *pszOption,
00104 bool bDefaultValue);
00105
00113 float ReadFloat(const char *pszSection,
00114 const char *pszOption,
00115 float fDefaultValue);
00116
00124 char *ReadString(const char *pszSection,
00125 const char *pszOption,
00126 const char *pszDefaultValue);
00127
00131 ConfigFile();
00132
00137 ConfigFile(const char *Filename);
00138
00142 ~ConfigFile();
00143
00144 private:
00145 static bool RegisterConfigFile(char *className=NULL);
00146
00147 static void Constructor(ConfigFile *parser){
00148 new(parser) ConfigFile();
00149 }
00150 static void Destructor(ConfigFile *parser){
00151 parser->~ConfigFile();
00152 }
00153
00154
00155 bool Load(string &szFilename) {
00156 return Load(szFilename.c_str());
00157 }
00158
00159 int ReadInteger(string &pszSection,
00160 string &pszOption,
00161 int iDefaultValue) {
00162 return ReadInteger(pszSection.c_str(), pszOption.c_str(), iDefaultValue);
00163 }
00164 long ReadLong (string &pszSection,
00165 string &pszOption,
00166 long lDefaultValue) {
00167 return ReadLong(pszSection.c_str(), pszOption.c_str(), lDefaultValue);
00168 }
00169 DWORD ReadDWord (string &pszSection,
00170 string &pszOption,
00171 DWORD DefaultValue) {
00172 return ReadDWord(pszSection.c_str(), pszOption.c_str(), DefaultValue);
00173 }
00174 bool ReadBoolean(string &pszSection,
00175 string &pszOption,
00176 bool bDefaultValue) {
00177 return ReadBoolean(pszSection.c_str(), pszOption.c_str(), bDefaultValue);
00178 }
00179 float ReadFloat(string &pszSection,
00180 string &pszOption,
00181 float fDefaultValue) {
00182 return ReadFloat(pszSection.c_str(), pszOption.c_str(), fDefaultValue);
00183 }
00184 string ReadString(const string &pszSection,
00185 const string &pszOption,
00186 const string &pszDefaultValue) {
00187 string str = ReadString(pszSection.c_str(), pszOption.c_str(), pszDefaultValue.c_str());
00188 return str;
00189 }
00190
00191 ifstream _ifs;
00192
00193 char _szString[ZAK_CFG_MAX_CHARACTERS];
00194
00195
00196 void deleteUnneeded(char *szString);
00197
00198
00199 void searchSection(const char *szSection);
00200
00201
00202 void searchValue(char *pszString, const char *szOption);
00203
00204 friend class ScriptMgr;
00205 };
00206
00207 }
00208
00209 #endif // _CONFIGFILE_H_