00001
00048 #ifndef INIPAT_HEADER
00049 #define INIPAT_HEADER
00050 #include <strings.h>
00051 #include "iostream"
00052 #include "fstream"
00053
00054 #include <vector>
00055 #include <stack>
00056
00057 using namespace std;
00058
00059
00060
00061 class ConfigObj;
00062
00072 class TagInfo
00073 {
00074 friend class ConfigObj;
00075 friend class TypeTagIs;
00076 friend class NameIs;
00077 unsigned int LineNo;
00078 char* Tag;
00079 void AssignTag(const char* Text);
00080 public:
00081 TagInfo(unsigned int N, char* Text );
00082 TagInfo(const TagInfo& Other);
00083 TagInfo(const TagInfo* Other);
00084 TagInfo& operator=(const TagInfo& Other);
00085 friend ostream& operator <<(ostream& Out, TagInfo& Info);
00086
00087 friend ostream& operator <<(ostream& Out, const TagInfo* Info);
00088
00090 inline const char* data() { return Tag; };
00091
00093 inline char* GetString() { return Tag; };
00094
00096 inline unsigned int GetLineNo() { return LineNo; };
00097
00099 ~TagInfo();
00100 };
00101
00102 typedef vector<TagInfo*> TagVector;
00103 typedef vector<TagInfo*>::iterator TagIterator;
00105 typedef vector<ConfigObj*> ConfigVector;
00107 typedef vector<ConfigObj*>::iterator ConfigIterator;
00109 typedef vector<ConfigObj*>::reverse_iterator ConfigRevIterator;
00110
00120 class ConfigObj
00121 {
00122 char* Name;
00123 unsigned int LineNo;
00124 TagVector Params;
00125 ConfigVector SubConfigs;
00126 void AssignName(const char* N);
00127 void KillParams();
00128 void KillConfigs();
00129 void CopyParams(const ConfigObj& Other);
00130 void CopyConfigs(const ConfigObj& Other);
00131 friend class TypeTagIs;
00132 friend class NameIs;
00133 public:
00134 ConfigObj(const char* N, unsigned int L);
00135 ConfigObj(const ConfigObj& Other);
00136 ConfigObj(const ConfigObj* Other);
00137 ConfigObj& operator=(const ConfigObj& Other);
00138
00146 bool IsMyName(const char* N) const;
00147
00155 ConfigIterator GetConfig(const char* N, unsigned int Index=0);
00156
00166 ConfigIterator GetConfig(const char* N, const char* Param, const char* ValueOfParam);
00167
00175 TagIterator GetTag(const char* N, unsigned int Index=0);
00176
00177
00178 inline TagInfo* GetTag(unsigned int Index){ if(Index < Params.size()) return Params[Index]; else return NULL;};
00179
00181 inline ConfigObj* GetConfig(unsigned int Index){ if(Index < SubConfigs.size()) return SubConfigs[Index]; else return NULL;};
00182
00183
00184 inline unsigned int GetLineNo(){ return LineNo; };
00185 inline TagIterator TagsBegin() { return Params.begin(); };
00186 inline TagIterator TagsEnd(){ return Params.end(); };
00187 inline ConfigIterator ConfigBegin(){ return SubConfigs.begin(); };
00188 inline ConfigIterator ConfigEnd(){ return SubConfigs.end(); };
00189 inline ConfigRevIterator ConfigRbegin(){ return SubConfigs.rbegin(); };
00190 inline ConfigRevIterator ConfigRend(){ return SubConfigs.rend(); };
00191
00199 TagIterator FindFirstTag(const char* ParamName);
00200
00201
00209 ConfigIterator FindFirstConfig(const char* ConfigName);
00210
00211
00212
00219 ConfigIterator FindNextConfig(ConfigIterator& First);
00220
00229 ConfigIterator FindNextConfig(ConfigIterator& First, const char* TwinTag);
00230
00231 void Reverse();
00232
00234 void Absorb(ConfigObj* Other );
00236 inline void Absorb(ConfigIterator Other ){ Absorb(*Other); };
00237
00246 void Load(char* filename);
00247
00255 ConfigStream& Load(ConfigStream& Input);
00256
00267 ostream& Write(ostream& oStream, short TabShift=0);
00268
00275 unsigned int CountParams(const char* Name=NULL);
00276
00283 unsigned int CountConfigs(const char* Name=NULL);
00284
00293 void Merge(const char* Name=NULL);
00294
00308 void DropTwins(const char* Name, const char* TagName);
00309
00311 inline bool empty()const {return ( Params.empty() && SubConfigs.empty() );};
00312
00313 void Drop(TagInfo* Param);
00314 void Drop(ConfigObj* C);
00316
00317 inline void Drop(TagIterator& it){ if(it!=Params.end()){ delete *it; Params.erase(it); } };
00318
00320 inline void Drop(ConfigIterator& ci) { if(ci!=SubConfigs.end()){delete *ci; SubConfigs.erase(ci); } };
00321
00322 inline void DropAll(){ KillParams(); KillConfigs(); };
00323
00324 inline TagInfo* operator[](unsigned int i){ return Params[i]; };
00325 inline bool operator==(char* N){ return IsMyName(N); };
00326
00327 ~ConfigObj();
00328 };
00329
00337 char ValidateINI(char* filename);
00338
00344 bool strToBool(const char* text, bool NoMatch=false);
00345
00347 class TypeTagIs
00348 {
00349 char* Value;
00350 bool check(ConfigObj* Subj);
00351 public:
00352 TypeTagIs(char* TypName);
00353 inline bool operator ()(ConfigIterator& Subj ){ return check(*Subj); };
00354 inline bool operator ()(ConfigRevIterator& Subj ){ return check(*Subj); };
00355
00356 ~TypeTagIs();
00357 };
00358
00359 class NameIs
00360 {
00361 unsigned int Len;
00362 char* TagName;
00363
00364 bool CheckTag(TagInfo* Subj);
00365 bool CheckConfig(ConfigObj* Subj);
00366 public:
00367 NameIs(char* TName);
00368 inline bool operator ()(TagIterator& Other ){ return CheckTag(*Other); };
00369 inline bool operator ()(ConfigIterator& Other ){ return CheckConfig(*Other); };
00370 inline bool operator ()(ConfigRevIterator& Other ){ return CheckConfig(*Other); };;
00371
00372 ~NameIs();
00373 };
00374
00375
00376 #endif // INIPAT_HEADER
00377