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
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _LTI_CONFIG_FILE_HANDLER_H_
00034 #define _LTI_CONFIG_FILE_HANDLER_H_
00035
00036 #include "ltiObject.h"
00037 #include <list>
00038 #include <map>
00039 #include <string>
00040 #include "ltiIOFunctor.h"
00041
00042 namespace lti {
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 class configFileHandler : public ioFunctor {
00075 public:
00076
00077
00078
00079 class parameters : public ioFunctor::parameters {
00080 public:
00081
00082
00083
00084 parameters();
00085
00086
00087
00088
00089
00090 parameters(const parameters& other);
00091
00092
00093
00094
00095 ~parameters();
00096
00097
00098
00099
00100 const char* getTypeName() const;
00101
00102
00103
00104
00105
00106
00107 parameters& copy(const parameters& other);
00108
00109
00110
00111
00112
00113
00114 parameters& operator=(const parameters& other);
00115
00116
00117
00118
00119
00120 virtual functor::parameters* clone() const;
00121
00122
00123
00124
00125
00126
00127
00128
00129 virtual bool write(ioHandler& handler,const bool complete=true) const;
00130
00131
00132
00133
00134
00135
00136
00137
00138 virtual bool read(ioHandler& handler,const bool complete=true);
00139
00140 # ifdef _LTI_MSC_6
00141
00142
00143
00144
00145
00146
00147
00148 bool readMS(ioHandler& handler,const bool complete=true);
00149
00150
00151
00152
00153
00154
00155
00156
00157 bool writeMS(ioHandler& handler,const bool complete=true) const;
00158 # endif
00159
00160
00161
00162
00163
00164
00165
00166
00167 bool formatOutput;
00168 };
00169
00170
00171
00172
00173 configFileHandler();
00174
00175
00176
00177
00178
00179 configFileHandler(const configFileHandler& other);
00180
00181
00182
00183
00184 virtual ~configFileHandler();
00185
00186
00187
00188
00189 virtual const char* getTypeName() const;
00190
00191
00192
00193
00194
00195
00196 configFileHandler& copy(const configFileHandler& other);
00197
00198
00199
00200
00201
00202
00203 configFileHandler& operator=(const configFileHandler& other);
00204
00205
00206
00207
00208 virtual functor* clone() const;
00209
00210
00211
00212
00213 const parameters& getParameters() const;
00214
00215
00216
00217
00218 bool apply();
00219
00220
00221
00222
00223
00224
00225 bool loadFile();
00226
00227
00228 bool loadFile(const std::string &fileName);
00229
00230
00231
00232
00233
00234 bool saveFile() const;
00235
00236
00237 bool saveFile(const std::string &fileName) const;
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 bool getValue(const std::string §ion, const std::string &key, std::string &value, std::string &comment) const;
00250
00251
00252 bool getValue(const std::string §ion, const std::string &key, std::string &value) const{
00253 std::string tt;
00254 return getValue(section,key,value,tt);
00255 }
00256
00257
00258
00259 bool getValue(const std::string §ion, const std::string &key, bool &value, std::string &comment) const;
00260
00261
00262 bool getValue(const std::string §ion, const std::string &key, bool &value) const{
00263 std::string tt;
00264 return getValue(section,key,value,tt);
00265 }
00266
00267
00268
00269 bool getValue(const std::string §ion, const std::string &key, double &value, std::string &comment) const;
00270
00271
00272 bool getValue(const std::string §ion, const std::string &key, double &value) const{
00273 std::string tt;
00274 return getValue(section,key,value,tt);
00275 }
00276
00277
00278
00279 bool getValue(const std::string §ion, const std::string &key, float &value, std::string &comment) const;
00280
00281
00282 bool getValue(const std::string §ion, const std::string &key, float &value) const{
00283 std::string tt;
00284 return getValue(section,key,value,tt);
00285 }
00286
00287
00288
00289 bool getValue(const std::string §ion, const std::string &key, int &value, std::string &comment) const;
00290
00291
00292 bool getValue(const std::string §ion, const std::string &key, int &value) const{
00293 std::string tt;
00294 return getValue(section,key,value,tt);
00295 }
00296
00297
00298
00299 bool getValue(const std::string §ion, const std::string &key, unsigned int &value, std::string &comment) const;
00300
00301
00302 bool getValue(const std::string §ion, const std::string &key, unsigned int &value) const{
00303 std::string tt;
00304 return getValue(section,key,value,tt);
00305 }
00306
00307
00308 std::list<std::string> getKeys(std::string section) const;
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326 bool setValue(const std::string §ion, const std::string &key = "", const std::string &value = "", const std::string &comment = "");
00327
00328
00329
00330 bool setValue(const std::string §ion, const std::string &key = "", const char* value= "", const std::string &comment = ""){
00331 return setValue(section, key, std::string(value), std::string(comment));
00332 }
00333
00334
00335
00336 bool setValue(const std::string §ion, const std::string &key = "", const bool &value = false, const std::string &comment = "");
00337
00338
00339
00340 bool setValue(const std::string §ion, const std::string &key = "", const double &value = 0.0, const std::string &comment = "");
00341
00342
00343
00344 bool setValue(const std::string §ion, const std::string &key = "", const float &value = 0.0f, const std::string &comment = "");
00345
00346
00347
00348 bool setValue(const std::string §ion, const std::string &key = "", const int &value = 0, const std::string &comment = "");
00349
00350
00351
00352 bool setValue(const std::string §ion, const std::string &key = "", const unsigned int &value = 0, const std::string &comment = "");
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366 void sortSections();
00367
00368
00369
00370
00371
00372
00373 bool deleteSection(const std::string §ion="");
00374
00375
00376
00377
00378
00379
00380 bool deleteKey(const std::string §ion, const std::string &key="");
00381
00382
00383
00384
00385
00386
00387 void clear();
00388
00389
00390
00391
00392 protected:
00393 class configEntry {
00394 public:
00395 configEntry() {
00396 configEntry("","");
00397 }
00398 configEntry(std::string v,
00399 std::string c) {
00400 value = v;
00401 comment = c;
00402 }
00403 ~configEntry() { };
00404 std::string value;
00405 std::string comment;
00406 };
00407
00408
00409
00410
00411 std::string splitLine(const std::string& inputLine,
00412 std::string& prolog,
00413 std::string& section,
00414 std::string& key,
00415 std::string& value,
00416 std::string& comment) const;
00417
00418
00419
00420
00421 void composeLine(const std::string& prolog,
00422 const std::string& section,
00423 const std::string& key,
00424 const std::string& value,
00425 const std::string& comment,
00426 bool secDef,
00427 int keyLength,
00428 std::string& outputLine) const;
00429
00430
00431
00432
00433
00434 int getMaxKeyLengths(std::map<std::string,int>& maxKeyLengths) const;
00435
00436
00437 std::map<std::string, std::map<std::string, configEntry> > dictionary;
00438
00439
00440 std::list<std::string> orderSections;
00441
00442
00443 std::map<std::string, std::list<std::string> > orderKeys;
00444
00445
00446 std::map<std::string, std::list<std::string> > sectionComments;
00447
00448
00449 std::map<std::string, std::string> sectionOrig;
00450
00451
00452 std::map<std::string, std::map<std::string, std::string> > keyOrig;
00453 };
00454 }
00455
00456 #endif