![]() |
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,2002 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (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 GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXSettings.h,v 1.18 2002/02/08 14:27:20 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXSETTINGS_H 00025 #define FXSETTINGS_H 00026 00027 #ifndef FXDICT_H 00028 #include "FXDict.h" 00029 #endif 00030 00031 00032 class FXStringDict; 00033 00034 00035 00036 /** 00037 * FXSettings is a key-value database. This is normally used as 00038 * part of FXRegistry, but can also be used separately in application 00039 * that need to maintain a key-value database of their own. 00040 */ 00041 class FXAPI FXSettings : public FXDict { 00042 FXDECLARE(FXSettings) 00043 protected: 00044 FXbool modified; // Changed settings 00045 protected: 00046 virtual void *createData(const void*); 00047 virtual void deleteData(void*); 00048 FXbool parseValue(FXchar* value,const FXchar* buffer); 00049 FXbool unparseValue(FXchar* buffer,const FXchar* value); 00050 FXStringDict* insert(const FXchar* ky){ return (FXStringDict*)FXDict::insert(ky,NULL); } 00051 FXStringDict* replace(const FXchar* ky,FXStringDict* section){ return (FXStringDict*)FXDict::replace(ky,section,TRUE); } 00052 FXStringDict* remove(const FXchar* ky){ return (FXStringDict*)FXDict::remove(ky); } 00053 private: 00054 FXSettings(const FXSettings&); 00055 FXSettings &operator=(const FXSettings&); 00056 public: 00057 00058 /// Construct settings database. 00059 FXSettings(); 00060 00061 /// Parse a file containing a settings database. 00062 FXbool parseFile(const FXString& filename,FXbool mark); 00063 00064 /// Unparse settings database into given file. 00065 FXbool unparseFile(const FXString& filename); 00066 00067 /// Obtain the string dictionary for the given section 00068 FXStringDict* data(FXuint pos) const { return (FXStringDict*)FXDict::data(pos); } 00069 00070 /// Find string dictionary for the given section 00071 FXStringDict* find(const FXchar *section) const { return (FXStringDict*)FXDict::find(section); } 00072 00073 /// Read a formatted registry entry, using scanf-style format 00074 FXint readFormatEntry(const FXchar *section,const FXchar *key,const FXchar *fmt,...) FX_SCANF(4,5) ; 00075 00076 /// Read a string registry entry; if no value is found, the default value def is returned 00077 const FXchar *readStringEntry(const FXchar *section,const FXchar *key,const FXchar *def=NULL); 00078 00079 /// Read a integer registry entry; if no value is found, the default value def is returned 00080 FXint readIntEntry(const FXchar *section,const FXchar *key,FXint def=0); 00081 00082 /// Read a unsigned integer registry entry; if no value is found, the default value def is returned 00083 FXuint readUnsignedEntry(const FXchar *section,const FXchar *key,FXuint def=0); 00084 00085 /// Read a double-precision floating point registry entry; if no value is found, the default value def is returned 00086 FXdouble readRealEntry(const FXchar *section,const FXchar *key,FXdouble def=0.0); 00087 00088 /// Read a color value registry entry; if no value is found, the default value def is returned 00089 FXColor readColorEntry(const FXchar *section,const FXchar *key,FXColor def=0); 00090 00091 /// Write a formatted registry entry, using printf-style format 00092 FXint writeFormatEntry(const FXchar *section,const FXchar *key,const FXchar *fmt,...) FX_PRINTF(4,5) ; 00093 00094 /// Write a string registry entry 00095 FXbool writeStringEntry(const FXchar *section,const FXchar *key,const FXchar *val); 00096 00097 /// Write a integer registry entry 00098 FXbool writeIntEntry(const FXchar *section,const FXchar *key,FXint val); 00099 00100 /// Write a unsigned integer registry entry 00101 FXbool writeUnsignedEntry(const FXchar *section,const FXchar *key,FXuint val); 00102 00103 /// Write a double-precision floating point registry entry 00104 FXbool writeRealEntry(const FXchar *section,const FXchar *key,FXdouble val); 00105 00106 /// Write a color value entry 00107 FXbool writeColorEntry(const FXchar *section,const FXchar *key,FXColor val); 00108 00109 /// Delete a registry entry 00110 FXbool deleteEntry(const FXchar *section,const FXchar *key); 00111 00112 /// See if entry exists 00113 FXbool existingEntry(const FXchar *section,const FXchar *key); 00114 00115 /// Delete section 00116 FXbool deleteSection(const FXchar *section); 00117 00118 /// See if section exists 00119 FXbool existingSection(const FXchar *section); 00120 00121 /// Clear all sections 00122 FXbool clear(); 00123 00124 /// Mark as changed 00125 void setModified(FXbool mdfy=TRUE){ modified=mdfy; } 00126 00127 /// Is it modified 00128 FXbool isModified() const { return modified; } 00129 00130 /// Cleanup 00131 virtual ~FXSettings(); 00132 }; 00133 00134 00135 #endif