![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * S e t t i n g s C l a s s * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1998,2009 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU Lesser General Public License as published by * 00010 * the Free Software Foundation; either version 3 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/> * 00020 ********************************************************************************* 00021 * $Id: FXSettings.h,v 1.49 2009/01/06 13:07:27 fox Exp $ * 00022 ********************************************************************************/ 00023 #ifndef FXSETTINGS_H 00024 #define FXSETTINGS_H 00025 00026 #ifndef FXDICT_H 00027 #include "FXDict.h" 00028 #endif 00029 00030 namespace FX { 00031 00032 00033 class FXStringDict; 00034 00035 00036 /** 00037 * The Settings class manages a key-value database. This is normally used as 00038 * part of Registry, but can also be used separately in applications that need 00039 * to maintain a key-value database in a file of their own. 00040 * String values can contain any character, and will be escaped when written 00041 * to the file. 00042 */ 00043 class FXAPI FXSettings : public FXDict { 00044 FXDECLARE(FXSettings) 00045 protected: 00046 FXbool modified; 00047 protected: 00048 virtual void *createData(void*); 00049 virtual void deleteData(void*); 00050 protected: 00051 FXStringDict* insert(const FXchar* ky){ return (FXStringDict*)FXDict::insert(ky,NULL); } 00052 FXStringDict* replace(const FXchar* ky,FXStringDict* section){ return (FXStringDict*)FXDict::replace(ky,section,true); } 00053 FXStringDict* remove(const FXchar* ky){ return (FXStringDict*)FXDict::remove(ky); } 00054 public: 00055 00056 /// Construct settings database. 00057 FXSettings(); 00058 00059 /// Construct copy of existing database. 00060 FXSettings(const FXSettings& orig); 00061 00062 /// Assignment operator 00063 FXSettings &operator=(const FXSettings& orig); 00064 00065 /// Is it modified 00066 FXbool isModified() const { return modified; } 00067 00068 /// Mark as changed 00069 void setModified(FXbool mdfy=true){ modified=mdfy; } 00070 00071 /// Parse a file containing a settings database. 00072 FXbool parseFile(const FXString& filename,FXbool mark); 00073 00074 /// Unparse settings database into given file. 00075 FXbool unparseFile(const FXString& filename); 00076 00077 /// Find string dictionary for the given section; may be NULL 00078 FXStringDict* find(const FXchar *section) const { return (FXStringDict*)FXDict::find(section); } 00079 00080 /// Obtain the string dictionary for the given section 00081 FXStringDict* data(FXint pos) const { return (FXStringDict*)FXDict::data(pos); } 00082 00083 /// Read a formatted registry entry, using scanf-style format 00084 FXint readFormatEntry(const FXchar *section,const FXchar *name,const FXchar *fmt,...) const FX_SCANF(4,5) ; 00085 FXint readFormatEntry(const FXString& section,const FXchar *name,const FXchar *fmt,...) const FX_SCANF(4,5) ; 00086 FXint readFormatEntry(const FXString& section,const FXString& name,const FXchar *fmt,...) const FX_SCANF(4,5) ; 00087 00088 /// Write a formatted registry entry, using printf-style format 00089 FXint writeFormatEntry(const FXchar *section,const FXchar *name,const FXchar *fmt,...) FX_PRINTF(4,5) ; 00090 FXint writeFormatEntry(const FXString& section,const FXchar *name,const FXchar *fmt,...) FX_PRINTF(4,5) ; 00091 FXint writeFormatEntry(const FXString& section,const FXString& name,const FXchar *fmt,...) FX_PRINTF(4,5) ; 00092 00093 /// Read a string registry entry; if no value is found, the default value def is returned 00094 const FXchar *readStringEntry(const FXchar *section,const FXchar *name,const FXchar *def=NULL) const; 00095 const FXchar *readStringEntry(const FXString& section,const FXchar *name,const FXchar *def=NULL) const; 00096 const FXchar *readStringEntry(const FXString& section,const FXString& name,const FXchar *def=NULL) const; 00097 00098 /// Write a string registry entry 00099 FXbool writeStringEntry(const FXchar *section,const FXchar *name,const FXchar *val); 00100 FXbool writeStringEntry(const FXString& section,const FXchar *name,const FXchar *val); 00101 FXbool writeStringEntry(const FXString& section,const FXString& name,const FXchar *val); 00102 00103 /// Read a integer registry entry; if no value is found, the default value def is returned 00104 FXint readIntEntry(const FXchar *section,const FXchar *name,FXint def=0) const; 00105 FXint readIntEntry(const FXString& section,const FXchar *name,FXint def=0) const; 00106 FXint readIntEntry(const FXString& section,const FXString& name,FXint def=0) const; 00107 00108 /// Write a integer registry entry 00109 FXbool writeIntEntry(const FXchar *section,const FXchar *name,FXint val); 00110 FXbool writeIntEntry(const FXString& section,const FXchar *name,FXint val); 00111 FXbool writeIntEntry(const FXString& section,const FXString& name,FXint val); 00112 00113 /// Read a unsigned integer registry entry; if no value is found, the default value def is returned 00114 FXuint readUIntEntry(const FXchar *section,const FXchar *name,FXuint def=0) const; 00115 FXuint readUIntEntry(const FXString& section,const FXchar *name,FXuint def=0) const; 00116 FXuint readUIntEntry(const FXString& section,const FXString& name,FXuint def=0) const; 00117 00118 /// Write a unsigned integer registry entry 00119 FXbool writeUIntEntry(const FXchar *section,const FXchar *name,FXuint val); 00120 FXbool writeUIntEntry(const FXString& section,const FXchar *name,FXuint val); 00121 FXbool writeUIntEntry(const FXString& section,const FXString& name,FXuint val); 00122 00123 /// Read a 64-bit long integer registry entry; if no value is found, the default value def is returned 00124 FXlong readLongEntry(const FXchar *section,const FXchar *name,FXlong def=0) const; 00125 FXlong readLongEntry(const FXString& section,const FXchar *name,FXlong def=0) const; 00126 FXlong readLongEntry(const FXString& section,const FXString& name,FXlong def=0) const; 00127 00128 /// Write a 64-bit long integer registry entry 00129 FXbool writeLongEntry(const FXchar *section,const FXchar *name,FXlong val); 00130 FXbool writeLongEntry(const FXString& section,const FXchar *name,FXlong val); 00131 FXbool writeLongEntry(const FXString& section,const FXString& name,FXlong val); 00132 00133 /// Read a 64-bit unsigned long integer registry entry; if no value is found, the default value def is returned 00134 FXulong readULongEntry(const FXchar *section,const FXchar *name,FXulong def=0) const; 00135 FXulong readULongEntry(const FXString& section,const FXchar *name,FXulong def=0) const; 00136 FXulong readULongEntry(const FXString& section,const FXString& name,FXulong def=0) const; 00137 00138 /// Write a 64-bit unsigned long integer registry entry 00139 FXbool writeULongEntry(const FXchar *section,const FXchar *name,FXulong val); 00140 FXbool writeULongEntry(const FXString& section,const FXchar *name,FXulong val); 00141 FXbool writeULongEntry(const FXString& section,const FXString& name,FXulong val); 00142 00143 /// Read a double-precision floating point registry entry; if no value is found, the default value def is returned 00144 FXdouble readRealEntry(const FXchar *section,const FXchar *name,FXdouble def=0.0) const; 00145 FXdouble readRealEntry(const FXString& section,const FXchar *name,FXdouble def=0.0) const; 00146 FXdouble readRealEntry(const FXString& section,const FXString& name,FXdouble def=0.0) const; 00147 00148 /// Write a double-precision floating point registry entry 00149 FXbool writeRealEntry(const FXchar *section,const FXchar *name,FXdouble val); 00150 FXbool writeRealEntry(const FXString& section,const FXchar *name,FXdouble val); 00151 FXbool writeRealEntry(const FXString& section,const FXString& name,FXdouble val); 00152 00153 /// Read a color value registry entry; if no value is found, the default value def is returned 00154 FXColor readColorEntry(const FXchar *section,const FXchar *name,FXColor def=0) const; 00155 FXColor readColorEntry(const FXString& section,const FXchar *name,FXColor def=0) const; 00156 FXColor readColorEntry(const FXString& section,const FXString& name,FXColor def=0) const; 00157 00158 /// Write a color value entry 00159 FXbool writeColorEntry(const FXchar *section,const FXchar *name,FXColor val); 00160 FXbool writeColorEntry(const FXString& section,const FXchar *name,FXColor val); 00161 FXbool writeColorEntry(const FXString& section,const FXString& name,FXColor val); 00162 00163 /// Read a boolean registry entry 00164 FXbool readBoolEntry(const FXchar *section,const FXchar *name,FXbool def=false) const; 00165 FXbool readBoolEntry(const FXString& section,const FXchar *name,FXbool def=false) const; 00166 FXbool readBoolEntry(const FXString& section,const FXString& name,FXbool def=false) const; 00167 00168 /// Write a boolean value entry 00169 FXbool writeBoolEntry(const FXchar *section,const FXchar *name,FXbool val); 00170 FXbool writeBoolEntry(const FXString& section,const FXchar *name,FXbool val); 00171 FXbool writeBoolEntry(const FXString& section,const FXString& name,FXbool val); 00172 00173 /// See if entry exists 00174 FXbool existingEntry(const FXchar *section,const FXchar *name) const; 00175 FXbool existingEntry(const FXString& section,const FXchar *name) const; 00176 FXbool existingEntry(const FXString& section,const FXString& name) const; 00177 00178 /// Delete a registry entry 00179 FXbool deleteEntry(const FXchar *section,const FXchar *name); 00180 FXbool deleteEntry(const FXString& section,const FXchar *name); 00181 FXbool deleteEntry(const FXString& section,const FXString& name); 00182 00183 /// See if section exists 00184 FXbool existingSection(const FXchar *section) const; 00185 FXbool existingSection(const FXString& section) const; 00186 00187 /// Delete section 00188 FXbool deleteSection(const FXchar *section); 00189 FXbool deleteSection(const FXString& section); 00190 00191 /// Clear all sections 00192 FXbool clear(); 00193 00194 /// Cleanup 00195 virtual ~FXSettings(); 00196 }; 00197 00198 } 00199 00200 #endif
![]() |