00001 #ifndef INI_H
00002 #define INI_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include <string>
00043 #include <vector>
00044 #include <fstream>
00045 #include <sstream>
00046 #include <iostream>
00047 using namespace std;
00048
00049 #define INI_DEFAULT_SECTION "main"
00050
00051 #define INI_MAX_LENGTH 300
00052 #define INI_MAX_LINES_PER_SEC 50 // lines every section can have
00053 #define INI_MAX_SECTIONS 20 // maximum amount of sections
00054
00055 #define INI_LINE_DONTSAVE "ini_dont_save123" // if a line contains this, it won't save
00056
00057
00058 class INIParser {
00059 public:
00060 INIParser(const char _filename[]);
00061 ~INIParser();
00062
00063 int GetInteger(const char section[], const char key[], int defaultValue);
00064 double GetDouble(const char section[], const char key[], double defaultValue);
00065 long GetLong(const char section[], const char key[], long defaultValue);
00066 bool GetBoolean(const char section[], const char key[], bool defaultValue);
00067 string GetString(const char section[], const char key[], string defaultValue);
00068 string Get(const char section[], const char key[], string defaultValue);
00069
00070 void SetInt(const char section[],const char key[], int newval);
00071 void SetLong(const char section[], const char key[], long newval);
00072 void SetBool(const char section[], const char key[], bool newval);
00073 void SetString(const char section[], const char key[], string newval);
00074 void Set(const char section[], const char key[], const char newval[]);
00075
00076 void CreateSection(const char section[]);
00077 void RemoveSection(const char section[]);
00078 void RemoveEntry(const char section[], const char key[]);
00079 bool ValidSection(const char section[]);
00080 bool ValidEntry(const char section[], const char key[]);
00081 int CountSections();
00082 int CountEntries();
00083 void Clear();
00084 void Close();
00085 bool Good();
00086
00087
00088 private:
00089
00090 string getKeyFromString(string mystring);
00091 string getValueFromString(string mystring);
00092 template <class T>
00093 string numtostring(T num);
00094 template <class T>
00095 T stringtonum(string mystring);
00096
00097
00098
00099 string filename;
00100 vector<string> sectionnames;
00101 vector< vector<string> > buffer;
00102 bool InitGood;
00103 bool Closed;
00104 bool withoutSections;
00105
00106
00107 int sections;
00108 int entries;
00109
00110 };
00111 #endif // INI_H