Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

IO/vtkXMLDataElement.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkXMLDataElement.h,v $
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00027 #ifndef __vtkXMLDataElement_h
00028 #define __vtkXMLDataElement_h
00029 
00030 #include "vtkObject.h"
00031 
00032 class vtkXMLDataParser;
00033 
00034 class VTK_IO_EXPORT vtkXMLDataElement : public vtkObject
00035 {
00036 public:
00037   vtkTypeRevisionMacro(vtkXMLDataElement,vtkObject);
00038   void PrintSelf(ostream& os, vtkIndent indent);
00039   static vtkXMLDataElement* New();
00040   
00042 
00043   vtkGetStringMacro(Name);
00044   vtkSetStringMacro(Name);
00046   
00048 
00049   vtkGetStringMacro(Id);
00050   vtkSetStringMacro(Id);
00052   
00055   const char* GetAttribute(const char* name);
00056 
00059   void SetAttribute(const char* name, const char* value);
00060   
00062 
00064   int GetScalarAttribute(const char* name, int& value);
00065   int GetScalarAttribute(const char* name, float& value);
00066   int GetScalarAttribute(const char* name, double& value);
00067   int GetScalarAttribute(const char* name, unsigned long& value);
00069 
00071 
00075   void SetIntAttribute(const char* name, int value);
00076   void SetFloatAttribute(const char* name, float value);
00077   void SetDoubleAttribute(const char* name, double value);
00078   void SetUnsignedLongAttribute(const char* name, unsigned long value);
00080   
00082 
00084   int GetVectorAttribute(const char* name, int length, int* value);
00085   int GetVectorAttribute(const char* name, int length, float* value);
00086   int GetVectorAttribute(const char* name, int length, double* value);
00087   int GetVectorAttribute(const char* name, int length, unsigned long* value);
00089   
00091 
00092   void SetVectorAttribute(const char* name, int length, const int* value);
00093   void SetVectorAttribute(const char* name, int length, const float* value);
00094   void SetVectorAttribute(const char* name, int length, const double* value);
00095   void SetVectorAttribute(const char* name, int length, const unsigned long* value);
00097 
00098 #ifdef VTK_ID_TYPE_IS_NOT_BASIC_TYPE
00099   //BTX
00100   int  GetScalarAttribute(const char* name, vtkIdType& value);
00101   void SetIdTypeAttribute(const char* name, vtkIdType value);
00102   int  GetVectorAttribute(const char* name, int length, vtkIdType* value);
00103   void SetVectorAttribute(const char* name, int length, const vtkIdType* value);
00104   //ETX
00105 #endif
00106   
00109   int GetWordTypeAttribute(const char* name, int& value);
00110   
00112 
00113   vtkGetMacro(NumberOfAttributes, int);
00115 
00117   const char* GetAttributeName(int idx);
00118 
00121   const char* GetAttributeValue(int idx);
00122 
00124   virtual void RemoveAllAttributes();
00125 
00127 
00128   vtkXMLDataElement* GetParent();
00129   void SetParent(vtkXMLDataElement* parent);
00131   
00133   virtual vtkXMLDataElement* GetRoot();
00134   
00136   int GetNumberOfNestedElements();
00137   
00139   vtkXMLDataElement* GetNestedElement(int index);
00140   
00142   void AddNestedElement(vtkXMLDataElement* element);
00143 
00145   virtual void RemoveNestedElement(vtkXMLDataElement *);
00146   
00148   virtual void RemoveAllNestedElements();
00149 
00151 
00153   vtkXMLDataElement* FindNestedElement(const char* id);
00154   vtkXMLDataElement* FindNestedElementWithName(const char* name);
00155   vtkXMLDataElement* FindNestedElementWithNameAndId(
00156     const char* name, const char* id);
00157   vtkXMLDataElement* FindNestedElementWithNameAndAttribute(
00158     const char* name, const char* att_name, const char* att_value);
00160   
00162   vtkXMLDataElement* LookupElement(const char* id);
00163   
00165 
00167   vtkGetMacro(XMLByteIndex, unsigned long);
00168   vtkSetMacro(XMLByteIndex, unsigned long);
00170   
00175   virtual int IsEqualTo(vtkXMLDataElement *elem);
00176 
00180   virtual void DeepCopy(vtkXMLDataElement *elem);
00181 
00183 
00188   vtkSetClampMacro(AttributeEncoding,int,VTK_ENCODING_NONE,VTK_ENCODING_UNKNOWN);
00189   vtkGetMacro(AttributeEncoding, int);
00191   
00192 protected:
00193   vtkXMLDataElement();
00194   ~vtkXMLDataElement();  
00195   
00196   // The name of the element from the XML file.
00197   char* Name;
00198   
00199   // The value of the "id" attribute, if any was given.
00200   char* Id;
00201   
00202   // The offset into the XML stream where the element begins.
00203   unsigned long XMLByteIndex;
00204   
00205   // The offset into the XML stream where the inline data begins.
00206   unsigned long InlineDataPosition;
00207   
00208   // The raw property name/value pairs read from the XML attributes.
00209   char** AttributeNames;
00210   char** AttributeValues;
00211   int NumberOfAttributes;
00212   int AttributesSize;
00213   int AttributeEncoding;
00214 
00215   // The set of nested elements.
00216   int NumberOfNestedElements;
00217   int NestedElementsSize;
00218   vtkXMLDataElement** NestedElements;
00219   
00220   // The parent of this element.
00221   vtkXMLDataElement* Parent;
00222   
00223   // Method used by vtkXMLFileParser to setup the element.
00224   void ReadXMLAttributes(const char** atts, int encoding);  
00225   void SeekInlineDataPosition(vtkXMLDataParser* parser);
00226   
00227   void PrintXML(ostream& os, vtkIndent indent);
00228   
00229   // Internal utility methods.
00230   vtkXMLDataElement* LookupElementInScope(const char* id);
00231   vtkXMLDataElement* LookupElementUpScope(const char* id);
00232   static int IsSpace(char c);
00233   
00234   //BTX
00235   friend class vtkXMLDataParser;
00236   //ETX
00237 
00238 private:
00239   vtkXMLDataElement(const vtkXMLDataElement&);  // Not implemented.
00240   void operator=(const vtkXMLDataElement&);  // Not implemented.
00241 };
00242 
00243 #endif