• Main Page
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

ucommon/keydata.h

Go to the documentation of this file.
00001 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
00002 //
00003 // This file is part of GNU uCommon C++.
00004 //
00005 // GNU uCommon C++ is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser General Public License as published 
00007 // by the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // GNU uCommon C++ is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with GNU uCommon C++.  If not, see <http://www.gnu.org/licenses/>.
00017 
00030 #ifndef _UCOMMON_KEYDATA_H_
00031 #define _UCOMMON_KEYDATA_H_
00032 
00033 #ifndef _UCOMMON_CONFIG_H_
00034 #include <ucommon/platform.h>
00035 #endif
00036 
00037 #ifndef  _UCOMMON_LINKED_H_
00038 #include <ucommon/linked.h>
00039 #endif
00040 
00041 #ifndef  _UCOMMON_MEMORY_H_
00042 #include <ucommon/memory.h>
00043 #endif
00044 
00045 NAMESPACE_UCOMMON
00046 
00047 class keyfile;
00048 
00057 class __EXPORT keydata : public OrderedObject
00058 {
00059 private:
00060     friend class keyfile;
00061     OrderedIndex index;
00062     keydata(keyfile *file);
00063     keydata(keyfile *file, const char *id);
00064     const char *name;
00065     keyfile *root;
00066 
00067 public:
00073     class __LOCAL keyvalue : public OrderedObject
00074     {
00075     private:
00076         friend class keydata;
00077         friend class keyfile;
00078         keyvalue(keyfile *allocator, keydata *section, const char *key, const char *data);
00079     public:
00080         const char *id;
00081         const char *value;
00082     };
00083 
00084     friend class keyvalue;
00085 
00091     const char *get(const char *id) const;
00092 
00098     inline const char *operator()(const char *id) const
00099         {return get(id);};
00100 
00108     void set(const char *id, const char *value);
00109 
00115     void clear(const char *id);
00116     
00121     inline const char *get(void) const
00122         {return name;};
00123 
00128     inline keyvalue *begin(void) const
00129         {return (keyvalue *)index.begin();};
00130 
00135     inline keyvalue *end(void) const
00136         {return (keyvalue*)index.end();};
00137 
00141     typedef linked_pointer<keyvalue> iterator;
00142 };  
00143 
00150 class __EXPORT keyfile : public memalloc
00151 {
00152 private:
00153     friend class keydata;
00154     OrderedIndex index;
00155     keydata *defaults;
00156 
00157     keydata *create(const char *section);
00158 
00159 public:
00164     keyfile(size_t pagesize = 0);
00165 
00171     keyfile(const char *path, size_t pagesize = 0);
00172 
00179     void load(const char *path);
00180 
00186     keydata *get(const char *section) const;
00187 
00188     inline keydata *operator()(const char *section) const
00189         {return get(section);};
00190 
00191     inline keydata *operator[](const char *section) const
00192         {return get(section);};
00193 
00198     inline keydata *get(void) const
00199         {return defaults;};
00200 
00205     inline keydata *begin(void) const
00206         {return (keydata *)index.begin();};
00207 
00212     inline keydata *end(void) const
00213         {return (keydata *)index.end();};
00214     
00218     typedef linked_pointer<keydata> iterator;
00219 };
00220 
00221 END_NAMESPACE
00222 
00223 #endif

Generated on Sun Sep 4 2011 for UCommon by  doxygen 1.7.1