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