Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

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_CFGFILE_H__
00020 #define __CS_CFGFILE_H__
00021 
00022 #include "iutil/cfgfile.h"
00023 #include "csutil/csvector.h"
00024 class csConfigNode;
00025 class csConfigIterator;
00026 
00030 class csConfigFile : public iConfigFile
00031 {
00032 public:
00033   SCF_DECLARE_IBASE;
00034 
00036   csConfigFile(const char *Filename = NULL, iVFS* = NULL);
00038   csConfigFile (iBase*);
00040   virtual ~csConfigFile();
00041 
00046   virtual const char *GetFileName () const;
00047 
00052   virtual iVFS* GetVFS () const;
00053 
00058   virtual void SetFileName (const char*, iVFS*);
00059 
00076   virtual bool Load (const char* iFileName, iVFS* = NULL, bool Merge = false,
00077     bool NewWins = true);
00078 
00083   virtual bool Save ();
00084 
00091   virtual bool Save (const char *iFileName, iVFS* = NULL);
00092 
00094   virtual void Clear();
00095 
00102   virtual iConfigIterator *Enumerate(const char *Subsection = NULL);
00103 
00105   virtual bool KeyExists(const char *Key) const;
00107   virtual bool SubsectionExists(const char *Subsection) const;
00108 
00110   virtual int GetInt(const char *Key, int Def) const;
00112   virtual float GetFloat(const char *Key, float Def = 0.0) const;
00114   virtual const char *GetStr(const char *Key, const char *Def = "") const;
00116   virtual bool GetBool(const char *Key, bool Def = false) const;
00118   virtual const char *GetComment(const char *Key) const;
00119 
00121   virtual void SetStr (const char *Key, const char *Val);
00123   virtual void SetInt (const char *Key, int Value);
00125   virtual void SetFloat (const char *Key, float Value);
00127   virtual void SetBool (const char *Key, bool Value);
00134   virtual bool SetComment (const char *Key, const char *Text);
00136   virtual void DeleteKey(const char *Key);
00138   virtual void SetEOFComment(const char *Text);
00140   virtual const char *GetEOFComment() const;
00141 
00142 private:
00143   friend class csConfigIterator;
00144 
00145   // pointer to the root node (there are always two unnamed nodes at the
00146   // beginning and end of the list to make inserting and deleting nodes
00147   // easier).
00148   csConfigNode *FirstNode, *LastNode;
00149   // list of all iterators for this config object. This is required because
00150   // changes to the configuration may affect the iterators (e.g. when
00151   // you delete a key). Sorry, but this can't be a typed vector!
00152   csVector *Iterators;
00153   // current file name and file system
00154   char *Filename;
00155   // the VFS filesystem used for this file (or NULL if not used)
00156   iVFS *VFS;
00157   // are the current contents of this object different from the contents
00158   // stored in the config file?
00159   bool Dirty;
00160   // final comment at the end of the configuration file
00161   char *EOFComment;
00162 
00163   // private initialization function
00164   void InitializeObject ();
00165   // load the configuration from a file, ignoring the dirty flag
00166   virtual bool LoadNow(const char *Filename, iVFS *vfs, bool overwrite);
00167   // load the configuration from a data buffer and add it to the current
00168   // configuration. This may modify the contents of the file buffer but
00169   // will not delete it. This function will set the dirty flag if any
00170   // options have been added or modified.
00171   virtual void LoadFromBuffer(char *Filedata, bool overwrite);
00172   // return a pointer to the named node or the first node of a subsection.
00173   csConfigNode *FindNode(const char *Name, bool isSubsection = false) const;
00174   // create a new node in the list
00175   csConfigNode *CreateNode(const char *Name);
00176   // deregister an iterator
00177   void RemoveIterator(csConfigIterator *it) const;
00178   // save file without looking for dirty flag
00179   virtual bool SaveNow(const char *Filename, iVFS *vfs) const;
00180 };
00181 
00182 #endif // __CS_CFGFILE_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000