csutil/cfgfile.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

csutil/cfgfile.h
Go to the documentation of this file.

    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
    00026 #include "csextern.h"
    00027 #include "csutil/array.h"
    00028 #include "csutil/scf_implementation.h"
    00029 #include "iutil/cfgfile.h"
    00030 #include "iutil/vfs.h"
    00031
    00032 class csConfigNode;
    00033 class csConfigIterator;
    00034 struct iCommandLineParser;
    00035
    00039 class CS_CRYSTALSPACE_EXPORT csConfigFile :
    00040   public scfImplementation1<csConfigFile, iConfigFile>
    00041 {
    00042 public:
    00044   csConfigFile(const char *Filename = 0, iVFS* = 0);
    00046   csConfigFile (iBase*);
    00048   virtual ~csConfigFile();
    00049
    00051   virtual bool IsEmpty() const;
    00052
    00054   virtual const char *GetFileName () const;
    00055
    00060   virtual iVFS* GetVFS () const;
    00061
    00066   virtual void SetFileName (const char*, iVFS*);
    00067
    00083   virtual bool Load (const char* iFileName, iVFS* = 0, bool Merge = false,
    00084     bool NewWins = true);
    00085
    00092   virtual void LoadFromBuffer(const char *Filedata, bool overwrite);
    00093
    00098   virtual bool Save ();
    00099
    00106   virtual bool Save (const char *iFileName, iVFS* = 0);
    00107
    00109   virtual void Clear();
    00110
    00117   virtual csPtr<iConfigIterator> Enumerate(const char *Subsection = 0);
    00118
    00120   virtual bool KeyExists(const char *Key) const;
    00122   virtual bool SubsectionExists(const char *Subsection) const;
    00123
    00125   virtual int GetInt(const char *Key, int Def) const;
    00127   virtual float GetFloat(const char *Key, float Def = 0.0) const;
    00129   virtual const char *GetStr(const char *Key, const char *Def = "") const;
    00131   virtual bool GetBool(const char *Key, bool Def = false) const;
    00133   virtual csPtr<iStringArray> GetTuple(const char *Key) const;
    00135   virtual const char *GetComment(const char *Key) const;
    00136
    00138   virtual void SetStr (const char *Key, const char *Val);
    00140   virtual void SetInt (const char *Key, int Value);
    00142   virtual void SetFloat (const char *Key, float Value);
    00144   virtual void SetBool (const char *Key, bool Value);
    00146   virtual void SetTuple (const char *Key, iStringArray* Value);
    00153   virtual bool SetComment (const char *Key, const char *Text);
    00155   virtual void DeleteKey(const char *Key);
    00157   virtual void SetEOFComment(const char *Text);
    00159   virtual const char *GetEOFComment() const;
    00160
    00169   virtual void ParseCommandLine (iCommandLineParser* cmdline, iVFS* vfs,
    00170     bool Merge = false, bool NewWins = true);
    00171 private:
    00172   friend class csConfigIterator;
    00173
    00174   /*
    00175    * pointer to the root node (there are always two unnamed nodes at the
    00176    * beginning and end of the list to make inserting and deleting nodes
    00177    * easier).
    00178    */
    00179   csConfigNode *FirstNode, *LastNode;
    00180   /*
    00181    * list of all iterators for this config object. This is required because
    00182    * changes to the configuration may affect the iterators (e.g. when
    00183    * you delete a key). Sorry, but this can't be a typed vector!
    00184    */
    00185   csArray<csConfigIterator*> *Iterators;
    00186   // current file name and file system
    00187   char *Filename;
    00188   // the VFS filesystem used for this file (or 0 if not used)
    00189   csRef<iVFS> VFS;
    00190   /*
    00191    * are the current contents of this object different from the contents
    00192    * stored in the config file?
    00193    */
    00194   bool Dirty;
    00195   // final comment at the end of the configuration file
    00196   char *EOFComment;
    00197
    00198   // private initialization function
    00199   void InitializeObject ();
    00200   // load the configuration from a file, ignoring the dirty flag
    00201   virtual bool LoadNow(const char *Filename, iVFS *vfs, bool overwrite);
    00202
    00203   // return a pointer to the named node or the first node of a subsection.
    00204   csConfigNode *FindNode(const char *Name, bool isSubsection = false) const;
    00205   // create a new node in the list
    00206   csConfigNode *CreateNode(const char *Name);
    00207   // deregister an iterator
    00208   void RemoveIterator(csConfigIterator *it) const;
    00209   // save file without looking for dirty flag
    00210   virtual bool SaveNow(const char *Filename, iVFS *vfs) const;
    00211 };
    00212
    00213 #endif // __CS_UTIL_CFGFILE_H__