VTK  9.0.1
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;
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* c, 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 
138  int GetWordTypeAttribute(const char* name, int& value);
139 
141 
144  vtkGetMacro(NumberOfAttributes, int);
146 
151  const char* GetAttributeName(int idx);
152 
157  const char* GetAttributeValue(int idx);
158 
160 
163  virtual void RemoveAttribute(const char* name);
164  virtual void RemoveAllAttributes();
166 
168 
174 
179 
184 
189 
194 
199 
203  virtual void RemoveAllNestedElements();
204 
206 
216  const char* name, const char* att_name, const char* att_value);
218 
224 
229 
231 
234  vtkGetMacro(XMLByteIndex, vtkTypeInt64);
235  vtkSetMacro(XMLByteIndex, vtkTypeInt64);
237 
245  virtual int IsEqualTo(vtkXMLDataElement* elem);
246 
253  virtual void DeepCopy(vtkXMLDataElement* elem);
254 
256 
264  vtkSetClampMacro(AttributeEncoding, int, VTK_ENCODING_NONE, VTK_ENCODING_UNKNOWN);
265  vtkGetMacro(AttributeEncoding, int);
267 
269 
272  void PrintXML(ostream& os, vtkIndent indent);
273  void PrintXML(const char* fname);
275 
277 
285  vtkGetMacro(CharacterDataWidth, int);
286  vtkSetMacro(CharacterDataWidth, int);
288 
289 protected:
291  ~vtkXMLDataElement() override;
292 
293  // The name of the element from the XML file.
294  char* Name;
295  // The value of the "id" attribute, if any was given.
296  char* Id;
297 
299 
300  // Data inside of the tag's open and close. ie <X> character data </X>
301  char* CharacterData; // Null terminated buffer.
302  size_t CharacterDataBlockSize; // Allocation size if buffer needs expand
303  size_t CharacterDataBufferSize; // Allocated size.
304  size_t EndOfCharacterData; // Number of bytes used.
305 
306  // Tags that have specialized character data handlers
307  // can set this flag to improve performance. The default is unset.
309 
310  // Get/Set the stream position of the elements inline data.
311  vtkGetMacro(InlineDataPosition, vtkTypeInt64);
312  vtkSetMacro(InlineDataPosition, vtkTypeInt64);
313  // The offset into the XML stream where the inline data begins.
314  vtkTypeInt64 InlineDataPosition;
315  // The offset into the XML stream where the element begins.
316  vtkTypeInt64 XMLByteIndex;
317 
318  // The raw property name/value pairs read from the XML attributes.
324 
325  // The set of nested elements.
329  // The parent of this element.
331 
332  // Internal utility methods.
335  static int IsSpace(char c);
336  void PrintCharacterData(ostream& os, vtkIndent indent);
337  static void PrintWithEscapedData(ostream& os, const char* data);
338 
339  friend class vtkXMLDataParser;
340  friend class vtkXMLMaterialParser;
341 
342 private:
343  vtkXMLDataElement(const vtkXMLDataElement&) = delete;
344  void operator=(const vtkXMLDataElement&) = delete;
345 };
346 
347 //----------------------------------------------------------------------------
348 inline void vtkXMLDataElement::AddCharacterData(const char* data, size_t length)
349 {
350  if (this->IgnoreCharacterData)
351  {
352  return;
353  }
354  // This is the index where we start to put the new data at.
355  size_t eod = this->EndOfCharacterData - 1;
356  // Check if the new data will write off the end. If it does
357  // resize the character data buffer.
358  this->EndOfCharacterData += length;
359  if (this->EndOfCharacterData >= this->CharacterDataBufferSize)
360  {
361  while (this->EndOfCharacterData >= this->CharacterDataBufferSize)
362  {
364  }
365  this->CharacterData =
366  static_cast<char*>(realloc(this->CharacterData, this->CharacterDataBufferSize));
367  }
368  // put the new data at the end of the buffer, and null terminate.
369  char* pCD = this->CharacterData + eod;
370  memmove(pCD, data, length);
371  pCD[length] = '\0';
372  return;
373 }
374 
375 #endif
a simple class to control print indentation
Definition: vtkIndent.h:34
abstract base class for most VTK objects
Definition: vtkObject.h:63
Represents an XML element and those nested inside.
int GetScalarAttribute(const char *name, unsigned long &value)
vtkTypeInt64 XMLByteIndex
const char * GetAttributeName(int idx)
Get the n-th attribute name.
void SetAttribute(const char *name, const char *value)
Set the attribute with the given name and value.
virtual void RemoveAllNestedElements()
Remove all nested elements.
int GetScalarAttribute(const char *name, unsigned long long &value)
static void PrintWithEscapedData(ostream &os, const char *data)
virtual vtkXMLDataElement * GetRoot()
Get root of the XML tree this element is part of.
vtkXMLDataElement ** NestedElements
vtkXMLDataElement * GetParent()
Set/Get the parent of this element.
int GetVectorAttribute(const char *name, int length, unsigned long long *value)
void PrintCharacterData(ostream &os, vtkIndent indent)
vtkXMLDataElement * FindNestedElementWithName(const char *name)
void PrintXML(ostream &os, vtkIndent indent)
Prints element tree as XML.
const char * GetAttribute(const char *name)
Get the attribute with the given name.
vtkTypeInt64 InlineDataPosition
int GetVectorAttribute(const char *name, int length, double *value)
void SetDoubleAttribute(const char *name, double value)
void SetVectorAttribute(const char *name, int length, const int *value)
Set the attribute with the given name.
int GetVectorAttribute(const char *name, int length, long long *value)
vtkXMLDataElement * FindNestedElement(const char *id)
Find the first nested element with the given id, given name, or given name and id.
void SetVectorAttribute(const char *name, int length, long long const *value)
int GetScalarAttribute(const char *name, long &value)
int GetScalarAttribute(const char *name, float &value)
void SetVectorAttribute(const char *name, int length, const float *value)
static int IsSpace(char c)
vtkXMLDataElement * GetNestedElement(int index)
Get the element nested in this one at the given index.
~vtkXMLDataElement() override
void SetVectorAttribute(const char *name, int length, unsigned long long const *value)
vtkXMLDataElement * LookupElementUpScope(const char *id)
void SetUnsignedLongAttribute(const char *name, unsigned long value)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int GetScalarAttribute(const char *name, int &value)
Get the attribute with the given name and converted to a scalar value.
virtual void SetName(const char *_arg)
int GetVectorAttribute(const char *name, int length, float *value)
vtkXMLDataElement * LookupElementWithName(const char *name)
Find the first nested element with given name.
void SetIntAttribute(const char *name, int value)
Set the attribute with the given name.
int GetVectorAttribute(const char *name, int length, int *value)
Get the attribute with the given name and converted to a scalar value.
virtual void RemoveAllAttributes()
static vtkXMLDataElement * New()
const char * GetAttributeValue(int idx)
Get the n-th attribute value.
virtual int IsEqualTo(vtkXMLDataElement *elem)
Check if the instance has the same name, attributes, character data and nested elements contents than...
void PrintXML(const char *fname)
void SetVectorAttribute(const char *name, int length, const unsigned long *value)
int GetVectorAttribute(const char *name, int length, long *value)
void AddCharacterData(const char *c, size_t length)
vtkXMLDataElement * LookupElementInScope(const char *id)
int GetVectorAttribute(const char *name, int length, unsigned long *value)
void SetFloatAttribute(const char *name, float value)
virtual void RemoveNestedElement(vtkXMLDataElement *)
Remove nested element.
vtkXMLDataElement * Parent
void SetParent(vtkXMLDataElement *parent)
vtkXMLDataElement * LookupElement(const char *id)
Lookup the element with the given id, starting at this scope.
virtual void DeepCopy(vtkXMLDataElement *elem)
Copy this element from another of the same type (elem), recursively.
int GetNumberOfNestedElements()
Get the number of elements nested in this one.
virtual void RemoveAttribute(const char *name)
Remove one or all attributes.
int GetScalarAttribute(const char *name, double &value)
vtkXMLDataElement * FindNestedElementWithNameAndId(const char *name, const char *id)
vtkXMLDataElement * FindNestedElementWithNameAndAttribute(const char *name, const char *att_name, const char *att_value)
void SetCharacterData(const char *c, int length)
Set/Get the character data between XML start/end tags.
int GetWordTypeAttribute(const char *name, int &value)
Get the attribute with the given name and converted to a word type such as VTK_FLOAT or VTK_UNSIGNED_...
void AddNestedElement(vtkXMLDataElement *element)
Add nested element.
int GetScalarAttribute(const char *name, long long &value)
void SetVectorAttribute(const char *name, int length, const double *value)
Used by vtkXMLReader to parse VTK XML files.
@ length
Definition: vtkX3D.h:399
@ value
Definition: vtkX3D.h:226
@ name
Definition: vtkX3D.h:225
@ index
Definition: vtkX3D.h:252
@ data
Definition: vtkX3D.h:321
#define VTK_ENCODING_UNKNOWN
#define VTK_ENCODING_NONE