Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXSettings.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * S e t t i n g s C l a s s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1998,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXSettings.h,v 1.33 2006/01/22 17:58:09 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXSETTINGS_H
25 #define FXSETTINGS_H
26 
27 #ifndef FXDICT_H
28 #include "FXDict.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 class FXStringDict;
35 
36 
37 /**
38 * The Settings class manages a key-value database. This is normally used as
39 * part of Registry, but can also be used separately in applications that need
40 * to maintain a key-value database in a file of their own.
41 * String values can contain any character, and will be escaped when written
42 * to the file.
43 */
44 class FXAPI FXSettings : public FXDict {
46 protected:
47  bool modified;
48 protected:
49  virtual void *createData(const void*);
50  virtual void deleteData(void*);
51  FXchar* dequote(FXchar* text) const;
52  FXchar* enquote(FXchar* result,const FXchar* text);
53  FXStringDict* insert(const FXchar* ky){ return (FXStringDict*)FXDict::insert(ky,NULL); }
54  FXStringDict* replace(const FXchar* ky,FXStringDict* section){ return (FXStringDict*)FXDict::replace(ky,section,true); }
55  FXStringDict* remove(const FXchar* ky){ return (FXStringDict*)FXDict::remove(ky); }
56 public:
57 
58  /// Construct settings database.
59  FXSettings();
60 
61  /// Construct copy of existing database.
62  FXSettings(const FXSettings& orig);
63 
64  /// Assignment operator
65  FXSettings &operator=(const FXSettings& orig);
66 
67  /// Parse a file containing a settings database.
68  bool parseFile(const FXString& filename,bool mark);
69 
70  /// Unparse settings database into given file.
71  bool unparseFile(const FXString& filename);
72 
73  /// Obtain the string dictionary for the given section
74  FXStringDict* data(FXuint pos) const { return (FXStringDict*)FXDict::data(pos); }
75 
76  /// Find string dictionary for the given section; may be NULL
77  FXStringDict* find(const FXchar *section) const { return (FXStringDict*)FXDict::find(section); }
78 
79  /// Read a formatted registry entry, using scanf-style format
80  FXint readFormatEntry(const FXchar *section,const FXchar *key,const FXchar *fmt,...) FX_SCANF(4,5) ;
81 
82  /// Read a string registry entry; if no value is found, the default value def is returned
83  const FXchar *readStringEntry(const FXchar *section,const FXchar *key,const FXchar *def=NULL);
84 
85  /// Read a integer registry entry; if no value is found, the default value def is returned
86  FXint readIntEntry(const FXchar *section,const FXchar *key,FXint def=0);
87 
88  /// Read a unsigned integer registry entry; if no value is found, the default value def is returned
89  FXuint readUnsignedEntry(const FXchar *section,const FXchar *key,FXuint def=0);
90 
91  /// Read a double-precision floating point registry entry; if no value is found, the default value def is returned
92  FXdouble readRealEntry(const FXchar *section,const FXchar *key,FXdouble def=0.0);
93 
94  /// Read a color value registry entry; if no value is found, the default value def is returned
95  FXColor readColorEntry(const FXchar *section,const FXchar *key,FXColor def=0);
96 
97  /// Read a boolean registry entry
98  FXbool readBoolEntry(const FXchar *section,const FXchar *key,FXbool def=FALSE);
99 
100  /// Write a formatted registry entry, using printf-style format
101  FXint writeFormatEntry(const FXchar *section,const FXchar *key,const FXchar *fmt,...) FX_PRINTF(4,5) ;
102 
103  /// Write a string registry entry
104  bool writeStringEntry(const FXchar *section,const FXchar *key,const FXchar *val);
105 
106  /// Write a integer registry entry
107  bool writeIntEntry(const FXchar *section,const FXchar *key,FXint val);
108 
109  /// Write a unsigned integer registry entry
110  bool writeUnsignedEntry(const FXchar *section,const FXchar *key,FXuint val);
111 
112  /// Write a double-precision floating point registry entry
113  bool writeRealEntry(const FXchar *section,const FXchar *key,FXdouble val);
114 
115  /// Write a color value entry
116  bool writeColorEntry(const FXchar *section,const FXchar *key,FXColor val);
117 
118  /// Write a boolean value entry
119  bool writeBoolEntry(const FXchar *section,const FXchar *key,FXbool val);
120 
121  /// Delete a registry entry
122  bool deleteEntry(const FXchar *section,const FXchar *key);
123 
124  /// See if entry exists
125  bool existingEntry(const FXchar *section,const FXchar *key);
126 
127  /// Delete section
128  bool deleteSection(const FXchar *section);
129 
130  /// See if section exists
131  bool existingSection(const FXchar *section);
132 
133  /// Clear all sections
134  bool clear();
135 
136  /// Mark as changed
137  void setModified(bool mdfy=true){ modified=mdfy; }
138 
139  /// Is it modified
140  bool isModified() const { return modified; }
141 
142  /// Cleanup
143  virtual ~FXSettings();
144  };
145 
146 }
147 
148 #endif
void * find(const FXchar *ky) const
Find data pointer given key.
FXString enquote(const FXString &file, bool forcequotes=false)
Enquote filename to make safe for shell.
char FXchar
Definition: fxdefs.h:387
unsigned int FXuint
Definition: fxdefs.h:396
#define FX_SCANF(fmt, arg)
Definition: fxdefs.h:147
FXString dequote(const FXString &file)
Dequote filename to get original again.
#define FXAPI
Definition: fxdefs.h:122
FXuchar FXbool
Definition: fxdefs.h:393
void * insert(const FXchar *ky, const void *ptr, bool mrk=false)
Insert a new entry into the table given key and mark.
String dictionary maps a character string to a character string.
Definition: FXStringDict.h:37
#define NULL
Definition: fxdefs.h:41
FXuint FXColor
Definition: fxdefs.h:454
void * data(FXuint pos) const
return data pointer at position pos.
Definition: FXDict.h:108
The Settings class manages a key-value database.
Definition: FXSettings.h:44
void * remove(const FXchar *ky)
Remove data given key.
double FXdouble
Definition: fxdefs.h:399
int FXint
Definition: fxdefs.h:397
The dictionary class maintains a fast-access hash table of entities indexed by a character string...
Definition: FXDict.h:41
#define FALSE
Definition: fxdefs.h:35
#define FX_PRINTF(fmt, arg)
Definition: fxdefs.h:146
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92
void * replace(const FXchar *ky, const void *ptr, bool mrk=false)
Replace data at key, if the entry's mark is less than or equal to the given mark. ...
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33

Copyright © 1997-2005 Jeroen van der Zijp