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

FXSettings.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                           S e t t i n g s   C l a s s                         *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1998,2010 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 #ifndef FXSETTINGS_H
00022 #define FXSETTINGS_H
00023 
00024 #ifndef FXDICT_H
00025 #include "FXDict.h"
00026 #endif
00027 
00028 namespace FX {
00029 
00030 
00031 class FXStringDict;
00032 
00033 
00034 /**
00035 * The Settings class manages a key-value database.  This is normally used as
00036 * part of Registry, but can also be used separately in applications that need
00037 * to maintain a key-value database in a file of their own.
00038 * String values can contain any character, and will be escaped when written
00039 * to the file.
00040 */
00041 class FXAPI FXSettings : public FXDict {
00042   FXDECLARE(FXSettings)
00043 protected:
00044   FXbool modified;
00045 protected:
00046   virtual void *createData(void*);
00047   virtual void deleteData(void*);
00048 protected:
00049   FXStringDict* insert(const FXchar* ky){ return (FXStringDict*)FXDict::insert(ky,NULL); }
00050   FXStringDict* replace(const FXchar* ky,FXStringDict* section){ return (FXStringDict*)FXDict::replace(ky,section,true); }
00051   FXStringDict* remove(const FXchar* ky){ return (FXStringDict*)FXDict::remove(ky); }
00052 public:
00053 
00054   /// Construct settings database.
00055   FXSettings();
00056 
00057   /// Construct copy of existing database.
00058   FXSettings(const FXSettings& orig);
00059 
00060   /// Assignment operator
00061   FXSettings &operator=(const FXSettings& orig);
00062 
00063   /// Is it modified
00064   FXbool isModified() const { return modified; }
00065 
00066   /// Mark as changed
00067   void setModified(FXbool mdfy=true){ modified=mdfy; }
00068 
00069   /// Parse a file containing a settings database.
00070   FXbool parseFile(const FXString& filename,FXbool mark);
00071 
00072   /// Unparse settings database into given file.
00073   FXbool unparseFile(const FXString& filename);
00074 
00075   /// Find string dictionary for the given section; may be NULL
00076   FXStringDict* find(const FXchar *section) const { return (FXStringDict*)FXDict::find(section); }
00077   FXStringDict* find(const FXString& section) const { return (FXStringDict*)FXDict::find(section.text()); }
00078 
00079   /// Obtain the string dictionary for the given section
00080   FXStringDict* data(FXint pos) const { return (FXStringDict*)FXDict::data(pos); }
00081 
00082   /// Read a formatted registry entry, using scanf-style format
00083   FXint readFormatEntry(const FXchar *section,const FXchar *name,const FXchar *fmt,...) const FX_SCANF(4,5) ;
00084   FXint readFormatEntry(const FXString& section,const FXchar *name,const FXchar *fmt,...) const FX_SCANF(4,5) ;
00085   FXint readFormatEntry(const FXString& section,const FXString& name,const FXchar *fmt,...) const FX_SCANF(4,5) ;
00086 
00087   /// Write a formatted registry entry, using printf-style format
00088   FXint writeFormatEntry(const FXchar *section,const FXchar *name,const FXchar *fmt,...) FX_PRINTF(4,5) ;
00089   FXint writeFormatEntry(const FXString& section,const FXchar *name,const FXchar *fmt,...) FX_PRINTF(4,5) ;
00090   FXint writeFormatEntry(const FXString& section,const FXString& name,const FXchar *fmt,...) FX_PRINTF(4,5) ;
00091 
00092   /// Read a string registry entry; if no value is found, the default value def is returned
00093   const FXchar *readStringEntry(const FXchar *section,const FXchar *name,const FXchar *def=NULL) const;
00094   const FXchar *readStringEntry(const FXString& section,const FXchar *name,const FXchar *def=NULL) const;
00095   const FXchar *readStringEntry(const FXString& section,const FXString& name,const FXchar *def=NULL) const;
00096 
00097   /// Write a string registry entry
00098   FXbool writeStringEntry(const FXchar *section,const FXchar *name,const FXchar *val);
00099   FXbool writeStringEntry(const FXString& section,const FXchar *name,const FXchar *val);
00100   FXbool writeStringEntry(const FXString& section,const FXString& name,const FXchar *val);
00101 
00102   /// Read a integer registry entry; if no value is found, the default value def is returned
00103   FXint readIntEntry(const FXchar *section,const FXchar *name,FXint def=0) const;
00104   FXint readIntEntry(const FXString& section,const FXchar *name,FXint def=0) const;
00105   FXint readIntEntry(const FXString& section,const FXString& name,FXint def=0) const;
00106 
00107   /// Write a integer registry entry
00108   FXbool writeIntEntry(const FXchar *section,const FXchar *name,FXint val);
00109   FXbool writeIntEntry(const FXString& section,const FXchar *name,FXint val);
00110   FXbool writeIntEntry(const FXString& section,const FXString& name,FXint val);
00111 
00112   /// Read a unsigned integer registry entry; if no value is found, the default value def is returned
00113   FXuint readUIntEntry(const FXchar *section,const FXchar *name,FXuint def=0) const;
00114   FXuint readUIntEntry(const FXString& section,const FXchar *name,FXuint def=0) const;
00115   FXuint readUIntEntry(const FXString& section,const FXString& name,FXuint def=0) const;
00116 
00117   /// Write a unsigned integer registry entry
00118   FXbool writeUIntEntry(const FXchar *section,const FXchar *name,FXuint val);
00119   FXbool writeUIntEntry(const FXString& section,const FXchar *name,FXuint val);
00120   FXbool writeUIntEntry(const FXString& section,const FXString& name,FXuint val);
00121 
00122   /// Read a 64-bit long integer registry entry; if no value is found, the default value def is returned
00123   FXlong readLongEntry(const FXchar *section,const FXchar *name,FXlong def=0) const;
00124   FXlong readLongEntry(const FXString& section,const FXchar *name,FXlong def=0) const;
00125   FXlong readLongEntry(const FXString& section,const FXString& name,FXlong def=0) const;
00126 
00127   /// Write a 64-bit long integer registry entry
00128   FXbool writeLongEntry(const FXchar *section,const FXchar *name,FXlong val);
00129   FXbool writeLongEntry(const FXString& section,const FXchar *name,FXlong val);
00130   FXbool writeLongEntry(const FXString& section,const FXString& name,FXlong val);
00131 
00132   /// Read a 64-bit unsigned long integer registry entry; if no value is found, the default value def is returned
00133   FXulong readULongEntry(const FXchar *section,const FXchar *name,FXulong def=0) const;
00134   FXulong readULongEntry(const FXString& section,const FXchar *name,FXulong def=0) const;
00135   FXulong readULongEntry(const FXString& section,const FXString& name,FXulong def=0) const;
00136 
00137   /// Write a 64-bit unsigned long integer registry entry
00138   FXbool writeULongEntry(const FXchar *section,const FXchar *name,FXulong val);
00139   FXbool writeULongEntry(const FXString& section,const FXchar *name,FXulong val);
00140   FXbool writeULongEntry(const FXString& section,const FXString& name,FXulong val);
00141 
00142   /// Read a double-precision floating point registry entry; if no value is found, the default value def is returned
00143   FXdouble readRealEntry(const FXchar *section,const FXchar *name,FXdouble def=0.0) const;
00144   FXdouble readRealEntry(const FXString& section,const FXchar *name,FXdouble def=0.0) const;
00145   FXdouble readRealEntry(const FXString& section,const FXString& name,FXdouble def=0.0) const;
00146 
00147   /// Write a double-precision floating point registry entry
00148   FXbool writeRealEntry(const FXchar *section,const FXchar *name,FXdouble val);
00149   FXbool writeRealEntry(const FXString& section,const FXchar *name,FXdouble val);
00150   FXbool writeRealEntry(const FXString& section,const FXString& name,FXdouble val);
00151 
00152   /// Read a color value registry entry; if no value is found, the default value def is returned
00153   FXColor readColorEntry(const FXchar *section,const FXchar *name,FXColor def=0) const;
00154   FXColor readColorEntry(const FXString& section,const FXchar *name,FXColor def=0) const;
00155   FXColor readColorEntry(const FXString& section,const FXString& name,FXColor def=0) const;
00156 
00157   /// Write a color value entry
00158   FXbool writeColorEntry(const FXchar *section,const FXchar *name,FXColor val);
00159   FXbool writeColorEntry(const FXString& section,const FXchar *name,FXColor val);
00160   FXbool writeColorEntry(const FXString& section,const FXString& name,FXColor val);
00161 
00162   /// Read a boolean registry entry
00163   FXbool readBoolEntry(const FXchar *section,const FXchar *name,FXbool def=false) const;
00164   FXbool readBoolEntry(const FXString& section,const FXchar *name,FXbool def=false) const;
00165   FXbool readBoolEntry(const FXString& section,const FXString& name,FXbool def=false) const;
00166 
00167   /// Write a boolean value entry
00168   FXbool writeBoolEntry(const FXchar *section,const FXchar *name,FXbool val);
00169   FXbool writeBoolEntry(const FXString& section,const FXchar *name,FXbool val);
00170   FXbool writeBoolEntry(const FXString& section,const FXString& name,FXbool val);
00171 
00172   /// See if entry exists
00173   FXbool existingEntry(const FXchar *section,const FXchar *name) const;
00174   FXbool existingEntry(const FXString& section,const FXchar *name) const;
00175   FXbool existingEntry(const FXString& section,const FXString& name) const;
00176 
00177   /// Delete a registry entry
00178   FXbool deleteEntry(const FXchar *section,const FXchar *name);
00179   FXbool deleteEntry(const FXString& section,const FXchar *name);
00180   FXbool deleteEntry(const FXString& section,const FXString& name);
00181 
00182   /// See if section exists
00183   FXbool existingSection(const FXchar *section) const;
00184   FXbool existingSection(const FXString& section) const;
00185 
00186   /// Delete section
00187   FXbool deleteSection(const FXchar *section);
00188   FXbool deleteSection(const FXString& section);
00189 
00190   /// Clear all sections
00191   FXbool clear();
00192 
00193   /// Cleanup
00194   virtual ~FXSettings();
00195   };
00196 
00197 }
00198 
00199 #endif

Copyright © 1997-2010 Jeroen van der Zijp