csutil/cfgfile.h
00001 /* 00002 Copyright (C) 2001 by Martin Geisse <mgeisse@gmx.net> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_UTIL_CFGFILE_H__ 00020 #define __CS_UTIL_CFGFILE_H__ 00021 00022 #include "iutil/cfgfile.h" 00023 #include "iutil/vfs.h" 00024 #include "array.h" 00025 00026 class csConfigNode; 00027 class csConfigIterator; 00028 00032 class csConfigFile : public iConfigFile 00033 { 00034 public: 00035 SCF_DECLARE_IBASE; 00036 00038 csConfigFile(const char *Filename = 0, iVFS* = 0); 00040 csConfigFile (iBase*); 00042 virtual ~csConfigFile(); 00043 00045 virtual const char *GetFileName () const; 00046 00051 virtual iVFS* GetVFS () const; 00052 00057 virtual void SetFileName (const char*, iVFS*); 00058 00074 virtual bool Load (const char* iFileName, iVFS* = 0, bool Merge = false, 00075 bool NewWins = true); 00076 00081 virtual bool Save (); 00082 00089 virtual bool Save (const char *iFileName, iVFS* = 0); 00090 00092 virtual void Clear(); 00093 00100 virtual csPtr<iConfigIterator> Enumerate(const char *Subsection = 0); 00101 00103 virtual bool KeyExists(const char *Key) const; 00105 virtual bool SubsectionExists(const char *Subsection) const; 00106 00108 virtual int GetInt(const char *Key, int Def) const; 00110 virtual float GetFloat(const char *Key, float Def = 0.0) const; 00112 virtual const char *GetStr(const char *Key, const char *Def = "") const; 00114 virtual bool GetBool(const char *Key, bool Def = false) const; 00116 virtual const char *GetComment(const char *Key) const; 00117 00119 virtual void SetStr (const char *Key, const char *Val); 00121 virtual void SetInt (const char *Key, int Value); 00123 virtual void SetFloat (const char *Key, float Value); 00125 virtual void SetBool (const char *Key, bool Value); 00132 virtual bool SetComment (const char *Key, const char *Text); 00134 virtual void DeleteKey(const char *Key); 00136 virtual void SetEOFComment(const char *Text); 00138 virtual const char *GetEOFComment() const; 00139 00140 private: 00141 friend class csConfigIterator; 00142 00143 /* 00144 * pointer to the root node (there are always two unnamed nodes at the 00145 * beginning and end of the list to make inserting and deleting nodes 00146 * easier). 00147 */ 00148 csConfigNode *FirstNode, *LastNode; 00149 /* 00150 * list of all iterators for this config object. This is required because 00151 * changes to the configuration may affect the iterators (e.g. when 00152 * you delete a key). Sorry, but this can't be a typed vector! 00153 */ 00154 csArray<csConfigIterator*> *Iterators; 00155 // current file name and file system 00156 char *Filename; 00157 // the VFS filesystem used for this file (or 0 if not used) 00158 csRef<iVFS> VFS; 00159 /* 00160 * are the current contents of this object different from the contents 00161 * stored in the config file? 00162 */ 00163 bool Dirty; 00164 // final comment at the end of the configuration file 00165 char *EOFComment; 00166 00167 // private initialization function 00168 void InitializeObject (); 00169 // load the configuration from a file, ignoring the dirty flag 00170 virtual bool LoadNow(const char *Filename, iVFS *vfs, bool overwrite); 00171 /* 00172 * load the configuration from a data buffer and add it to the current 00173 * configuration. This may modify the contents of the file buffer but 00174 * will not delete it. This function will set the dirty flag if any 00175 * options have been added or modified. 00176 */ 00177 virtual void LoadFromBuffer(char *Filedata, bool overwrite); 00178 // return a pointer to the named node or the first node of a subsection. 00179 csConfigNode *FindNode(const char *Name, bool isSubsection = false) const; 00180 // create a new node in the list 00181 csConfigNode *CreateNode(const char *Name); 00182 // deregister an iterator 00183 void RemoveIterator(csConfigIterator *it) const; 00184 // save file without looking for dirty flag 00185 virtual bool SaveNow(const char *Filename, iVFS *vfs) const; 00186 }; 00187 00188 #endif // __CS_UTIL_CFGFILE_H__
Generated for Crystal Space by doxygen 1.2.18