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 "vtkCommonDataModelModule.h" // For export macro
31 #include "vtkObject.h"
32 
33 class vtkXMLDataParser;
34 
36 {
37 public:
39  void PrintSelf(ostream& os, vtkIndent indent);
40  static vtkXMLDataElement* New();
41 
43 
44  vtkGetStringMacro(Name);
45  virtual void SetName (const char* _arg);
47 
49 
50  vtkGetStringMacro(Id);
51  vtkSetStringMacro(Id);
53 
56  const char* GetAttribute(const char* name);
57 
60  void SetAttribute(const char* name, const char* value);
61 
63 
64  void SetCharacterData(const char* c, int length);
65  void AddCharacterData(const char* c, size_t length);
66  vtkGetStringMacro(CharacterData);
68 
70 
72  int GetScalarAttribute(const char* name, int& value);
73  int GetScalarAttribute(const char* name, float& value);
74  int GetScalarAttribute(const char* name, double& value);
75  int GetScalarAttribute(const char* name, unsigned long& value);
77 
79 
83  void SetIntAttribute(const char* name, int value);
84  void SetFloatAttribute(const char* name, float value);
85  void SetDoubleAttribute(const char* name, double value);
86  void SetUnsignedLongAttribute(const char* name, unsigned long value);
88 
90 
92  int GetVectorAttribute(const char* name, int length, int* value);
93  int GetVectorAttribute(const char* name, int length, float* value);
94  int GetVectorAttribute(const char* name, int length, double* value);
95  int GetVectorAttribute(const char* name, int length, unsigned long* value);
97 
99 
100  void SetVectorAttribute(const char* name, int length, const int* value);
101  void SetVectorAttribute(const char* name, int length, const float* value);
102  void SetVectorAttribute(const char* name, int length, const double* value);
103  void SetVectorAttribute(const char* name, int length, const unsigned long* value);
105 
106  //BTX
107 #ifdef VTK_TYPE_USE_LONG_LONG
108  int GetScalarAttribute(const char* name, long long& value);
109  int GetVectorAttribute(const char* name, int length, long long* value);
110  void SetVectorAttribute(const char* name, int length, long long const* value);
111  int GetScalarAttribute(const char* name, unsigned long long& value);
112  int GetVectorAttribute(const char* name, int length, unsigned long long* value);
113  void SetVectorAttribute(const char* name, int length, unsigned long long const* value);
114 #endif
115 #ifdef VTK_TYPE_USE___INT64
116  int GetScalarAttribute(const char* name, __int64& value);
117  int GetVectorAttribute(const char* name, int length, __int64* value);
118  void SetVectorAttribute(const char* name, int length, __int64 const* value);
119  int GetScalarAttribute(const char* name, unsigned __int64& value);
120  int GetVectorAttribute(const char* name, int length, unsigned __int64* value);
121  void SetVectorAttribute(const char* name, int length, unsigned __int64 const* value);
122 #endif
123  //ETX
124 
127  int GetWordTypeAttribute(const char* name, int& value);
128 
130 
131  vtkGetMacro(NumberOfAttributes, int);
133 
135  const char* GetAttributeName(int idx);
136 
139  const char* GetAttributeValue(int idx);
140 
142 
143  virtual void RemoveAttribute(const char *name);
144  virtual void RemoveAllAttributes();
146 
148 
149  vtkXMLDataElement* GetParent();
150  void SetParent(vtkXMLDataElement* parent);
152 
154  virtual vtkXMLDataElement* GetRoot();
155 
157  int GetNumberOfNestedElements();
158 
160  vtkXMLDataElement* GetNestedElement(int index);
161 
163  void AddNestedElement(vtkXMLDataElement* element);
164 
166  virtual void RemoveNestedElement(vtkXMLDataElement *);
167 
169  virtual void RemoveAllNestedElements();
170 
172 
175  vtkXMLDataElement* FindNestedElement(const char* id);
176  vtkXMLDataElement* FindNestedElementWithName(const char* name);
177  vtkXMLDataElement* FindNestedElementWithNameAndId(
178  const char* name, const char* id);
179  vtkXMLDataElement* FindNestedElementWithNameAndAttribute(
180  const char* name, const char* att_name, const char* att_value);
182 
185  vtkXMLDataElement* LookupElementWithName(const char* name);
186 
188  vtkXMLDataElement* LookupElement(const char* id);
189 
191 
193  vtkGetMacro(XMLByteIndex, vtkTypeInt64);
194  vtkSetMacro(XMLByteIndex, vtkTypeInt64);
196 
201  virtual int IsEqualTo(vtkXMLDataElement *elem);
202 
206  virtual void DeepCopy(vtkXMLDataElement *elem);
207 
209 
214  vtkSetClampMacro(AttributeEncoding,int,VTK_ENCODING_NONE,VTK_ENCODING_UNKNOWN);
215  vtkGetMacro(AttributeEncoding, int);
217 
219 
220  void PrintXML(ostream& os, vtkIndent indent);
221  void PrintXML(const char* fname);
223 
225 
230  vtkGetMacro(CharacterDataWidth,int);
231  vtkSetMacro(CharacterDataWidth,int);
233 
234 protected:
237 
238  // The name of the element from the XML file.
239  char* Name;
240  // The value of the "id" attribute, if any was given.
241  char* Id;
242 
244 
245  // Data inside of the tag's open and close. ie <X> character data </X>
246  char* CharacterData; // Null terminated buffer.
247  size_t CharacterDataBlockSize; // Allocation size if buffer needs expand
248  size_t CharacterDataBufferSize; // Allocated size.
249  size_t EndOfCharacterData; // Number of bytes used.
250 
251  // Tags that have specialized character data handlers
252  // can set this flag to improve performance. The default is unset.
254 
255  // Get/Set the stream position of the elements inline data.
256  vtkGetMacro(InlineDataPosition,vtkTypeInt64);
257  vtkSetMacro(InlineDataPosition,vtkTypeInt64);
258  // The offset into the XML stream where the inline data begins.
259  vtkTypeInt64 InlineDataPosition;
260  // The offset into the XML stream where the element begins.
261  vtkTypeInt64 XMLByteIndex;
262 
263  // The raw property name/value pairs read from the XML attributes.
269 
270  // The set of nested elements.
274  // The parent of this element.
276 
277  // Internal utility methods.
278  vtkXMLDataElement* LookupElementInScope(const char* id);
279  vtkXMLDataElement* LookupElementUpScope(const char* id);
280  static int IsSpace(char c);
281  void PrintCharacterData(ostream &os,vtkIndent indent);
282  static void PrintWithEscapedData(ostream& os, const char* data);
283 
284  //BTX
285  friend class vtkXMLDataParser;
286  friend class vtkXMLMaterialParser;
287  //ETX
288 
289 private:
290  vtkXMLDataElement(const vtkXMLDataElement&); // Not implemented.
291  void operator=(const vtkXMLDataElement&); // Not implemented.
292 };
293 
294 //----------------------------------------------------------------------------
295 inline
297 {
298  if (this->IgnoreCharacterData){ return; }
299  // This is the index where we start to put the new data at.
300  size_t eod=this->EndOfCharacterData-1;
301  // Check if the new data will write off the end. If it does
302  // resize the character data buffer.
303  this->EndOfCharacterData+=length;
305  {
306  while(this->EndOfCharacterData>=this->CharacterDataBufferSize)
307  {
309  }
310  this->CharacterData
311  = static_cast<char *>(realloc(this->CharacterData,this->CharacterDataBufferSize));
312  }
313  // put the new data at the end of the buffer, and null terminate.
314  char *pCD=this->CharacterData+eod;
315  memmove(pCD,data,length);
316  pCD[length]='\0';
317  return;
318 }
319 
320 #endif
vtkXMLDataElement ** NestedElements
abstract base class for most VTK objects
Definition: vtkObject.h:61
Represents an XML element and those nested inside.
void DeepCopy(vtkPistonReference *self, vtkPistonReference *other)
#define VTK_ENCODING_UNKNOWN
vtkTypeInt64 XMLByteIndex
void AddCharacterData(const char *c, size_t length)
vtkXMLDataElement * Parent
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
#define VTK_ENCODING_NONE
Used by vtkXMLReader to parse VTK XML files.
static vtkObject * New()
vtkTypeInt64 InlineDataPosition
#define VTKCOMMONDATAMODEL_EXPORT