Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | 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   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00031 #ifndef __vtkXMLDataElement_h
00032 #define __vtkXMLDataElement_h
00033 
00034 #include "vtkObject.h"
00035 
00036 class vtkXMLDataParser;
00037 
00038 class VTK_IO_EXPORT vtkXMLDataElement : public vtkObject
00039 {
00040 public:
00041   vtkTypeRevisionMacro(vtkXMLDataElement,vtkObject);
00042   void PrintSelf(ostream& os, vtkIndent indent);
00043   static vtkXMLDataElement* New();
00044   
00046 
00047   vtkGetStringMacro(Name);
00048   vtkSetStringMacro(Name);
00050   
00052 
00053   vtkGetStringMacro(Id);
00054   vtkSetStringMacro(Id);
00056   
00059   const char* GetAttribute(const char* name);
00060 
00063   void SetAttribute(const char* name, const char* value);
00064   
00066 
00068   int GetScalarAttribute(const char* name, int& value);
00069   int GetScalarAttribute(const char* name, float& value);
00070   int GetScalarAttribute(const char* name, double& value);
00071   int GetScalarAttribute(const char* name, unsigned long& value);
00073 
00075 
00079   void SetIntAttribute(const char* name, int value);
00080   void SetFloatAttribute(const char* name, float value);
00081   void SetDoubleAttribute(const char* name, double value);
00082   void SetUnsignedLongAttribute(const char* name, unsigned long value);
00084   
00086 
00088   int GetVectorAttribute(const char* name, int length, int* value);
00089   int GetVectorAttribute(const char* name, int length, float* value);
00090   int GetVectorAttribute(const char* name, int length, double* value);
00091   int GetVectorAttribute(const char* name, int length, unsigned long* value);
00093   
00095 
00096   void SetVectorAttribute(const char* name, int length, const int* value);
00097   void SetVectorAttribute(const char* name, int length, const float* value);
00098   void SetVectorAttribute(const char* name, int length, const double* value);
00099   void SetVectorAttribute(const char* name, int length, const unsigned long* value);
00101 
00102 #ifdef VTK_ID_TYPE_IS_NOT_BASIC_TYPE
00103   //BTX
00104   int  GetScalarAttribute(const char* name, vtkIdType& value);
00105   void SetIdTypeAttribute(const char* name, vtkIdType value);
00106   int  GetVectorAttribute(const char* name, int length, vtkIdType* value);
00107   void SetVectorAttribute(const char* name, int length, const vtkIdType* value);
00108   //ETX
00109 #endif
00110   
00113   int GetWordTypeAttribute(const char* name, int& value);
00114   
00116 
00117   vtkGetMacro(NumberOfAttributes, int);
00119 
00121   const char* GetAttributeName(int idx);
00122 
00124 
00125   vtkXMLDataElement* GetParent();
00126   void SetParent(vtkXMLDataElement* parent);
00128   
00130   int GetNumberOfNestedElements();
00131   
00133   vtkXMLDataElement* GetNestedElement(int index);
00134   
00136   void AddNestedElement(vtkXMLDataElement* element);
00137 
00139 
00141   vtkXMLDataElement* FindNestedElement(const char* id);
00142   vtkXMLDataElement* FindNestedElementWithName(const char* name);
00143   vtkXMLDataElement* FindNestedElementWithNameAndId(
00144     const char* name, const char* id);
00145   vtkXMLDataElement* FindNestedElementWithNameAndAttribute(
00146     const char* name, const char* att_name, const char* att_value);
00148   
00150   vtkXMLDataElement* LookupElement(const char* id);
00151   
00153 
00155   vtkGetMacro(XMLByteIndex, unsigned long);
00156   vtkSetMacro(XMLByteIndex, unsigned long);
00158   
00159 protected:
00160   vtkXMLDataElement();
00161   ~vtkXMLDataElement();  
00162   
00163   // The name of the element from the XML file.
00164   char* Name;
00165   
00166   // The value of the "id" attribute, if any was given.
00167   char* Id;
00168   
00169   // The offset into the XML stream where the element begins.
00170   unsigned long XMLByteIndex;
00171   
00172   // The offset into the XML stream where the inline data begins.
00173   unsigned long InlineDataPosition;
00174   
00175   // The raw property name/value pairs read from the XML attributes.
00176   char** AttributeNames;
00177   char** AttributeValues;
00178   int NumberOfAttributes;
00179   int AttributesSize;
00180   
00181   // The set of nested elements.
00182   int NumberOfNestedElements;
00183   int NestedElementsSize;
00184   vtkXMLDataElement** NestedElements;
00185   
00186   // The parent of this element.
00187   vtkXMLDataElement* Parent;
00188   
00189   // Method used by vtkXMLFileParser to setup the element.
00190   void ReadXMLAttributes(const char** atts);  
00191   void SeekInlineDataPosition(vtkXMLDataParser* parser);
00192   
00193   void PrintXML(ostream& os, vtkIndent indent);
00194   
00195   // Internal utility methods.
00196   vtkXMLDataElement* LookupElementInScope(const char* id);
00197   vtkXMLDataElement* LookupElementUpScope(const char* id);
00198   static int IsSpace(char c);
00199   
00200   //BTX
00201   friend class vtkXMLDataParser;
00202   //ETX
00203   
00204 private:
00205   vtkXMLDataElement(const vtkXMLDataElement&);  // Not implemented.
00206   void operator=(const vtkXMLDataElement&);  // Not implemented.
00207 };
00208 
00209 #endif