CrystalSpace

Public API Reference

iutil/document.h

Go to the documentation of this file.
00001 /*
00002     Crystal Space Document Interface
00003     Copyright (C) 2002 by Jorrit Tyberghein
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_IUTIL_DOCUMENT_H__
00021 #define __CS_IUTIL_DOCUMENT_H__
00022 
00028 #include "csutil/scf.h"
00029 
00030 struct iDocumentNode;
00031 struct iDocumentAttribute;
00032 struct iFile;
00033 struct iDataBuffer;
00034 struct iString;
00035 struct iVFS;
00036 
00040 enum csDocumentNodeType
00041 {
00043   CS_NODE_DOCUMENT = 1,
00045   CS_NODE_ELEMENT,
00047   CS_NODE_COMMENT,
00049   CS_NODE_UNKNOWN,
00051   CS_NODE_TEXT,
00053   CS_NODE_DECLARATION
00054 };
00055 
00059 
00060 #define CS_CHANGEABLE_NEVER             0
00062 #define CS_CHANGEABLE_NEWROOT           1
00064 #define CS_CHANGEABLE_YES               2
00065 
00067 //===========================================================================
00068 
00075 struct iDocumentAttributeIterator : public virtual iBase
00076 {
00077   SCF_INTERFACE(iDocumentAttributeIterator, 2,0,0);
00079   virtual bool HasNext () = 0;
00081   virtual csRef<iDocumentAttribute> Next () = 0;
00082 };
00083 
00084 //===========================================================================
00085 
00086 
00099 struct iDocumentAttribute : public virtual iBase
00100 {
00101   SCF_INTERFACE(iDocumentAttribute, 2,0,0);
00103   virtual const char* GetName () = 0;
00105   virtual const char* GetValue () = 0;
00107   virtual int GetValueAsInt () = 0;
00109   virtual float GetValueAsFloat () = 0;
00111   virtual bool GetValueAsBool () = 0;
00113   virtual void SetName (const char* name) = 0;
00115   virtual void SetValue (const char* value) = 0;
00117   virtual void SetValueAsInt (int v) = 0;
00119   virtual void SetValueAsFloat (float f) = 0;
00120 };
00121 
00122 //===========================================================================
00123 
00130 struct iDocumentNodeIterator : public virtual iBase
00131 {
00132   SCF_INTERFACE(iDocumentNodeIterator, 2,0,0);
00134   virtual bool HasNext () = 0;
00136   virtual csRef<iDocumentNode> Next () = 0;
00137 };
00138 
00139 //===========================================================================
00140 
00141 
00155 struct iDocumentNode : public virtual iBase
00156 {
00157   SCF_INTERFACE(iDocumentNode, 2,0,0);
00161   virtual csDocumentNodeType GetType () = 0;
00162 
00171   virtual bool Equals (iDocumentNode* other) = 0;
00172 
00183   virtual const char* GetValue () = 0;
00194   virtual void SetValue (const char* value) = 0;
00196   virtual void SetValueAsInt (int value) = 0;
00198   virtual void SetValueAsFloat (float value) = 0;
00199 
00201   virtual csRef<iDocumentNode> GetParent () = 0;
00202 
00203   //---------------------------------------------------------------------
00204   
00209   virtual csRef<iDocumentNodeIterator> GetNodes () = 0;
00214   virtual csRef<iDocumentNodeIterator> GetNodes (const char* value) = 0;
00216   virtual csRef<iDocumentNode> GetNode (const char* value) = 0;
00217 
00219   virtual void RemoveNode (const csRef<iDocumentNode>& child) = 0;
00221   virtual void RemoveNodes (csRef<iDocumentNodeIterator> children) = 0;
00223   virtual void RemoveNodes () = 0;
00224 
00231   virtual csRef<iDocumentNode> CreateNodeBefore (csDocumentNodeType type,
00232         iDocumentNode* before = 0) = 0;
00233 
00240   virtual const char* GetContentsValue () = 0;
00246   virtual int GetContentsValueAsInt () = 0;
00252   virtual float GetContentsValueAsFloat () = 0;
00253 
00254   //---------------------------------------------------------------------
00255 
00260   virtual csRef<iDocumentAttributeIterator> GetAttributes () = 0;
00262   virtual csRef<iDocumentAttribute> GetAttribute (const char* name) = 0;
00264   virtual const char* GetAttributeValue (const char* name) = 0;
00266   virtual int GetAttributeValueAsInt (const char* name) = 0;
00268   virtual float GetAttributeValueAsFloat (const char* name) = 0;
00273   virtual bool GetAttributeValueAsBool (const char* name,
00274         bool defaultvalue=false) = 0;
00275 
00277   virtual void RemoveAttribute (const csRef<iDocumentAttribute>& attr) = 0;
00279   virtual void RemoveAttributes () = 0;
00280 
00282   virtual void SetAttribute (const char* name, const char* value) = 0;
00284   virtual void SetAttributeAsInt (const char* name, int value) = 0;
00286   virtual void SetAttributeAsFloat (const char* name, float value) = 0;
00287 };
00288 
00289 //===========================================================================
00290 
00291 
00298 struct iDocument : public virtual iBase
00299 {
00300   SCF_INTERFACE(iDocument, 2,0,0);
00302   virtual void Clear () = 0;
00303 
00305   virtual csRef<iDocumentNode> CreateRoot () = 0;
00306 
00311   virtual csRef<iDocumentNode> GetRoot () = 0;
00312 
00324   virtual const char* Parse (iFile* file, bool collapse = false) = 0;
00325 
00337   virtual const char* Parse (iDataBuffer* buf, bool collapse = false) = 0;
00338 
00350   virtual const char* Parse (iString* str, bool collapse = false) = 0;
00351 
00363   virtual const char* Parse (const char* buf, bool collapse = false) = 0;
00364 
00370   virtual const char* Write (iFile* file) = 0;
00371 
00377   virtual const char* Write (iString* str) = 0;
00378 
00384   virtual const char* Write (iVFS* vfs, const char* filename) = 0;
00385   
00393   virtual int Changeable () = 0;
00394 };
00395 
00396 //===========================================================================
00397 
00398 
00412 struct iDocumentSystem : public virtual iBase
00413 {
00414   SCF_INTERFACE(iDocumentSystem, 2,0,0);
00416   virtual csRef<iDocument> CreateDocument () = 0;
00417 };
00418 
00421 #endif // __CS_IUTIL_DOCUMENT_H__

Generated for Crystal Space by doxygen 1.4.7