00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _CONFIGFILE_H
00026 #define _CONFIGFILE_H
00027
00028 #include <stdio.h>
00029 #include <string>
00030 #include <iostream>
00031 #include <fstream>
00032 #include <cmath>
00033 #include <cassert>
00034
00035 using namespace std;
00036
00037
00038
00039 class CONFIGVARIABLE
00040 {
00041 public:
00042 CONFIGVARIABLE();
00043
00044 string section;
00045 string name;
00046
00047 string GetFullName();
00048
00049 string val_s;
00050 int val_i;
00051 float val_f;
00052 float val_v[3];
00053 bool val_b;
00054
00055 CONFIGVARIABLE * next;
00056
00057 void Set(string newval);
00058
00059 void DebugPrint();
00060
00061 string strLTrim(string instr);
00062 string strRTrim(string instr);
00063 string strTrim(string instr);
00064 string strLCase(string instr);
00065
00066 bool written;
00067 };
00068
00069 class CONFIGFILE
00070 {
00071 private:
00072 string filename;
00073 CONFIGVARIABLE * vars;
00074 void Add(CONFIGVARIABLE * newvar);
00075 string Trim(string instr);
00076 void ProcessLine(string & cursection, string linestr);
00077 string Strip(string instr, char stripchar);
00078 string LCase(string instr);
00079 bool SUPPRESS_ERROR;
00080
00081 public:
00082 CONFIGFILE();
00083 CONFIGFILE(string fname);
00084 ~CONFIGFILE();
00085
00086 void Load(string fname);
00087 void Clear();
00088
00089
00090 bool ClearParam(string param);
00091
00092
00093 bool GetParam(string param, string & outvar);
00094 bool GetParam(string param, int & outvar);
00095 bool GetParam(string param, float & outvar);
00096 bool GetParam(string param, float * outvar);
00097 bool GetParam(string param, bool & outvar);
00098
00099
00100 bool SetParam(string param, string invar);
00101 bool SetParam(string param, int invar);
00102 bool SetParam(string param, float invar);
00103 bool SetParam(string param, float * invar);
00104 bool SetParam(string param, bool invar);
00105
00106 void DebugPrint();
00107
00108 bool Write();
00109 bool Write(bool with_brackets);
00110 bool Write(bool with_brackets, string save_as);
00111
00112 void SuppressError(bool newse) {SUPPRESS_ERROR = newse;}
00113
00114 CONFIGVARIABLE * GetHead() {return vars;}
00115 };
00116
00117 #endif
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169