CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

csutil/cfgdoc.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2004 by Jorrit Tyberghein
00003               (C) 2004 by Frank Richter
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_UTIL_CFGDOC_H__
00021 #define __CS_UTIL_CFGDOC_H__
00022 
00027 #include "csextern.h"
00028 #include "iutil/cfgfile.h"
00029 #include "iutil/document.h"
00030 #include "csutil/hash.h"
00031 #include "csutil/hashhandlers.h"
00032 
00038 class CS_CSUTIL_EXPORT csConfigDocument : public iConfigFile
00039 {
00040   char* filename;
00041   csRef<iDocument> document;
00042   csRef<iVFS> fileVFS;
00043 
00044   struct CS_CSUTIL_EXPORT KeyInfo
00045   {
00046     csRef<iDocumentNode> comment;
00047     csRef<iDocumentNode> node;
00048     char* cachedStringValue;
00049     char* cachedComment;
00050 
00051     KeyInfo () : cachedStringValue(0), cachedComment(0) {}
00052     KeyInfo (const KeyInfo& other)
00053     {
00054       cachedStringValue = csStrNew (other.cachedStringValue);
00055       cachedComment = csStrNew (other.cachedComment);
00056     }
00057     ~KeyInfo()
00058     {
00059       delete[] cachedStringValue;
00060       delete[] cachedComment;
00061     }
00062   };
00063   csHash<KeyInfo, csStrKey, csConstCharHashKeyHandler> keys;
00064 
00065   void ParseDocument (iDocument* doc, bool Merge = false,
00066     bool NewWins = true);
00067   void ParseNode (const char* parent, iDocumentNode* node, 
00068     bool NewWins = true);
00069 public:
00070   SCF_DECLARE_IBASE;
00071   
00072   csConfigDocument ();
00073   csConfigDocument (const char *Filename, iVFS* = 0);
00074   csConfigDocument (iDocument* doc);
00075   csConfigDocument (iDocumentNode* node);
00076   virtual ~csConfigDocument();
00077   
00078   virtual const char* GetFileName () const;
00079 
00080   virtual iVFS* GetVFS () const;
00081 
00082   virtual void SetFileName (const char*, iVFS*);
00083 
00084   virtual bool Load (const char* iFileName, iVFS* = 0, bool Merge = false,
00085     bool NewWins = true);
00086   bool LoadNode (iDocumentNode* node, bool Merge = false, bool NewWins = true);
00087 
00088   virtual bool Save ();
00089 
00090   virtual bool Save (const char *iFileName, iVFS* = 0);
00091 
00092   virtual void Clear ();
00093 
00094   virtual csPtr<iConfigIterator> Enumerate (const char *Subsection = 0);
00095 
00096   virtual bool KeyExists (const char *Key) const;
00097   virtual bool SubsectionExists (const char *Subsection) const;
00098 
00099   virtual int GetInt (const char *Key, int Def = 0) const;
00100   virtual float GetFloat (const char *Key, float Def = 0.0) const;
00101   virtual const char *GetStr (const char *Key, const char *Def = "") const;
00102   virtual bool GetBool (const char *Key, bool Def = false) const;
00103   virtual const char *GetComment (const char *Key) const;
00104 
00105   virtual void SetStr (const char *Key, const char *Val);
00106   virtual void SetInt (const char *Key, int Value);
00107   virtual void SetFloat (const char *Key, float Value);
00108   virtual void SetBool (const char *Key, bool Value);
00109   virtual bool SetComment (const char *Key, const char *Text);
00110   virtual void DeleteKey (const char *Key);
00111   virtual const char *GetEOFComment () const;
00112   virtual void SetEOFComment (const char *Text);
00113 };
00114 
00115 #endif // __CS_UTIL_CFGDOC_H__

Generated for Crystal Space by doxygen 1.2.18