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,2005 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.24 2005/02/02 16:37:40 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXSETTINGS_H 00025 #define FXSETTINGS_H 00026 00027 #ifndef FXDICT_H 00028 #include "FXDict.h" 00029 #endif 00030 00031 namespace FX { 00032 00033 00034 class FXStringDict; 00035 00036 00037 /** 00038 * The Settings class manages a key-value database. This is normally used as 00039 * part of Registry, but can also be used separately in applications that need 00040 * to maintain a key-value database in a file of their own. 00041 */ 00042 class FXAPI FXSettings : public FXDict { 00043 FXDECLARE(FXSettings) 00044 protected: 00045 FXbool modified; // Changed settings 00046 protected: 00047 virtual void *createData(const void*); 00048 virtual void deleteData(void*); 00049 FXbool parseValue(FXchar* value,const FXchar* buffer); 00050 FXbool unparseValue(FXchar* buffer,const FXchar* value); 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 private: 00055 FXSettings(const FXSettings&); 00056 FXSettings &operator=(const FXSettings&); 00057 public: 00058 00059 /// Construct settings database. 00060 FXSettings(); 00061 00062 /// Parse a file containing a settings database. 00063 FXbool parseFile(const FXString& filename,FXbool mark); 00064 00065 /// Unparse settings database into given file. 00066 FXbool unparseFile(const FXString& filename); 00067 00068 /// Obtain the string dictionary for the given section 00069 FXStringDict* data(FXuint pos) const { return (FXStringDict*)FXDict::data(pos); } 00070 00071 /// Find string dictionary for the given section; may be NULL 00072 FXStringDict* find(const FXchar *section) const { return (FXStringDict*)FXDict::find(section); } 00073 00074 /// Read a formatted registry entry, using scanf-style format 00075 FXint readFormatEntry(const FXchar *section,const FXchar *key,const FXchar *fmt,...) FX_SCANF(4,5) ; 00076 00077 /// Read a string registry entry; if no value is found, the default value def is returned 00078 const FXchar *readStringEntry(const FXchar *section,const FXchar *key,const FXchar *def=NULL); 00079 00080 /// Read a integer registry entry; if no value is found, the default value def is returned 00081 FXint readIntEntry(const FXchar *section,const FXchar *key,FXint def=0); 00082 00083 /// Read a unsigned integer registry entry; if no value is found, the default value def is returned 00084 FXuint readUnsignedEntry(const FXchar *section,const FXchar *key,FXuint def=0); 00085 00086 /// Read a double-precision floating point registry entry; if no value is found, the default value def is returned 00087 FXdouble readRealEntry(const FXchar *section,const FXchar *key,FXdouble def=0.0); 00088 00089 /// Read a color value registry entry; if no value is found, the default value def is returned 00090 FXColor readColorEntry(const FXchar *section,const FXchar *key,FXColor def=0); 00091 00092 /// Write a formatted registry entry, using printf-style format 00093 FXint writeFormatEntry(const FXchar *section,const FXchar *key,const FXchar *fmt,...) FX_PRINTF(4,5) ; 00094 00095 /// Write a string registry entry 00096 FXbool writeStringEntry(const FXchar *section,const FXchar *key,const FXchar *val); 00097 00098 /// Write a integer registry entry 00099 FXbool writeIntEntry(const FXchar *section,const FXchar *key,FXint val); 00100 00101 /// Write a unsigned integer registry entry 00102 FXbool writeUnsignedEntry(const FXchar *section,const FXchar *key,FXuint val); 00103 00104 /// Write a double-precision floating point registry entry 00105 FXbool writeRealEntry(const FXchar *section,const FXchar *key,FXdouble val); 00106 00107 /// Write a color value entry 00108 FXbool writeColorEntry(const FXchar *section,const FXchar *key,FXColor val); 00109 00110 /// Delete a registry entry 00111 FXbool deleteEntry(const FXchar *section,const FXchar *key); 00112 00113 /// See if entry exists 00114 FXbool existingEntry(const FXchar *section,const FXchar *key); 00115 00116 /// Delete section 00117 FXbool deleteSection(const FXchar *section); 00118 00119 /// See if section exists 00120 FXbool existingSection(const FXchar *section); 00121 00122 /// Clear all sections 00123 FXbool clear(); 00124 00125 /// Mark as changed 00126 void setModified(FXbool mdfy=TRUE){ modified=mdfy; } 00127 00128 /// Is it modified 00129 FXbool isModified() const { return modified; } 00130 00131 /// Cleanup 00132 virtual ~FXSettings(); 00133 }; 00134 00135 } 00136 00137 #endif
Copyright © 1997-2005 Jeroen van der Zijp |