VTK  9.2.6
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 =========================================================================*/
28 #ifndef vtkXMLDataElement_h
29 #define vtkXMLDataElement_h
30 
31 #include "vtkCommonDataModelModule.h" // For export macro
32 #include "vtkObject.h"
33 
34 class vtkXMLDataParser;
35 
36 class VTKCOMMONDATAMODEL_EXPORT vtkXMLDataElement : public vtkObject
37 {
38 public:
39  vtkTypeMacro(vtkXMLDataElement, vtkObject);
40  void PrintSelf(ostream& os, vtkIndent indent) override;
41  static vtkXMLDataElement* New();
42 
44 
47  vtkGetStringMacro(Name);
48  virtual void SetName(const char* _arg);
50 
52 
55  vtkGetStringMacro(Id);
56  vtkSetStringMacro(Id);
58 
63  const char* GetAttribute(const char* name);
64 
69  void SetAttribute(const char* name, const char* value);
70 
72 
75  void SetCharacterData(const char* data, int length);
76  void AddCharacterData(const char* c, size_t length);
77  vtkGetStringMacro(CharacterData);
79 
81 
85  int GetScalarAttribute(const char* name, int& value);
86  int GetScalarAttribute(const char* name, float& value);
87  int GetScalarAttribute(const char* name, double& value);
88  int GetScalarAttribute(const char* name, long& value);
89  int GetScalarAttribute(const char* name, unsigned long& value);
91 
93 
99  void SetIntAttribute(const char* name, int value);
100  void SetFloatAttribute(const char* name, float value);
101  void SetDoubleAttribute(const char* name, double value);
102  void SetUnsignedLongAttribute(const char* name, unsigned long value);
104 
106 
110  int GetVectorAttribute(const char* name, int length, int* value);
111  int GetVectorAttribute(const char* name, int length, float* value);
112  int GetVectorAttribute(const char* name, int length, double* value);
113  int GetVectorAttribute(const char* name, int length, long* value);
114  int GetVectorAttribute(const char* name, int length, unsigned long* value);
116 
118 
121  void SetVectorAttribute(const char* name, int length, const int* value);
122  void SetVectorAttribute(const char* name, int length, const float* value);
123  void SetVectorAttribute(const char* name, int length, const double* value);
124  void SetVectorAttribute(const char* name, int length, const unsigned long* value);
126 
127  int GetScalarAttribute(const char* name, long long& value);
128  int GetVectorAttribute(const char* name, int length, long long* value);
129  void SetVectorAttribute(const char* name, int length, long long const* value);
130  int GetScalarAttribute(const char* name, unsigned long long& value);
131  int GetVectorAttribute(const char* name, int length, unsigned long long* value);
132  void SetVectorAttribute(const char* name, int length, unsigned long long const* value);
133 
140  int GetWordTypeAttribute(const char* name, int& value);
141 
143 
146  vtkGetMacro(NumberOfAttributes, int);
148 
153  const char* GetAttributeName(int idx);
154 
159  const char* GetAttributeValue(int idx);
160 
162 
165  virtual void RemoveAttribute(const char* name);
166  virtual void RemoveAllAttributes();
168 
170 
173  vtkXMLDataElement* GetParent();
174  void SetParent(vtkXMLDataElement* parent);
176 
180  virtual vtkXMLDataElement* GetRoot();
181 
185  int GetNumberOfNestedElements();
186 
190  vtkXMLDataElement* GetNestedElement(int index);
191 
195  void AddNestedElement(vtkXMLDataElement* element);
196 
200  virtual void RemoveNestedElement(vtkXMLDataElement*);
201 
205  virtual void RemoveAllNestedElements();
206 
208 
214  vtkXMLDataElement* FindNestedElement(const char* id);
215  vtkXMLDataElement* FindNestedElementWithName(const char* name);
216  vtkXMLDataElement* FindNestedElementWithNameAndId(const char* name, const char* id);
217  vtkXMLDataElement* FindNestedElementWithNameAndAttribute(
218  const char* name, const char* att_name, const char* att_value);
220 
225  vtkXMLDataElement* LookupElementWithName(const char* name);
226 
230  vtkXMLDataElement* LookupElement(const char* id);
231 
233 
236  vtkGetMacro(XMLByteIndex, vtkTypeInt64);
237  vtkSetMacro(XMLByteIndex, vtkTypeInt64);
239 
247  virtual int IsEqualTo(vtkXMLDataElement* elem);
248 
255  virtual void DeepCopy(vtkXMLDataElement* elem);
256 
258 
266  vtkSetClampMacro(AttributeEncoding, int, VTK_ENCODING_NONE, VTK_ENCODING_UNKNOWN);
267  vtkGetMacro(AttributeEncoding, int);
269 
271 
274  void PrintXML(ostream& os, vtkIndent indent);
275  void PrintXML(VTK_FILEPATH const char* fname);
277 
279 
287  vtkGetMacro(CharacterDataWidth, int);
288  vtkSetMacro(CharacterDataWidth, int);
290 
291 protected:
293  ~vtkXMLDataElement() override;
294 
295  // The name of the element from the XML file.
296  char* Name;
297  // The value of the "id" attribute, if any was given.
298  char* Id;
299 
301 
302  // Data inside of the tag's open and close. ie <X> character data </X>
303  char* CharacterData; // Null terminated buffer.
304  size_t CharacterDataBlockSize; // Allocation size if buffer needs expand
305  size_t CharacterDataBufferSize; // Allocated size.
306  size_t EndOfCharacterData; // Number of bytes used.
307 
308  // Tags that have specialized character data handlers
309  // can set this flag to improve performance. The default is unset.
311 
312  // Get/Set the stream position of the elements inline data.
313  vtkGetMacro(InlineDataPosition, vtkTypeInt64);
314  vtkSetMacro(InlineDataPosition, vtkTypeInt64);
315  // The offset into the XML stream where the inline data begins.
316  vtkTypeInt64 InlineDataPosition;
317  // The offset into the XML stream where the element begins.
318  vtkTypeInt64 XMLByteIndex;
319 
320  // The raw property name/value pairs read from the XML attributes.
326 
327  // The set of nested elements.
331  // The parent of this element.
333 
334  // Internal utility methods.
335  vtkXMLDataElement* LookupElementInScope(const char* id);
336  vtkXMLDataElement* LookupElementUpScope(const char* id);
337  static int IsSpace(char c);
338  void PrintCharacterData(ostream& os, vtkIndent indent);
339  static void PrintWithEscapedData(ostream& os, const char* data);
340 
341  friend class vtkXMLDataParser;
342  friend class vtkXMLMaterialParser;
343 
344 private:
345  vtkXMLDataElement(const vtkXMLDataElement&) = delete;
346  void operator=(const vtkXMLDataElement&) = delete;
347 };
348 
349 //----------------------------------------------------------------------------
350 inline void vtkXMLDataElement::AddCharacterData(const char* data, size_t length)
351 {
352  if (this->IgnoreCharacterData)
353  {
354  return;
355  }
356  // This is the index where we start to put the new data at.
357  size_t eod = this->EndOfCharacterData - 1;
358  // Check if the new data will write off the end. If it does
359  // resize the character data buffer.
360  this->EndOfCharacterData += length;
361  if (this->EndOfCharacterData >= this->CharacterDataBufferSize)
362  {
363  while (this->EndOfCharacterData >= this->CharacterDataBufferSize)
364  {
366  }
367  this->CharacterData =
368  static_cast<char*>(realloc(this->CharacterData, this->CharacterDataBufferSize));
369  }
370  // put the new data at the end of the buffer, and null terminate.
371  char* pCD = this->CharacterData + eod;
372  memmove(pCD, data, length);
373  pCD[length] = '\0';
374  return;
375 }
376 
377 #endif
vtkXMLDataElement ** NestedElements
abstract base class for most VTK objects
Definition: vtkObject.h:62
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Represents an XML element and those nested inside.
#define VTK_ENCODING_UNKNOWN
vtkTypeInt64 XMLByteIndex
void AddCharacterData(const char *c, size_t length)
Set/Get the character data between XML start/end tags.
vtkXMLDataElement * Parent
a simple class to control print indentation
Definition: vtkIndent.h:39
#define VTK_ENCODING_NONE
#define VTK_FILEPATH
Used by vtkXMLReader to parse VTK XML files.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkTypeInt64 InlineDataPosition