VTK
vtkXMLDataElement.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkXMLDataElement.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
27 #ifndef __vtkXMLDataElement_h
28 #define __vtkXMLDataElement_h
29 
30 #include "vtkObject.h"
31 
32 class vtkXMLDataParser;
33 
35 {
36 public:
38  void PrintSelf(ostream& os, vtkIndent indent);
39  static vtkXMLDataElement* New();
40 
42 
43  vtkGetStringMacro(Name);
44  virtual void SetName (const char* _arg);
46 
48 
49  vtkGetStringMacro(Id);
50  vtkSetStringMacro(Id);
52 
55  const char* GetAttribute(const char* name);
56 
59  void SetAttribute(const char* name, const char* value);
60 
62 
63  void SetCharacterData(const char* c, int length);
64  void AddCharacterData(const char* c, size_t length);
65  vtkGetStringMacro(CharacterData);
67 
69 
71  int GetScalarAttribute(const char* name, int& value);
72  int GetScalarAttribute(const char* name, float& value);
73  int GetScalarAttribute(const char* name, double& value);
74  int GetScalarAttribute(const char* name, unsigned long& value);
76 
78 
82  void SetIntAttribute(const char* name, int value);
83  void SetFloatAttribute(const char* name, float value);
84  void SetDoubleAttribute(const char* name, double value);
85  void SetUnsignedLongAttribute(const char* name, unsigned long value);
87 
89 
91  int GetVectorAttribute(const char* name, int length, int* value);
92  int GetVectorAttribute(const char* name, int length, float* value);
93  int GetVectorAttribute(const char* name, int length, double* value);
94  int GetVectorAttribute(const char* name, int length, unsigned long* value);
96 
98 
99  void SetVectorAttribute(const char* name, int length, const int* value);
100  void SetVectorAttribute(const char* name, int length, const float* value);
101  void SetVectorAttribute(const char* name, int length, const double* value);
102  void SetVectorAttribute(const char* name, int length, const unsigned long* value);
104 
105 #ifdef VTK_USE_64BIT_IDS
106  //BTX
107  int GetScalarAttribute(const char* name, vtkIdType& value);
108  void SetIdTypeAttribute(const char* name, vtkIdType value);
109  int GetVectorAttribute(const char* name, int length, vtkIdType* value);
110  void SetVectorAttribute(const char* name, int length, const vtkIdType* value);
111  //ETX
112 #endif
113 
116  int GetWordTypeAttribute(const char* name, int& value);
117 
119 
120  vtkGetMacro(NumberOfAttributes, int);
122 
124  const char* GetAttributeName(int idx);
125 
128  const char* GetAttributeValue(int idx);
129 
131 
132  virtual void RemoveAttribute(const char *name);
133  virtual void RemoveAllAttributes();
135 
137 
138  vtkXMLDataElement* GetParent();
139  void SetParent(vtkXMLDataElement* parent);
141 
143  virtual vtkXMLDataElement* GetRoot();
144 
146  int GetNumberOfNestedElements();
147 
149  vtkXMLDataElement* GetNestedElement(int index);
150 
152  void AddNestedElement(vtkXMLDataElement* element);
153 
155  virtual void RemoveNestedElement(vtkXMLDataElement *);
156 
158  virtual void RemoveAllNestedElements();
159 
161 
164  vtkXMLDataElement* FindNestedElement(const char* id);
165  vtkXMLDataElement* FindNestedElementWithName(const char* name);
166  vtkXMLDataElement* FindNestedElementWithNameAndId(
167  const char* name, const char* id);
168  vtkXMLDataElement* FindNestedElementWithNameAndAttribute(
169  const char* name, const char* att_name, const char* att_value);
171 
174  vtkXMLDataElement* LookupElementWithName(const char* name);
175 
177  vtkXMLDataElement* LookupElement(const char* id);
178 
180 
182  vtkGetMacro(XMLByteIndex, unsigned long);
183  vtkSetMacro(XMLByteIndex, unsigned long);
185 
190  virtual int IsEqualTo(vtkXMLDataElement *elem);
191 
195  virtual void DeepCopy(vtkXMLDataElement *elem);
196 
198 
203  vtkSetClampMacro(AttributeEncoding,int,VTK_ENCODING_NONE,VTK_ENCODING_UNKNOWN);
204  vtkGetMacro(AttributeEncoding, int);
206 
208 
209  void PrintXML(ostream& os, vtkIndent indent);
210  void PrintXML(const char* fname);
212 
214 
219  vtkGetMacro(CharacterDataWidth,int);
220  vtkSetMacro(CharacterDataWidth,int);
222 
223 protected:
226 
227  // The name of the element from the XML file.
228  char* Name;
229  // The value of the "id" attribute, if any was given.
230  char* Id;
231 
233 
234  // Data inside of the tag's open and close. ie <X> character data </X>
235  char* CharacterData; // Null terminated buffer.
236  size_t CharacterDataBlockSize; // Allocation size if buffer needs expand
237  size_t CharacterDataBufferSize; // Allocated size.
238  size_t EndOfCharacterData; // Number of bytes used.
239 
240  // Tags that have specialized character data handlers
241  // can set this flag to improve performance. The default is unset.
243 
244  // Get/Set the stream position of the elements inline data.
245  vtkGetMacro(InlineDataPosition,unsigned long);
246  vtkSetMacro(InlineDataPosition,unsigned long);
247  // The offset into the XML stream where the inline data begins.
248  unsigned long InlineDataPosition;
249  // The offset into the XML stream where the element begins.
250  unsigned long XMLByteIndex;
251 
252  // The raw property name/value pairs read from the XML attributes.
258 
259  // The set of nested elements.
263  // The parent of this element.
265 
266  // Internal utility methods.
267  vtkXMLDataElement* LookupElementInScope(const char* id);
268  vtkXMLDataElement* LookupElementUpScope(const char* id);
269  static int IsSpace(char c);
270  void PrintCharacterData(ostream &os,vtkIndent indent);
271  static void PrintWithEscapedData(ostream& os, const char* data);
272 
273  //BTX
274  friend class vtkXMLDataParser;
275  friend class vtkXMLMaterialParser;
276  //ETX
277 
278 private:
279  vtkXMLDataElement(const vtkXMLDataElement&); // Not implemented.
280  void operator=(const vtkXMLDataElement&); // Not implemented.
281 };
282 
283 //----------------------------------------------------------------------------
284 inline
285 void vtkXMLDataElement::AddCharacterData(const char* data, size_t length)
286 {
287  if (this->IgnoreCharacterData){ return; }
288  // This is the index where we start to put the new data at.
289  size_t eod=this->EndOfCharacterData-1;
290  // Check if the new data will write off the end. If it does
291  // resize the character data buffer.
292  this->EndOfCharacterData+=length;
294  {
295  while(this->EndOfCharacterData>=this->CharacterDataBufferSize)
296  {
298  }
299  this->CharacterData
300  = static_cast<char *>(realloc(this->CharacterData,this->CharacterDataBufferSize));
301  }
302  // put the new data at the end of the buffer, and null terminate.
303  char *pCD=this->CharacterData+eod;
304  memmove(pCD,data,length);
305  pCD[length]='\0';
306  return;
307 }
308 
309 #endif
vtkXMLDataElement ** NestedElements
abstract base class for most VTK objects
Definition: vtkObject.h:60
Represents an XML element and those nested inside.
int vtkIdType
Definition: vtkType.h:255
#define VTK_ENCODING_UNKNOWN
void AddCharacterData(const char *c, size_t length)
unsigned long InlineDataPosition
unsigned long XMLByteIndex
vtkXMLDataElement * Parent
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:37
#define VTK_ENCODING_NONE
#define VTK_COMMON_EXPORT
static vtkObject * New()