Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 = CS::StrDup (other.cachedStringValue);
00061 cachedComment = CS::StrDup (other.cachedComment);
00062 originalKey = CS::StrDup (other.originalKey);
00063 }
00064 ~KeyInfo()
00065 {
00066 cs_free (cachedStringValue);
00067 cs_free (cachedComment);
00068 cs_free (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 csPtr<iStringArray> GetTuple(const char *Key) const;
00111 virtual const char *GetComment (const char *Key) const;
00112
00113 virtual void SetStr (const char *Key, const char *Val);
00114 virtual void SetInt (const char *Key, int Value);
00115 virtual void SetFloat (const char *Key, float Value);
00116 virtual void SetBool (const char *Key, bool Value);
00117 virtual void SetTuple (const char *Key, iStringArray* Value);
00118 virtual bool SetComment (const char *Key, const char *Text);
00119 virtual void DeleteKey (const char *Key);
00120 virtual const char *GetEOFComment () const;
00121 virtual void SetEOFComment (const char *Text);
00122 };
00123
00124 #endif // __CS_UTIL_CFGDOC_H__