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

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 =========================================================================*/
00038 #ifndef __vtkXMLDataElement_h
00039 #define __vtkXMLDataElement_h
00040 
00041 #include "vtkObject.h"
00042 
00043 class vtkXMLDataParser;
00044 
00045 class VTK_IO_EXPORT vtkXMLDataElement : public vtkObject
00046 {
00047 public:
00048   vtkTypeRevisionMacro(vtkXMLDataElement,vtkObject);
00049   void PrintSelf(ostream& os, vtkIndent indent);
00050   static vtkXMLDataElement* New();
00051   
00053 
00054   vtkGetStringMacro(Name);
00055   vtkSetStringMacro(Name);
00057   
00059 
00060   vtkGetStringMacro(Id);
00061   vtkSetStringMacro(Id);
00063   
00066   const char* GetAttribute(const char* name);
00067 
00070   void SetAttribute(const char* name, const char* value);
00071   
00073 
00075   int GetScalarAttribute(const char* name, int& value);
00076   int GetScalarAttribute(const char* name, float& value);
00077   int GetScalarAttribute(const char* name, double& value);
00078   int GetScalarAttribute(const char* name, unsigned long& value);
00080 
00082 
00086   void SetIntAttribute(const char* name, int value);
00087   void SetFloatAttribute(const char* name, float value);
00088   void SetDoubleAttribute(const char* name, double value);
00089   void SetUnsignedLongAttribute(const char* name, unsigned long value);
00091   
00093 
00095   int GetVectorAttribute(const char* name, int length, int* value);
00096   int GetVectorAttribute(const char* name, int length, float* value);
00097   int GetVectorAttribute(const char* name, int length, double* value);
00098   int GetVectorAttribute(const char* name, int length, unsigned long* value);
00100   
00102 
00103   void SetVectorAttribute(const char* name, int length, const int* value);
00104   void SetVectorAttribute(const char* name, int length, const float* value);
00105   void SetVectorAttribute(const char* name, int length, const double* value);
00106   void SetVectorAttribute(const char* name, int length, const unsigned long* value);
00108 
00109 #ifdef VTK_ID_TYPE_IS_NOT_BASIC_TYPE
00110   //BTX
00111   int  GetScalarAttribute(const char* name, vtkIdType& value);
00112   void SetIdTypeAttribute(const char* name, vtkIdType value);
00113   int  GetVectorAttribute(const char* name, int length, vtkIdType* value);
00114   void SetVectorAttribute(const char* name, int length, const vtkIdType* value);
00115   //ETX
00116 #endif
00117   
00120   int GetWordTypeAttribute(const char* name, int& value);
00121   
00123 
00124   vtkGetMacro(NumberOfAttributes, int);
00126 
00128   const char* GetAttributeName(int idx);
00129 
00132   const char* GetAttributeValue(int idx);
00133 
00135   virtual void RemoveAllAttributes();
00136 
00138 
00139   vtkXMLDataElement* GetParent();
00140   void SetParent(vtkXMLDataElement* parent);
00142   
00144   virtual vtkXMLDataElement* GetRoot();
00145   
00147   int GetNumberOfNestedElements();
00148   
00150   vtkXMLDataElement* GetNestedElement(int index);
00151   
00153   void AddNestedElement(vtkXMLDataElement* element);
00154 
00156   virtual void RemoveNestedElement(vtkXMLDataElement *);
00157   
00159   virtual void RemoveAllNestedElements();
00160 
00162 
00164   vtkXMLDataElement* FindNestedElement(const char* id);
00165   vtkXMLDataElement* FindNestedElementWithName(const char* name);
00166   vtkXMLDataElement* FindNestedElementWithNameAndId(
00167     const char* name, const char* id);
00168   vtkXMLDataElement* FindNestedElementWithNameAndAttribute(
00169     const char* name, const char* att_name, const char* att_value);
00171   
00173   vtkXMLDataElement* LookupElement(const char* id);
00174   
00176 
00178   vtkGetMacro(XMLByteIndex, unsigned long);
00179   vtkSetMacro(XMLByteIndex, unsigned long);
00181   
00186   virtual int IsEqualTo(vtkXMLDataElement *elem);
00187 
00191   virtual void DeepCopy(vtkXMLDataElement *elem);
00192 
00194 
00199   vtkSetClampMacro(AttributeEncoding,int,VTK_ENCODING_NONE,VTK_ENCODING_UNKNOWN);
00200   vtkGetMacro(AttributeEncoding, int);
00202   
00203 protected:
00204   vtkXMLDataElement();
00205   ~vtkXMLDataElement();  
00206   
00207   // The name of the element from the XML file.
00208   char* Name;
00209   
00210   // The value of the "id" attribute, if any was given.
00211   char* Id;
00212   
00213   // The offset into the XML stream where the element begins.
00214   unsigned long XMLByteIndex;
00215   
00216   // The offset into the XML stream where the inline data begins.
00217   unsigned long InlineDataPosition;
00218   
00219   // The raw property name/value pairs read from the XML attributes.
00220   char** AttributeNames;
00221   char** AttributeValues;
00222   int NumberOfAttributes;
00223   int AttributesSize;
00224   int AttributeEncoding;
00225 
00226   // The set of nested elements.
00227   int NumberOfNestedElements;
00228   int NestedElementsSize;
00229   vtkXMLDataElement** NestedElements;
00230   
00231   // The parent of this element.
00232   vtkXMLDataElement* Parent;
00233   
00234   // Method used by vtkXMLFileParser to setup the element.
00235   void ReadXMLAttributes(const char** atts, int encoding);  
00236   void SeekInlineDataPosition(vtkXMLDataParser* parser);
00237   
00238   void PrintXML(ostream& os, vtkIndent indent);
00239   
00240   // Internal utility methods.
00241   vtkXMLDataElement* LookupElementInScope(const char* id);
00242   vtkXMLDataElement* LookupElementUpScope(const char* id);
00243   static int IsSpace(char c);
00244   
00245   //BTX
00246   friend class vtkXMLDataParser;
00247   //ETX
00248 
00249 private:
00250   vtkXMLDataElement(const vtkXMLDataElement&);  // Not implemented.
00251   void operator=(const vtkXMLDataElement&);  // Not implemented.
00252 };
00253 
00254 #endif