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,2006 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.33 2006/01/22 17:58:09 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 * String values can contain any character, and will be escaped when written
00042 * to the file.
00043 */
00044 class FXAPI FXSettings : public FXDict {
00045   FXDECLARE(FXSettings)
00046 protected:
00047   bool modified;
00048 protected:
00049   virtual void *createData(const void*);
00050   virtual void deleteData(void*);
00051   FXchar* dequote(FXchar* text) const;
00052   FXchar* enquote(FXchar* result,const FXchar* text);
00053   FXStringDict* insert(const FXchar* ky){ return (FXStringDict*)FXDict::insert(ky,NULL); }
00054   FXStringDict* replace(const FXchar* ky,FXStringDict* section){ return (FXStringDict*)FXDict::replace(ky,section,true); }
00055   FXStringDict* remove(const FXchar* ky){ return (FXStringDict*)FXDict::remove(ky); }
00056 public:
00057 
00058   /// Construct settings database.
00059   FXSettings();
00060 
00061   /// Construct copy of existing database.
00062   FXSettings(const FXSettings& orig);
00063 
00064   /// Assignment operator
00065   FXSettings &operator=(const FXSettings& orig);
00066 
00067   /// Parse a file containing a settings database.
00068   bool parseFile(const FXString& filename,bool mark);
00069 
00070   /// Unparse settings database into given file.
00071   bool unparseFile(const FXString& filename);
00072 
00073   /// Obtain the string dictionary for the given section
00074   FXStringDict* data(FXuint pos) const { return (FXStringDict*)FXDict::data(pos); }
00075 
00076   /// Find string dictionary for the given section; may be NULL
00077   FXStringDict* find(const FXchar *section) const { return (FXStringDict*)FXDict::find(section); }
00078 
00079   /// Read a formatted registry entry, using scanf-style format
00080   FXint readFormatEntry(const FXchar *section,const FXchar *key,const FXchar *fmt,...) FX_SCANF(4,5) ;
00081 
00082   /// Read a string registry entry; if no value is found, the default value def is returned
00083   const FXchar *readStringEntry(const FXchar *section,const FXchar *key,const FXchar *def=NULL);
00084 
00085   /// Read a integer registry entry; if no value is found, the default value def is returned
00086   FXint readIntEntry(const FXchar *section,const FXchar *key,FXint def=0);
00087 
00088   /// Read a unsigned integer registry entry; if no value is found, the default value def is returned
00089   FXuint readUnsignedEntry(const FXchar *section,const FXchar *key,FXuint def=0);
00090 
00091   /// Read a double-precision floating point registry entry; if no value is found, the default value def is returned
00092   FXdouble readRealEntry(const FXchar *section,const FXchar *key,FXdouble def=0.0);
00093 
00094   /// Read a color value registry entry; if no value is found, the default value def is returned
00095   FXColor readColorEntry(const FXchar *section,const FXchar *key,FXColor def=0);
00096 
00097   /// Read a boolean registry entry
00098   FXbool readBoolEntry(const FXchar *section,const FXchar *key,FXbool def=FALSE);
00099 
00100   /// Write a formatted registry entry, using printf-style format
00101   FXint writeFormatEntry(const FXchar *section,const FXchar *key,const FXchar *fmt,...) FX_PRINTF(4,5) ;
00102 
00103   /// Write a string registry entry
00104   bool writeStringEntry(const FXchar *section,const FXchar *key,const FXchar *val);
00105 
00106   /// Write a integer registry entry
00107   bool writeIntEntry(const FXchar *section,const FXchar *key,FXint val);
00108 
00109   /// Write a unsigned integer registry entry
00110   bool writeUnsignedEntry(const FXchar *section,const FXchar *key,FXuint val);
00111 
00112   /// Write a double-precision floating point registry entry
00113   bool writeRealEntry(const FXchar *section,const FXchar *key,FXdouble val);
00114 
00115   /// Write a color value entry
00116   bool writeColorEntry(const FXchar *section,const FXchar *key,FXColor val);
00117 
00118   /// Write a boolean value entry
00119   bool writeBoolEntry(const FXchar *section,const FXchar *key,FXbool val);
00120 
00121   /// Delete a registry entry
00122   bool deleteEntry(const FXchar *section,const FXchar *key);
00123 
00124   /// See if entry exists
00125   bool existingEntry(const FXchar *section,const FXchar *key);
00126 
00127   /// Delete section
00128   bool deleteSection(const FXchar *section);
00129 
00130   /// See if section exists
00131   bool existingSection(const FXchar *section);
00132 
00133   /// Clear all sections
00134   bool clear();
00135 
00136   /// Mark as changed
00137   void setModified(bool mdfy=true){ modified=mdfy; }
00138 
00139   /// Is it modified
00140   bool isModified() const { return modified; }
00141 
00142   /// Cleanup
00143   virtual ~FXSettings();
00144   };
00145 
00146 }
00147 
00148 #endif

Copyright © 1997-2005 Jeroen van der Zijp