00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __EDELIB_CONFIG_H__
00022 #define __EDELIB_CONFIG_H__
00023
00024 #include <stdio.h>
00025 #include "List.h"
00026
00027 EDELIB_NS_BEGIN
00028
00033 enum ConfigErrors {
00034 CONF_SUCCESS = 0,
00035 CONF_ERR_FILE,
00036 CONF_ERR_BAD,
00037 CONF_ERR_SECTION,
00038 CONF_ERR_KEY,
00039 CONF_ERR_MEMORY,
00040 CONF_ERR_NOVALUE
00041 };
00042
00043 class Config;
00044 class ConfigSection;
00045 class ConfigEntry;
00046
00047 #ifndef SKIP_DOCS
00048 typedef list<ConfigEntry*> EntryList;
00049 typedef list<ConfigEntry*>::iterator EntryListIter;
00050
00051 typedef list<ConfigSection*> SectionList;
00052 typedef list<ConfigSection*>::iterator SectionListIter;
00053 #endif
00054
00112 class EDELIB_API Config {
00113 private:
00114 unsigned int errcode;
00115 unsigned int linenum;
00116 unsigned int sectnum;
00117 ConfigSection* cached;
00118
00119 SectionList section_list;
00120
00121 ConfigSection* add_section(const char* section);
00122 ConfigSection* find_section(const char* section);
00123
00124 E_DISABLE_CLASS_COPY(Config)
00125 public:
00127 Config();
00128
00130 ~Config() { clear(); }
00131
00138 bool load(const char* fname);
00139
00148 bool save(const char* fname);
00149
00163 operator bool(void) const { return ((errcode == CONF_SUCCESS) ? 1 : 0); }
00164
00168 void clear(void);
00169
00179 bool get(const char* section, const char* key, char* ret, unsigned int size);
00180
00203 bool get_localized(const char* section, const char* key, char* ret, unsigned int size);
00204
00216 bool get_allocated(const char* section, const char* key, char** ret, unsigned int& retsize);
00217
00227 bool get(const char* section, const char* key, bool& ret, bool dfl = false);
00228
00238 bool get(const char* section, const char* key, int& ret, int dfl = 0);
00239
00249 bool get(const char* section, const char* key, float& ret, float dfl = 0);
00250
00260 bool get(const char* section, const char* key, long& ret, long dfl = 0);
00261
00271 bool get(const char* section, const char* key, double& ret, double dfl = 0);
00272
00282 bool get(const char* section, const char* key, char& ret, char dfl = 0);
00283
00292 void set(const char* section, const char* key, char* val);
00293
00302 void set(const char* section, const char* key, const char* val);
00303
00312 void set_localized(const char* section, const char* key, char* val);
00313
00322 void set_localized(const char* section, const char* key, const char* val);
00323
00332 void set(const char* section, const char* key, bool val);
00333
00342 void set(const char* section, const char* key, int val);
00343
00352 void set(const char* section, const char* key, long val);
00353
00362 void set(const char* section, const char* key, float val);
00363
00372 void set(const char* section, const char* key, double val);
00373
00379 bool exist(const char* section);
00380
00386 bool key_exist(const char* section, const char* key);
00387
00393 unsigned int num_sections(void);
00394
00401 unsigned int line(void);
00402
00409 int error(void);
00410
00415 const char* strerror(void);
00416
00422 const char* strerror(int code);
00423 };
00424
00425 #ifndef SKIP_DOCS
00426
00427 EDELIB_API int config_getline(char** buff, int* len, FILE* f);
00428 #endif
00429
00430 EDELIB_NS_END
00431 #endif