00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00025 #ifndef _UCOMMON_KEYDATA_H_
00026 #define _UCOMMON_KEYDATA_H_
00027
00028 #ifndef _UCOMMON_LINKED_H_
00029 #include <ucommon/linked.h>
00030 #endif
00031
00032 #ifndef _UCOMMON_MEMORY_H_
00033 #include <ucommon/memory.h>
00034 #endif
00035
00036 NAMESPACE_UCOMMON
00037
00038 class keyfile;
00039
00048 class __EXPORT keydata : public OrderedObject
00049 {
00050 private:
00051 friend class keyfile;
00052 OrderedIndex index;
00053 keydata(keyfile *file);
00054 keydata(keyfile *file, const char *id);
00055 const char *name;
00056 keyfile *root;
00057
00058 public:
00064 class __LOCAL keyvalue : public OrderedObject
00065 {
00066 private:
00067 friend class keydata;
00068 friend class keyfile;
00069 keyvalue(keyfile *allocator, keydata *section, const char *key, const char *data);
00070 public:
00071 const char *id;
00072 const char *value;
00073 };
00074
00075 friend class keyvalue;
00076
00082 const char *get(const char *id);
00083
00089 inline const char *operator()(const char *id)
00090 {return get(id);};
00091
00099 void set(const char *id, const char *value);
00100
00106 void clear(const char *id);
00107
00112 inline const char *get(void)
00113 {return name;};
00114
00119 inline keyvalue *begin(void)
00120 {return (keyvalue *)index.begin();};
00121
00126 inline keyvalue *end(void)
00127 {return (keyvalue*)index.end();};
00128
00132 typedef linked_pointer<keyvalue> iterator;
00133 };
00134
00141 class __EXPORT keyfile : public memalloc
00142 {
00143 private:
00144 friend class keydata;
00145 OrderedIndex index;
00146 keydata *defaults;
00147
00148 keydata *create(const char *section);
00149
00150 public:
00155 keyfile(size_t pagesize = 0);
00156
00162 keyfile(const char *path, size_t pagesize = 0);
00163
00170 void load(const char *path);
00171
00177 keydata *get(const char *section);
00178
00179 inline keydata *operator()(const char *section)
00180 {return get(section);};
00181
00182 inline keydata *operator[](const char *section)
00183 {return get(section);};
00184
00189 inline keydata *get(void)
00190 {return defaults;};
00191
00196 inline keydata *begin(void)
00197 {return (keydata *)index.begin();};
00198
00203 inline keydata *end(void)
00204 {return (keydata *)index.end();};
00205
00209 typedef linked_pointer<keydata> iterator;
00210 };
00211
00212 END_NAMESPACE
00213
00214 #endif