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();
00131
00138 bool load(const char* fname);
00139
00146 bool save(const char* fname);
00147
00161 operator bool(void) const { return ((errcode == CONF_SUCCESS) ? 1 : 0); }
00162
00166 void clear(void);
00167
00177 bool get(const char* section, const char* key, char* ret, unsigned int size);
00178
00201 bool get_localized(const char* section, const char* key, char* ret, unsigned int size);
00202
00214 bool get_allocated(const char* section, const char* key, char** ret, unsigned int& retsize);
00215
00225 bool get(const char* section, const char* key, bool& ret, bool dfl = false);
00226
00236 bool get(const char* section, const char* key, int& ret, int dfl = 0);
00237
00247 bool get(const char* section, const char* key, float& ret, float dfl = 0);
00248
00258 bool get(const char* section, const char* key, long& ret, long dfl = 0);
00259
00269 bool get(const char* section, const char* key, double& ret, double dfl = 0);
00270
00280 bool get(const char* section, const char* key, char& ret, char dfl = 0);
00281
00290 void set(const char* section, const char* key, char* val);
00291
00300 void set(const char* section, const char* key, const char* val);
00301
00310 void set_localized(const char* section, const char* key, char* val);
00311
00320 void set_localized(const char* section, const char* key, const char* val);
00321
00330 void set(const char* section, const char* key, bool val);
00331
00340 void set(const char* section, const char* key, int val);
00341
00350 void set(const char* section, const char* key, long val);
00351
00360 void set(const char* section, const char* key, float val);
00361
00370 void set(const char* section, const char* key, double val);
00371
00377 bool exist(const char* section);
00378
00384 bool key_exist(const char* section, const char* key);
00385
00391 unsigned int num_sections(void);
00392
00399 unsigned int line(void);
00400
00407 int error(void);
00408
00413 const char* strerror(void);
00414
00420 const char* strerror(int code);
00421 };
00422
00423 #ifndef SKIP_DOCS
00424
00425 EDELIB_API int config_getline(char** buff, int* len, FILE* f);
00426 #endif
00427
00428 EDELIB_NS_END
00429 #endif