00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
00059 FXSettings();
00060
00062 FXSettings(const FXSettings& orig);
00063
00065 FXSettings &operator=(const FXSettings& orig);
00066
00068 bool parseFile(const FXString& filename,bool mark);
00069
00071 bool unparseFile(const FXString& filename);
00072
00074 FXStringDict* data(FXuint pos) const { return (FXStringDict*)FXDict::data(pos); }
00075
00077 FXStringDict* find(const FXchar *section) const { return (FXStringDict*)FXDict::find(section); }
00078
00080 FXint readFormatEntry(const FXchar *section,const FXchar *key,const FXchar *fmt,...) FX_SCANF(4,5) ;
00081
00083 const FXchar *readStringEntry(const FXchar *section,const FXchar *key,const FXchar *def=NULL);
00084
00086 FXint readIntEntry(const FXchar *section,const FXchar *key,FXint def=0);
00087
00089 FXuint readUnsignedEntry(const FXchar *section,const FXchar *key,FXuint def=0);
00090
00092 FXdouble readRealEntry(const FXchar *section,const FXchar *key,FXdouble def=0.0);
00093
00095 FXColor readColorEntry(const FXchar *section,const FXchar *key,FXColor def=0);
00096
00098 FXbool readBoolEntry(const FXchar *section,const FXchar *key,FXbool def=FALSE);
00099
00101 FXint writeFormatEntry(const FXchar *section,const FXchar *key,const FXchar *fmt,...) FX_PRINTF(4,5) ;
00102
00104 bool writeStringEntry(const FXchar *section,const FXchar *key,const FXchar *val);
00105
00107 bool writeIntEntry(const FXchar *section,const FXchar *key,FXint val);
00108
00110 bool writeUnsignedEntry(const FXchar *section,const FXchar *key,FXuint val);
00111
00113 bool writeRealEntry(const FXchar *section,const FXchar *key,FXdouble val);
00114
00116 bool writeColorEntry(const FXchar *section,const FXchar *key,FXColor val);
00117
00119 bool writeBoolEntry(const FXchar *section,const FXchar *key,FXbool val);
00120
00122 bool deleteEntry(const FXchar *section,const FXchar *key);
00123
00125 bool existingEntry(const FXchar *section,const FXchar *key);
00126
00128 bool deleteSection(const FXchar *section);
00129
00131 bool existingSection(const FXchar *section);
00132
00134 bool clear();
00135
00137 void setModified(bool mdfy=true){ modified=mdfy; }
00138
00140 bool isModified() const { return modified; }
00141
00143 virtual ~FXSettings();
00144 };
00145
00146
00147 namespace FXSettingsHelpers
00148 {
00151 template<typename type> inline void rwSetting(bool save, FXSettings &settings, const FXchar *section, const FXchar *name, type &val, const type &defval);
00152 template<> inline void rwSetting<bool>(bool save, FXSettings &settings, const FXchar *section, const FXchar *name, bool &val, const bool &defval)
00153 {
00154 save ? settings.writeIntEntry(section, name, val)
00155 : (val=(0!=settings.readIntEntry(section, name, defval)));
00156 }
00157 template<> inline void rwSetting<FXint>(bool save, FXSettings &settings, const FXchar *section, const FXchar *name, FXint &val, const FXint &defval)
00158 {
00159 save ? settings.writeIntEntry(section, name, val)
00160 : (val=settings.readIntEntry(section, name, defval));
00161 }
00162 template<> inline void rwSetting<FXuint>(bool save, FXSettings &settings, const FXchar *section, const FXchar *name, FXuint &val, const FXuint &defval)
00163 {
00164 save ? settings.writeUnsignedEntry(section, name, val)
00165 : (val=settings.readUnsignedEntry(section, name, defval));
00166 }
00167
00168
00169
00170
00171
00172
00173 template<> inline void rwSetting<double>(bool save, FXSettings &settings, const FXchar *section, const FXchar *name, double &val, const double &defval)
00174 {
00175 save ? settings.writeRealEntry(section, name, val)
00176 : (val=settings.readRealEntry(section, name, defval));
00177 }
00178 template<> inline void rwSetting<FXString>(bool save, FXSettings &settings, const FXchar *section, const FXchar *name, FXString &val, const FXString &defval)
00179 {
00180 save ? settings.writeStringEntry(section, name, val.text())
00181 : (val=settings.readStringEntry(section, name, defval.text()), true);
00182 }
00183
00184 template<typename type> inline void rwSetting(bool save, FXSettings &settings, const FXchar *section, const FXchar *name, type &val, int defval)
00185 {
00186 rwSetting<type>(save, settings, section, name, val, (type) defval);
00187 }
00188 }
00189
00190 }
00191
00192 #endif
00193