CrystalSpace

Public API Reference

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 "csutil/hash.h"
00029 #include "csutil/scf_implementation.h"
00030 #include "iutil/cfgfile.h"
00031 #include "iutil/document.h"
00032 
00033 class csConfigDocumentIterator;
00034 
00039 class CS_CRYSTALSPACE_EXPORT csConfigDocument : 
00040   public scfImplementation1<csConfigDocument,iConfigFile>
00041 {
00042   friend class csConfigDocumentIterator;
00043 
00044   char* filename;
00045   csRef<iDocument> document;
00046   csRef<iVFS> fileVFS;
00047 
00048   struct CS_CRYSTALSPACE_EXPORT KeyInfo
00049   {
00050     csRef<iDocumentNode> comment;
00051     csRef<iDocumentNode> node;
00052     char* cachedStringValue;
00053     char* cachedComment;
00054     char* originalKey;
00055 
00056     KeyInfo () : cachedStringValue(0), cachedComment(0), originalKey(0) {}
00057     KeyInfo (const KeyInfo& other)
00058     {
00059       cachedStringValue = csStrNew (other.cachedStringValue);
00060       cachedComment = csStrNew (other.cachedComment);
00061       originalKey = csStrNew (other.originalKey);
00062     }
00063     ~KeyInfo()
00064     {
00065       delete[] cachedStringValue;
00066       delete[] cachedComment;
00067       delete[] originalKey;
00068     }
00069   };
00070   csHash<KeyInfo, csStrKey> keys;
00071 
00072   void ParseDocument (iDocument* doc, bool Merge = false,
00073     bool NewWins = true);
00074   void ParseNode (const char* parent, iDocumentNode* node, 
00075     bool NewWins = true);
00076 public:
00077   
00078   csConfigDocument ();
00079   csConfigDocument (const char *Filename, iVFS* = 0);
00080   csConfigDocument (iDocument* doc);
00081   csConfigDocument (iDocumentNode* node);
00082   virtual ~csConfigDocument();
00083   
00084   virtual const char* GetFileName () const;
00085 
00086   virtual iVFS* GetVFS () const;
00087 
00088   virtual void SetFileName (const char*, iVFS*);
00089 
00090   virtual bool Load (const char* iFileName, iVFS* = 0, bool Merge = false,
00091     bool NewWins = true);
00092   bool LoadNode (iDocumentNode* node, bool Merge = false, bool NewWins = true);
00093 
00094   virtual bool Save ();
00095 
00096   virtual bool Save (const char *iFileName, iVFS* = 0);
00097 
00098   virtual void Clear ();
00099 
00100   virtual csPtr<iConfigIterator> Enumerate (const char *Subsection = 0);
00101 
00102   virtual bool KeyExists (const char *Key) const;
00103   virtual bool SubsectionExists (const char *Subsection) const;
00104 
00105   virtual int GetInt (const char *Key, int Def = 0) const;
00106   virtual float GetFloat (const char *Key, float Def = 0.0) const;
00107   virtual const char *GetStr (const char *Key, const char *Def = "") const;
00108   virtual bool GetBool (const char *Key, bool Def = false) const;
00109   virtual const char *GetComment (const char *Key) const;
00110 
00111   virtual void SetStr (const char *Key, const char *Val);
00112   virtual void SetInt (const char *Key, int Value);
00113   virtual void SetFloat (const char *Key, float Value);
00114   virtual void SetBool (const char *Key, bool Value);
00115   virtual bool SetComment (const char *Key, const char *Text);
00116   virtual void DeleteKey (const char *Key);
00117   virtual const char *GetEOFComment () const;
00118   virtual void SetEOFComment (const char *Text);
00119 };
00120 
00121 #endif // __CS_UTIL_CFGDOC_H__

Generated for Crystal Space by doxygen 1.4.6