ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

keydata.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 // Copyright (C) 2015 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 
46 namespace ucommon {
47 
48 class keyfile;
49 
59 {
60 private:
61  friend class keyfile;
62 
64  const char *name;
66 
67  keydata(keyfile *file);
68  keydata(keyfile *file, const char *id);
70 
71 public:
78  {
79  private:
80  friend class keydata;
81  friend class keyfile;
82  keyvalue(keyfile *allocator, keydata *section, const char *key, const char *data);
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 
152 };
153 
160 class __EXPORT keyfile : public memalloc
161 {
162 private:
163  friend class keydata;
166  int errcode;
167 
168 protected:
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 
176 public:
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 
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
ucommon::keydata::pointer
linked_pointer< keyvalue > pointer
Definition: keydata.h:151
ucommon::keyfile
Definition: keydata.h:160
ucommon::keydata::begin
keyvalue * begin(void) const
Definition: keydata.h:136
ucommon
Definition: access.cpp:23
ucommon::keydata::keyvalue::id
const char * id
Definition: keydata.h:86
__LOCAL
#define __LOCAL
Definition: platform.h:298
ucommon::keydata
Definition: keydata.h:58
ucommon::keyfile::end
keydata * end(void) const
Definition: keydata.h:259
ucommon::keyfile::index
OrderedIndex index
Definition: keydata.h:164
ucommon::keyfile::get
keydata * get(void) const
Definition: keydata.h:243
ucommon::copy
T copy(const T &src)
Definition: generics.h:395
ucommon::keydata::operator()
const char * operator()(const char *id) const
Definition: keydata.h:104
ucommon::clear
T & clear(T &o)
Definition: generics.h:416
ucommon::keyfile::err
int err(void) const
Definition: keydata.h:268
ucommon::keyfile::operator()
keydata * operator()(const char *section) const
Definition: keydata.h:231
__EXPORT
#define __EXPORT
Definition: config.h:49
ucommon::OrderedIndex
Definition: linked.h:176
ucommon::keydata::name
const char * name
Definition: keydata.h:64
ucommon::keydata::index
OrderedIndex index
Definition: keydata.h:63
ucommon::linked_pointer
Definition: linked.h:991
ucommon::keyfile::pointer
linked_pointer< keydata > pointer
Definition: keydata.h:266
__DELETE_COPY
#define __DELETE_COPY(x)
Definition: platform.h:160
platform.h
ucommon::keydata::end
keyvalue * end(void) const
Definition: keydata.h:144
ucommon::keydata::root
keyfile * root
Definition: keydata.h:65
ucommon::keyfile::errcode
int errcode
Definition: keydata.h:166
ucommon::keyfile::operator[]
keydata * operator[](const char *section) const
Definition: keydata.h:235
ucommon::OrderedIndex::end
LinkedObject * end(void) const
Definition: linked.h:278
ucommon::memalloc
Definition: memory.h:61
ucommon::keydata::keyvalue
Definition: keydata.h:77
ucommon::keyfile::operator=
keyfile & operator=(keyfile &source)
Definition: keydata.h:278
ucommon::keyfile::begin
keydata * begin(void) const
Definition: keydata.h:251
ucommon::keydata::get
const char * get(void) const
Definition: keydata.h:128
ucommon::OrderedObject
Definition: linked.h:312
ucommon::keydata::keyvalue::value
const char * value
Definition: keydata.h:87
memory.h
ucommon::keyfile::defaults
keydata * defaults
Definition: keydata.h:165
linked.h
ucommon::OrderedIndex::begin
LinkedObject * begin(void) const
Definition: linked.h:270