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  int GetScalarAttribute(const char* name, long long& value);
108  int GetVectorAttribute(const char* name, int length, long long* value);
109  void SetVectorAttribute(const char* name, int length, long long const* value);
110  int GetScalarAttribute(const char* name, unsigned long long& value);
111  int GetVectorAttribute(const char* name, int length, unsigned long long* value);
112  void SetVectorAttribute(const char* name, int length, unsigned long long const* value);
113  //ETX
114 
117  int GetWordTypeAttribute(const char* name, int& value);
118 
120 
121  vtkGetMacro(NumberOfAttributes, int);
123 
125  const char* GetAttributeName(int idx);
126 
129  const char* GetAttributeValue(int idx);
130 
132 
133  virtual void RemoveAttribute(const char *name);
134  virtual void RemoveAllAttributes();
136 
138 
139  vtkXMLDataElement* GetParent();
140  void SetParent(vtkXMLDataElement* parent);
142 
144  virtual vtkXMLDataElement* GetRoot();
145 
147  int GetNumberOfNestedElements();
148 
150  vtkXMLDataElement* GetNestedElement(int index);
151 
153  void AddNestedElement(vtkXMLDataElement* element);
154 
156  virtual void RemoveNestedElement(vtkXMLDataElement *);
157 
159  virtual void RemoveAllNestedElements();
160 
162 
165  vtkXMLDataElement* FindNestedElement(const char* id);
166  vtkXMLDataElement* FindNestedElementWithName(const char* name);
167  vtkXMLDataElement* FindNestedElementWithNameAndId(
168  const char* name, const char* id);
169  vtkXMLDataElement* FindNestedElementWithNameAndAttribute(
170  const char* name, const char* att_name, const char* att_value);
172 
175  vtkXMLDataElement* LookupElementWithName(const char* name);
176 
178  vtkXMLDataElement* LookupElement(const char* id);
179 
181 
183  vtkGetMacro(XMLByteIndex, vtkTypeInt64);
184  vtkSetMacro(XMLByteIndex, vtkTypeInt64);
186 
191  virtual int IsEqualTo(vtkXMLDataElement *elem);
192 
196  virtual void DeepCopy(vtkXMLDataElement *elem);
197 
199 
204  vtkSetClampMacro(AttributeEncoding,int,VTK_ENCODING_NONE,VTK_ENCODING_UNKNOWN);
205  vtkGetMacro(AttributeEncoding, int);
207 
209 
210  void PrintXML(ostream& os, vtkIndent indent);
211  void PrintXML(const char* fname);
213 
215 
220  vtkGetMacro(CharacterDataWidth,int);
221  vtkSetMacro(CharacterDataWidth,int);
223 
224 protected:
227 
228  // The name of the element from the XML file.
229  char* Name;
230  // The value of the "id" attribute, if any was given.
231  char* Id;
232 
234 
235  // Data inside of the tag's open and close. ie <X> character data </X>
236  char* CharacterData; // Null terminated buffer.
237  size_t CharacterDataBlockSize; // Allocation size if buffer needs expand
238  size_t CharacterDataBufferSize; // Allocated size.
239  size_t EndOfCharacterData; // Number of bytes used.
240 
241  // Tags that have specialized character data handlers
242  // can set this flag to improve performance. The default is unset.
244 
245  // Get/Set the stream position of the elements inline data.
246  vtkGetMacro(InlineDataPosition,vtkTypeInt64);
247  vtkSetMacro(InlineDataPosition,vtkTypeInt64);
248  // The offset into the XML stream where the inline data begins.
249  vtkTypeInt64 InlineDataPosition;
250  // The offset into the XML stream where the element begins.
251  vtkTypeInt64 XMLByteIndex;
252 
253  // The raw property name/value pairs read from the XML attributes.
259 
260  // The set of nested elements.
264  // The parent of this element.
266 
267  // Internal utility methods.
268  vtkXMLDataElement* LookupElementInScope(const char* id);
269  vtkXMLDataElement* LookupElementUpScope(const char* id);
270  static int IsSpace(char c);
271  void PrintCharacterData(ostream &os,vtkIndent indent);
272  static void PrintWithEscapedData(ostream& os, const char* data);
273 
274  //BTX
275  friend class vtkXMLDataParser;
276  friend class vtkXMLMaterialParser;
277  //ETX
278 
279 private:
280  vtkXMLDataElement(const vtkXMLDataElement&); // Not implemented.
281  void operator=(const vtkXMLDataElement&); // Not implemented.
282 };
283 
284 //----------------------------------------------------------------------------
285 inline
287 {
288  if (this->IgnoreCharacterData){ return; }
289  // This is the index where we start to put the new data at.
290  size_t eod=this->EndOfCharacterData-1;
291  // Check if the new data will write off the end. If it does
292  // resize the character data buffer.
293  this->EndOfCharacterData+=length;
295  {
296  while(this->EndOfCharacterData>=this->CharacterDataBufferSize)
297  {
299  }
300  this->CharacterData
301  = static_cast<char *>(realloc(this->CharacterData,this->CharacterDataBufferSize));
302  }
303  // put the new data at the end of the buffer, and null terminate.
304  char *pCD=this->CharacterData+eod;
305  memmove(pCD,data,length);
306  pCD[length]='\0';
307  return;
308 }
309 
310 #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