Crystal Space: csutil/cfgdoc.h Source File (Crystal Space Public API Reference)

| ## Public API Reference

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

- File List
- File Members

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