UCommon
keydata.h
Go to the documentation of this file.
1// Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2// Copyright (C) 2015-2020 Cherokees of Idaho.
3//
4// This file is part of GNU uCommon C++.
5//
6// GNU uCommon C++ is free software: you can redistribute it and/or modify
7// it under the terms of the GNU Lesser General Public License as published
8// by the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// GNU uCommon C++ is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
18
31#ifndef _UCOMMON_KEYDATA_H_
32#define _UCOMMON_KEYDATA_H_
33
34#ifndef _UCOMMON_CONFIG_H_
35#include <ucommon/platform.h>
36#endif
37
38#ifndef _UCOMMON_LINKED_H_
39#include <ucommon/linked.h>
40#endif
41
42#ifndef _UCOMMON_MEMORY_H_
43#include <ucommon/memory.h>
44#endif
45
46namespace ucommon {
47
48class keyfile;
49
58class __EXPORT keydata : public OrderedObject
59{
60private:
61 friend class keyfile;
62
63 OrderedIndex index;
64 const char *name;
65 keyfile *root;
66
67 keydata(keyfile *file);
68 keydata(keyfile *file, const char *id);
69 __DELETE_COPY(keydata);
70
71public:
77 class __LOCAL keyvalue : public OrderedObject
78 {
79 private:
80 friend class keydata;
81 friend class keyfile;
82 keyvalue(keyfile *allocator, keydata *section, const char *key, const char *data);
83 __DELETE_COPY(keyvalue);
84
85 public:
86 const char *id;
87 const char *value;
88 };
89
90 friend class keyvalue;
91
97 const char *get(const char *id) const;
98
104 inline const char *operator()(const char *id) const {
105 return get(id);
106 }
107
115 void set(const char *id, const char *value);
116
122 void clear(const char *id);
123
128 inline const char *get(void) const {
129 return name;
130 }
131
136 inline keyvalue *begin(void) const {
137 return (keyvalue *)index.begin();
138 }
139
144 inline keyvalue *end(void) const {
145 return (keyvalue*)index.end();
146 }
147
151 typedef linked_pointer<keyvalue> pointer;
152};
153
160class __EXPORT keyfile : public memalloc
161{
162private:
163 friend class keydata;
164 OrderedIndex index;
165 keydata *defaults;
166 int errcode;
167
168protected:
169 keydata *create(const char *section);
170
171#ifdef _MSWINDOWS_
172 void load(HKEY root, keydata *section = NULL, const char *path = NULL);
173 bool save(HKEY root, keydata *section = NULL, const char *path = NULL);
174#endif
175
176public:
181 keyfile(size_t pagesize = 0);
182
188 keyfile(const char *path, size_t pagesize = 0);
189
190 keyfile(const keyfile &copy, size_t pagesize = 0);
191
198 void load(const char *path);
199
205 bool save(const char *path);
206
211 void load(const keyfile *source);
212
217 void load(const keydata *source);
218
222 void release(void);
223
229 keydata *get(const char *section) const;
230
231 inline keydata *operator()(const char *section) const {
232 return get(section);
233 }
234
235 inline keydata *operator[](const char *section) const {
236 return get(section);
237 }
238
243 inline keydata *get(void) const {
244 return defaults;
245 }
246
251 inline keydata *begin(void) const {
252 return (keydata *)index.begin();
253 }
254
259 inline keydata *end(void) const {
260 return (keydata *)index.end();
261 }
262
266 typedef linked_pointer<keydata> pointer;
267
268 inline int err(void) const {
269 return errcode;
270 }
271
276 void assign(keyfile& source);
277
278 inline keyfile& operator=(keyfile& source) {
279 assign(source);
280 return *this;
281 }
282};
283
284} // namespace ucommon
285
286#endif
Private heaps, pools, and associations.
Various miscellaneous platform specific headers and defines.
Linked objects, lists, templates, and containers.
Common namespace for all ucommon objects.
Definition access.h:47