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

FXSettings.h
1 /********************************************************************************
2 * *
3 * S e t t i n g s C l a s s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1998,2026 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (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 *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXSETTINGS_H
22 #define FXSETTINGS_H
23 
24 namespace FX {
25 
26 
34 class FXAPI FXSettings {
35 protected:
36  struct Entry {
37  FXString key; // Key
38  FXStringDictionary data; // Value
39  FXuint hash; // Hash of key
40  };
41 protected:
42  Entry *table; // Hash table
43  FXbool modified; // Changed
44 protected:
45 
46  // Change size of the table
47  FXbool no(FXival n);
48 
49  // Change number of used entries
50  void used(FXival u){ ((FXival*)(void*)table)[-2]=u; }
51 
52  // Change number of free entries
53  void free(FXival f){ ((FXival*)(void*)table)[-3]=f; }
54 
55  // Resize the table to the given size, keeping contents
56  FXbool resize(FXival n);
57 public:
58 
60  FXSettings();
61 
63  FXSettings(const FXSettings& other);
64 
66  FXival no() const { return ((FXival*)(void*)table)[-1]; }
67 
69  FXival used() const { return ((FXival*)(void*)table)[-2]; }
70 
72  FXival free() const { return ((FXival*)(void*)table)[-3]; }
73 
75  FXbool empty() const { return ((FXival*)(void*)table)[-1]<=1; }
76 
78  FXSettings& operator=(const FXSettings& other);
79 
81  FXSettings& adopt(FXSettings& other);
82 
84  FXbool isModified() const { return modified; }
85 
87  void setModified(FXbool mdfy=true){ modified=mdfy; }
88 
90  FXbool parseFile(const FXString& filename,FXbool mrk=true);
91 
93  FXbool unparseFile(const FXString& filename);
94 
96  FXbool parse(const FXString& string,FXbool mrk=true);
97 
99  FXbool unparse(FXString& string) const;
100 
102  FXival find(const FXchar* ky) const;
103 
105  FXival find(const FXString& ky) const { return find(ky.text()); }
106 
108  FXbool has(const FXchar* ky) const { return 0<=find(ky); }
109 
111  FXbool has(const FXString& ky) const { return 0<=find(ky); }
112 
114  FXStringDictionary& at(const FXchar* ky);
115 
117  const FXStringDictionary& at(const FXchar* ky) const;
118 
120  FXStringDictionary& at(const FXString& ky){ return at(ky.text()); }
121 
123  const FXStringDictionary& at(const FXString& ky) const { return at(ky.text()); }
124 
126  FXStringDictionary& operator[](const FXchar* ky){ return at(ky); }
127 
129  const FXStringDictionary& operator[](const FXchar* ky) const { return at(ky); }
130 
132  FXStringDictionary& operator[](const FXString& ky){ return at(ky); }
133 
135  const FXStringDictionary& operator[](const FXString& ky) const { return at(ky); }
136 
138  FXbool empty(FXival pos) const { return table[pos].key.empty(); }
139 
141  const FXString& key(FXival pos) const { return table[pos].key; }
142 
144  FXStringDictionary& data(FXival pos){ return table[pos].data; }
145 
147  const FXStringDictionary& data(FXival pos) const { return table[pos].data; }
148 
150  FXint readFormatEntry(const FXchar* section,const FXchar* name,const FXchar* fmt,...) const FX_SCANF(4,5) ;
151  FXint readFormatEntry(const FXchar* section,const FXString& name,const FXchar* fmt,...) const FX_SCANF(4,5) ;
152  FXint readFormatEntry(const FXString& section,const FXchar* name,const FXchar* fmt,...) const FX_SCANF(4,5) ;
153  FXint readFormatEntry(const FXString& section,const FXString& name,const FXchar* fmt,...) const FX_SCANF(4,5) ;
154 
156  FXint writeFormatEntry(const FXchar* section,const FXchar* name,const FXchar* fmt,...) FX_PRINTF(4,5) ;
157  FXint writeFormatEntry(const FXchar* section,const FXString& name,const FXchar* fmt,...) FX_PRINTF(4,5) ;
158  FXint writeFormatEntry(const FXString& section,const FXchar* name,const FXchar* fmt,...) FX_PRINTF(4,5) ;
159  FXint writeFormatEntry(const FXString& section,const FXString& name,const FXchar* fmt,...) FX_PRINTF(4,5) ;
160 
162  const FXchar* readStringEntry(const FXchar* section,const FXchar* name,const FXchar* def=nullptr) const;
163  const FXchar* readStringEntry(const FXchar* section,const FXString& name,const FXchar* def=nullptr) const;
164  const FXchar* readStringEntry(const FXString& section,const FXchar* name,const FXchar* def=nullptr) const;
165  const FXchar* readStringEntry(const FXString& section,const FXString& name,const FXchar* def=nullptr) const;
166 
168  FXbool writeStringEntry(const FXchar* section,const FXchar* name,const FXchar* val);
169  FXbool writeStringEntry(const FXchar* section,const FXString& name,const FXchar* val);
170  FXbool writeStringEntry(const FXString& section,const FXchar *name,const FXchar* val);
171  FXbool writeStringEntry(const FXString& section,const FXString& name,const FXchar* val);
172 
174  FXint readIntEntry(const FXchar* section,const FXchar* name,FXint def=0) const;
175  FXint readIntEntry(const FXchar* section,const FXString& name,FXint def=0) const;
176  FXint readIntEntry(const FXString& section,const FXchar* name,FXint def=0) const;
177  FXint readIntEntry(const FXString& section,const FXString& name,FXint def=0) const;
178 
180  FXbool writeIntEntry(const FXchar* section,const FXchar* name,FXint val);
181  FXbool writeIntEntry(const FXchar* section,const FXString& name,FXint val);
182  FXbool writeIntEntry(const FXString& section,const FXchar* name,FXint val);
183  FXbool writeIntEntry(const FXString& section,const FXString& name,FXint val);
184 
186  FXuint readUIntEntry(const FXchar* section,const FXchar* name,FXuint def=0) const;
187  FXuint readUIntEntry(const FXchar* section,const FXString& name,FXuint def=0) const;
188  FXuint readUIntEntry(const FXString& section,const FXchar* name,FXuint def=0) const;
189  FXuint readUIntEntry(const FXString& section,const FXString& name,FXuint def=0) const;
190 
192  FXbool writeUIntEntry(const FXchar* section,const FXchar* name,FXuint val);
193  FXbool writeUIntEntry(const FXchar* section,const FXString& name,FXuint val);
194  FXbool writeUIntEntry(const FXString& section,const FXchar* name,FXuint val);
195  FXbool writeUIntEntry(const FXString& section,const FXString& name,FXuint val);
196 
198  FXlong readLongEntry(const FXchar* section,const FXchar* name,FXlong def=0) const;
199  FXlong readLongEntry(const FXchar* section,const FXString& name,FXlong def=0) const;
200  FXlong readLongEntry(const FXString& section,const FXchar* name,FXlong def=0) const;
201  FXlong readLongEntry(const FXString& section,const FXString& name,FXlong def=0) const;
202 
204  FXbool writeLongEntry(const FXchar* section,const FXchar* name,FXlong val);
205  FXbool writeLongEntry(const FXchar* section,const FXString& name,FXlong val);
206  FXbool writeLongEntry(const FXString& section,const FXchar* name,FXlong val);
207  FXbool writeLongEntry(const FXString& section,const FXString& name,FXlong val);
208 
210  FXulong readULongEntry(const FXchar* section,const FXchar* name,FXulong def=0) const;
211  FXulong readULongEntry(const FXchar* section,const FXString& name,FXulong def=0) const;
212  FXulong readULongEntry(const FXString& section,const FXchar* name,FXulong def=0) const;
213  FXulong readULongEntry(const FXString& section,const FXString& name,FXulong def=0) const;
214 
216  FXbool writeULongEntry(const FXchar* section,const FXchar* name,FXulong val);
217  FXbool writeULongEntry(const FXchar* section,const FXString& name,FXulong val);
218  FXbool writeULongEntry(const FXString& section,const FXchar* name,FXulong val);
219  FXbool writeULongEntry(const FXString& section,const FXString& name,FXulong val);
220 
222  FXdouble readRealEntry(const FXchar* section,const FXchar* name,FXdouble def=0.0) const;
223  FXdouble readRealEntry(const FXchar* section,const FXString& name,FXdouble def=0.0) const;
224  FXdouble readRealEntry(const FXString& section,const FXchar* name,FXdouble def=0.0) const;
225  FXdouble readRealEntry(const FXString& section,const FXString& name,FXdouble def=0.0) const;
226 
228  FXbool writeRealEntry(const FXchar* section,const FXchar* name,FXdouble val);
229  FXbool writeRealEntry(const FXchar* section,const FXString& name,FXdouble val);
230  FXbool writeRealEntry(const FXString& section,const FXchar* name,FXdouble val);
231  FXbool writeRealEntry(const FXString& section,const FXString& name,FXdouble val);
232 
234  FXColor readColorEntry(const FXchar* section,const FXchar* name,FXColor def=0) const;
235  FXColor readColorEntry(const FXchar* section,const FXString& name,FXColor def=0) const;
236  FXColor readColorEntry(const FXString& section,const FXchar* name,FXColor def=0) const;
237  FXColor readColorEntry(const FXString& section,const FXString& name,FXColor def=0) const;
238 
240  FXbool writeColorEntry(const FXchar* section,const FXchar* name,FXColor val);
241  FXbool writeColorEntry(const FXchar* section,const FXString& name,FXColor val);
242  FXbool writeColorEntry(const FXString& section,const FXchar* name,FXColor val);
243  FXbool writeColorEntry(const FXString& section,const FXString& name,FXColor val);
244 
246  FXbool readBoolEntry(const FXchar* section,const FXchar* name,FXbool def=false) const;
247  FXbool readBoolEntry(const FXchar* section,const FXString& name,FXbool def=false) const;
248  FXbool readBoolEntry(const FXString& section,const FXchar* name,FXbool def=false) const;
249  FXbool readBoolEntry(const FXString& section,const FXString& name,FXbool def=false) const;
250 
252  FXbool writeBoolEntry(const FXchar* section,const FXchar* name,FXbool val);
253  FXbool writeBoolEntry(const FXchar* section,const FXString& name,FXbool val);
254  FXbool writeBoolEntry(const FXString& section,const FXchar* name,FXbool val);
255  FXbool writeBoolEntry(const FXString& section,const FXString& name,FXbool val);
256 
258  FXbool existingEntry(const FXchar* section,const FXchar* name) const;
259  FXbool existingEntry(const FXchar* section,const FXString& name) const;
260  FXbool existingEntry(const FXString& section,const FXchar* name) const;
261  FXbool existingEntry(const FXString& section,const FXString& name) const;
262 
264  FXbool existingSection(const FXchar* section) const;
265  FXbool existingSection(const FXString& section) const;
266 
268  void deleteEntry(const FXchar* section,const FXchar* name);
269  void deleteEntry(const FXchar* section,const FXString& name);
270  void deleteEntry(const FXString& section,const FXchar* name);
271  void deleteEntry(const FXString& section,const FXString& name);
272 
274  void deleteSection(const FXchar* section);
275  void deleteSection(const FXString& section);
276 
278  void clear();
279 
281  ~FXSettings();
282  };
283 
284 
285 }
286 
287 #endif
FXbool has(const FXchar *ky) const
Check if key is mapped.
Definition: FXSettings.h:108
FXival find(const FXString &ky) const
Find position of given key, returning -1 if not found.
Definition: FXSettings.h:105
FXStringDictionary & operator[](const FXString &ky)
Return reference to slot assocated with given key.
Definition: FXSettings.h:132
FXbool empty() const
See if map is empty.
Definition: FXSettings.h:75
const FXString & key(FXival pos) const
Return key at position pos.
Definition: FXSettings.h:141
void setModified(FXbool mdfy=true)
Mark as changed.
Definition: FXSettings.h:87
FXbool empty(FXival pos) const
Return true if slot is empty.
Definition: FXSettings.h:138
FXival no() const
Return the size of the table, including the empty slots.
Definition: FXSettings.h:66
FXbool has(const FXString &ky) const
Check if key is mapped.
Definition: FXSettings.h:111
FXchar * text()
Get text contents as pointer.
Definition: FXString.h:119
FXbool empty() const
See if string is empty.
Definition: FXString.h:125
FXival used() const
Return number of used slots in the table.
Definition: FXSettings.h:69
The Settings class manages a key-value database.
Definition: FXSettings.h:34
const FXStringDictionary & operator[](const FXchar *ky) const
Return constant reference to slot assocated with given key.
Definition: FXSettings.h:129
Definition: FX4Splitter.h:28
FXStringDictionary & operator[](const FXchar *ky)
Return reference to slot assocated with given key.
Definition: FXSettings.h:126
const FXStringDictionary & at(const FXString &ky) const
Return constant reference to slot assocated with given key.
Definition: FXSettings.h:123
FXStringDictionary & data(FXival pos)
Return reference to slot at position pos.
Definition: FXSettings.h:144
const FXStringDictionary & data(FXival pos) const
Return constant reference to slot at position pos.
Definition: FXSettings.h:147
const FXStringDictionary & operator[](const FXString &ky) const
Return constant reference to slot assocated with given key.
Definition: FXSettings.h:135
FXival free() const
Return number of free slots in the table.
Definition: FXSettings.h:72
FXStringDictionary & at(const FXString &ky)
Return reference to slot assocated with given key.
Definition: FXSettings.h:120
FXbool isModified() const
Is it modified.
Definition: FXSettings.h:84
The dictionary class maintains a fast-access hash table of entities indexed by a character string...
Definition: FXStringDictionary.h:31
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42
Definition: FXSettings.h:36

Copyright © 1997-2026 Jeroen van der Zijp