VTK: Common/DataModel/vtkXMLDataElement.h Source File

| VTK 9.3.1

vtkXMLDataElement.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
16 #ifndef vtkXMLDataElement_h
17 #define vtkXMLDataElement_h
18
19 #include "vtkCommonDataModelModule.h" // For export macro
20 #include "vtkObject.h"
21
22 VTK_ABI_NAMESPACE_BEGIN
23 class vtkXMLDataParser;
24
25 class VTKCOMMONDATAMODEL_EXPORT vtkXMLDataElement : public vtkObject
26 {
27 public:
28 vtkTypeMacro(vtkXMLDataElement, vtkObject);
29 void PrintSelf(ostream& os, vtkIndent indent) override;
30 static vtkXMLDataElement* New();
31
33
36 vtkGetStringMacro(Name);
37 virtual void SetName(const char* _arg);
39
41
44 vtkGetStringMacro(Id);
45 vtkSetStringMacro(Id);
47
52 const char* GetAttribute(const char* name);
53
58 void SetAttribute(const char* name, const char* value);
59
61
64 void SetCharacterData(const char* data, int length);
65 void AddCharacterData(const char* c, size_t length);
66 vtkGetStringMacro(CharacterData);
68
70
74 int GetScalarAttribute(const char* name, int& value);
75 int GetScalarAttribute(const char* name, float& value);
76 int GetScalarAttribute(const char* name, double& value);
77 int GetScalarAttribute(const char* name, long& value);
78 int GetScalarAttribute(const char* name, unsigned long& value);
80
82
88 void SetIntAttribute(const char* name, int value);
89 void SetFloatAttribute(const char* name, float value);
90 void SetDoubleAttribute(const char* name, double value);
91 void SetUnsignedLongAttribute(const char* name, unsigned long value);
93
95
99 int GetVectorAttribute(const char* name, int length, int* value);
100 int GetVectorAttribute(const char* name, int length, float* value);
101 int GetVectorAttribute(const char* name, int length, double* value);
102 int GetVectorAttribute(const char* name, int length, long* value);
103 int GetVectorAttribute(const char* name, int length, unsigned long* value);
105
107
110 void SetVectorAttribute(const char* name, int length, const int* value);
111 void SetVectorAttribute(const char* name, int length, const float* value);
112 void SetVectorAttribute(const char* name, int length, const double* value);
113 void SetVectorAttribute(const char* name, int length, const unsigned long* value);
115
116 int GetScalarAttribute(const char* name, long long& value);
117 int GetVectorAttribute(const char* name, int length, long long* value);
118 void SetVectorAttribute(const char* name, int length, long long const* value);
119 int GetScalarAttribute(const char* name, unsigned long long& value);
120 int GetVectorAttribute(const char* name, int length, unsigned long long* value);
121 void SetVectorAttribute(const char* name, int length, unsigned long long const* value);
122
129 int GetWordTypeAttribute(const char* name, int& value);
130
132
135 vtkGetMacro(NumberOfAttributes, int);
137
142 const char* GetAttributeName(int idx);
143
148 const char* GetAttributeValue(int idx);
149
151
154 virtual void RemoveAttribute(const char* name);
155 virtual void RemoveAllAttributes();
157
159
162 vtkXMLDataElement* GetParent();
163 void SetParent(vtkXMLDataElement* parent);
165
169 virtual vtkXMLDataElement* GetRoot();
170
174 int GetNumberOfNestedElements();
175
179 vtkXMLDataElement* GetNestedElement(int index);
180
184 void AddNestedElement(vtkXMLDataElement* element);
185
189 virtual void RemoveNestedElement(vtkXMLDataElement*);
190
194 virtual void RemoveAllNestedElements();
195
197
203 vtkXMLDataElement* FindNestedElement(const char* id);
204 vtkXMLDataElement* FindNestedElementWithName(const char* name);
205 vtkXMLDataElement* FindNestedElementWithNameAndId(const char* name, const char* id);
206 vtkXMLDataElement* FindNestedElementWithNameAndAttribute(
207 const char* name, const char* att_name, const char* att_value);
209
214 vtkXMLDataElement* LookupElementWithName(const char* name);
215
219 vtkXMLDataElement* LookupElement(const char* id);
220
222
225 vtkGetMacro(XMLByteIndex, vtkTypeInt64);
226 vtkSetMacro(XMLByteIndex, vtkTypeInt64);
228
236 virtual int IsEqualTo(vtkXMLDataElement* elem);
237
244 virtual void DeepCopy(vtkXMLDataElement* elem);
245
247
255 vtkSetClampMacro(AttributeEncoding, int, VTK_ENCODING_NONE, VTK_ENCODING_UNKNOWN);
256 vtkGetMacro(AttributeEncoding, int);
258
260
263 void PrintXML(ostream& os, vtkIndent indent);
264 void PrintXML(VTK_FILEPATH const char* fname);
266
268
276 vtkGetMacro(CharacterDataWidth, int);
277 vtkSetMacro(CharacterDataWidth, int);
279
280 protected:
281 vtkXMLDataElement();
282 ~vtkXMLDataElement() override;
283
284 // The name of the element from the XML file.
285 char* Name;
286 // The value of the "id" attribute, if any was given.
287 char* Id;
288
289 int CharacterDataWidth;
290
291 // Data inside of the tag's open and close. ie <X> character data </X>
292 char* CharacterData; // Null terminated buffer.
293 size_t CharacterDataBlockSize; // Allocation size if buffer needs expand
294 size_t CharacterDataBufferSize; // Allocated size.
295 size_t EndOfCharacterData; // Number of bytes used.
296
297 // Tags that have specialized character data handlers
298 // can set this flag to improve performance. The default is unset.
299 vtkTypeBool IgnoreCharacterData;
300
301 // Get/Set the stream position of the elements inline data.
302 vtkGetMacro(InlineDataPosition, vtkTypeInt64);
303 vtkSetMacro(InlineDataPosition, vtkTypeInt64);
304 // The offset into the XML stream where the inline data begins.
305 vtkTypeInt64 InlineDataPosition;
306 // The offset into the XML stream where the element begins.
307 vtkTypeInt64 XMLByteIndex;
308
309 // The raw property name/value pairs read from the XML attributes.
310 char** AttributeNames;
311 char** AttributeValues;
312 int NumberOfAttributes;
313 int AttributesSize;
314 int AttributeEncoding;
315
316 // The set of nested elements.
317 int NumberOfNestedElements;
318 int NestedElementsSize;
319 vtkXMLDataElement** NestedElements;
320 // The parent of this element.
321 vtkXMLDataElement* Parent;
322
323 // Internal utility methods.
324 vtkXMLDataElement* LookupElementInScope(const char* id);
325 vtkXMLDataElement* LookupElementUpScope(const char* id);
326 static int IsSpace(char c);
327 void PrintCharacterData(ostream& os, vtkIndent indent);
328 static void PrintWithEscapedData(ostream& os, const char* data);
329
330 friend class vtkXMLDataParser;
331 friend class vtkXMLMaterialParser;
332
333 private:
334 vtkXMLDataElement(const vtkXMLDataElement&) = delete;
335 void operator=(const vtkXMLDataElement&) = delete;
336 };
337
338 //----------------------------------------------------------------------------
339 inline void vtkXMLDataElement::AddCharacterData(const char* data, size_t length)
340 {
341 if (this->IgnoreCharacterData)
342 {
343 return;
344 }
345 // This is the index where we start to put the new data at.
346 size_t eod = this->EndOfCharacterData - 1;
347 // Check if the new data will write off the end. If it does
348 // resize the character data buffer.
349 this->EndOfCharacterData += length;
350 if (this->EndOfCharacterData >= this->CharacterDataBufferSize)
351 {
352 while (this->EndOfCharacterData >= this->CharacterDataBufferSize)
353 {
354 this->CharacterDataBufferSize += this->CharacterDataBlockSize;
355 }
356 this->CharacterData =
357 static_cast<char*>(realloc(this->CharacterData, this->CharacterDataBufferSize));
358 }
359 // put the new data at the end of the buffer, and null terminate.
360 char* pCD = this->CharacterData + eod;
361 memmove(pCD, data, length);
362 pCD[length] = '\0';
363 }
364
365 VTK_ABI_NAMESPACE_END
366 #endif
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:61
vtkXMLDataElement
Represents an XML element and those nested inside.
Definition: vtkXMLDataElement.h:26
vtkXMLDataElement::GetScalarAttribute
int GetScalarAttribute(const char *name, unsigned long &value)
Get the attribute with the given name and converted to a scalar value.
vtkXMLDataElement::XMLByteIndex
vtkTypeInt64 XMLByteIndex
Definition: vtkXMLDataElement.h:307
vtkXMLDataElement::GetAttributeName
const char * GetAttributeName(int idx)
Get the n-th attribute name.
vtkXMLDataElement::SetAttribute
void SetAttribute(const char *name, const char *value)
Set the attribute with the given name and value.
vtkXMLDataElement::RemoveAllNestedElements
virtual void RemoveAllNestedElements()
Remove all nested elements.
vtkXMLDataElement::GetScalarAttribute
int GetScalarAttribute(const char *name, unsigned long long &value)
vtkXMLDataElement::PrintXML
void PrintXML(VTK_FILEPATH const char *fname)
Prints element tree as XML.
vtkXMLDataElement::PrintWithEscapedData
static void PrintWithEscapedData(ostream &os, const char *data)
vtkXMLDataElement::GetRoot
virtual vtkXMLDataElement * GetRoot()
Get root of the XML tree this element is part of.
vtkXMLDataElement::NestedElements
vtkXMLDataElement ** NestedElements
Definition: vtkXMLDataElement.h:319
vtkXMLDataElement::GetParent
vtkXMLDataElement * GetParent()
Set/Get the parent of this element.
vtkXMLDataElement::GetVectorAttribute
int GetVectorAttribute(const char *name, int length, unsigned long long *value)
vtkXMLDataElement::PrintCharacterData
void PrintCharacterData(ostream &os, vtkIndent indent)
vtkXMLDataElement::AttributeNames
char ** AttributeNames
Definition: vtkXMLDataElement.h:310
vtkXMLDataElement::FindNestedElementWithName
vtkXMLDataElement * FindNestedElementWithName(const char *name)
Find the first nested element with the given id, given name, or given name and id.
vtkXMLDataElement::PrintXML
void PrintXML(ostream &os, vtkIndent indent)
Prints element tree as XML.
vtkXMLDataElement::GetAttribute
const char * GetAttribute(const char *name)
Get the attribute with the given name.
vtkXMLDataElement::InlineDataPosition
vtkTypeInt64 InlineDataPosition
Definition: vtkXMLDataElement.h:303
vtkXMLDataElement::GetVectorAttribute
int GetVectorAttribute(const char *name, int length, double *value)
Get the attribute with the given name and converted to a scalar value.
vtkXMLDataElement::SetDoubleAttribute
void SetDoubleAttribute(const char *name, double value)
Set the attribute with the given name.
vtkXMLDataElement::SetVectorAttribute
void SetVectorAttribute(const char *name, int length, const int *value)
Set the attribute with the given name.
vtkXMLDataElement::GetVectorAttribute
int GetVectorAttribute(const char *name, int length, long long *value)
vtkXMLDataElement::FindNestedElement
vtkXMLDataElement * FindNestedElement(const char *id)
Find the first nested element with the given id, given name, or given name and id.
vtkXMLDataElement::AttributesSize
int AttributesSize
Definition: vtkXMLDataElement.h:313
vtkXMLDataElement::vtkXMLDataElement
vtkXMLDataElement()
vtkXMLDataElement::SetVectorAttribute
void SetVectorAttribute(const char *name, int length, long long const *value)
vtkXMLDataElement::GetScalarAttribute
int GetScalarAttribute(const char *name, long &value)
Get the attribute with the given name and converted to a scalar value.
vtkXMLDataElement::GetScalarAttribute
int GetScalarAttribute(const char *name, float &value)
Get the attribute with the given name and converted to a scalar value.
vtkXMLDataElement::SetVectorAttribute
void SetVectorAttribute(const char *name, int length, const float *value)
Set the attribute with the given name.
vtkXMLDataElement::Id
char * Id
Definition: vtkXMLDataElement.h:287
vtkXMLDataElement::IsSpace
static int IsSpace(char c)
vtkXMLDataElement::GetNestedElement
vtkXMLDataElement * GetNestedElement(int index)
Get the element nested in this one at the given index.
vtkXMLDataElement::NumberOfNestedElements
int NumberOfNestedElements
Definition: vtkXMLDataElement.h:317
vtkXMLDataElement::AttributeEncoding
int AttributeEncoding
Definition: vtkXMLDataElement.h:314
vtkXMLDataElement::~vtkXMLDataElement
~vtkXMLDataElement() override
vtkXMLDataElement::SetVectorAttribute
void SetVectorAttribute(const char *name, int length, unsigned long long const *value)
vtkXMLDataElement::NumberOfAttributes
int NumberOfAttributes
Definition: vtkXMLDataElement.h:312
vtkXMLDataElement::LookupElementUpScope
vtkXMLDataElement * LookupElementUpScope(const char *id)
vtkXMLDataElement::NestedElementsSize
int NestedElementsSize
Definition: vtkXMLDataElement.h:318
vtkXMLDataElement::SetUnsignedLongAttribute
void SetUnsignedLongAttribute(const char *name, unsigned long value)
Set the attribute with the given name.
vtkXMLDataElement::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkXMLDataElement::GetScalarAttribute
int GetScalarAttribute(const char *name, int &value)
Get the attribute with the given name and converted to a scalar value.
vtkXMLDataElement::IgnoreCharacterData
vtkTypeBool IgnoreCharacterData
Definition: vtkXMLDataElement.h:299
vtkXMLDataElement::SetName
virtual void SetName(const char *_arg)
Set/Get the name of the element.
vtkXMLDataElement::GetVectorAttribute
int GetVectorAttribute(const char *name, int length, float *value)
Get the attribute with the given name and converted to a scalar value.
vtkXMLDataElement::LookupElementWithName
vtkXMLDataElement * LookupElementWithName(const char *name)
Find the first nested element with given name.
vtkXMLDataElement::EndOfCharacterData
size_t EndOfCharacterData
Definition: vtkXMLDataElement.h:295
vtkXMLDataElement::SetIntAttribute
void SetIntAttribute(const char *name, int value)
Set the attribute with the given name.
vtkXMLDataElement::GetVectorAttribute
int GetVectorAttribute(const char *name, int length, int *value)
Get the attribute with the given name and converted to a scalar value.
vtkXMLDataElement::RemoveAllAttributes
virtual void RemoveAllAttributes()
Remove one or all attributes.
vtkXMLDataElement::New
static vtkXMLDataElement * New()
vtkXMLDataElement::CharacterData
char * CharacterData
Definition: vtkXMLDataElement.h:292
vtkXMLDataElement::GetAttributeValue
const char * GetAttributeValue(int idx)
Get the n-th attribute value.
vtkXMLDataElement::CharacterDataBlockSize
size_t CharacterDataBlockSize
Definition: vtkXMLDataElement.h:293
vtkXMLDataElement::IsEqualTo
virtual int IsEqualTo(vtkXMLDataElement *elem)
Check if the instance has the same name, attributes, character data and nested elements contents than...
vtkXMLDataElement::SetVectorAttribute
void SetVectorAttribute(const char *name, int length, const unsigned long *value)
Set the attribute with the given name.
vtkXMLDataElement::GetVectorAttribute
int GetVectorAttribute(const char *name, int length, long *value)
Get the attribute with the given name and converted to a scalar value.
vtkXMLDataElement::AddCharacterData
void AddCharacterData(const char *c, size_t length)
Set/Get the character data between XML start/end tags.
Definition: vtkXMLDataElement.h:339
vtkXMLDataElement::LookupElementInScope
vtkXMLDataElement * LookupElementInScope(const char *id)
vtkXMLDataElement::GetVectorAttribute
int GetVectorAttribute(const char *name, int length, unsigned long *value)
Get the attribute with the given name and converted to a scalar value.
vtkXMLDataElement::SetFloatAttribute
void SetFloatAttribute(const char *name, float value)
Set the attribute with the given name.
vtkXMLDataElement::CharacterDataWidth
int CharacterDataWidth
Definition: vtkXMLDataElement.h:289
vtkXMLDataElement::CharacterDataBufferSize
size_t CharacterDataBufferSize
Definition: vtkXMLDataElement.h:294
vtkXMLDataElement::RemoveNestedElement
virtual void RemoveNestedElement(vtkXMLDataElement *)
Remove nested element.
vtkXMLDataElement::Parent
vtkXMLDataElement * Parent
Definition: vtkXMLDataElement.h:321
vtkXMLDataElement::SetParent
void SetParent(vtkXMLDataElement *parent)
Set/Get the parent of this element.
vtkXMLDataElement::LookupElement
vtkXMLDataElement * LookupElement(const char *id)
Lookup the element with the given id, starting at this scope.
vtkXMLDataElement::AttributeValues
char ** AttributeValues
Definition: vtkXMLDataElement.h:311
vtkXMLDataElement::DeepCopy
virtual void DeepCopy(vtkXMLDataElement *elem)
Copy this element from another of the same type (elem), recursively.
vtkXMLDataElement::GetNumberOfNestedElements
int GetNumberOfNestedElements()
Get the number of elements nested in this one.
vtkXMLDataElement::RemoveAttribute
virtual void RemoveAttribute(const char *name)
Remove one or all attributes.
vtkXMLDataElement::GetScalarAttribute
int GetScalarAttribute(const char *name, double &value)
Get the attribute with the given name and converted to a scalar value.
vtkXMLDataElement::FindNestedElementWithNameAndId
vtkXMLDataElement * FindNestedElementWithNameAndId(const char *name, const char *id)
Find the first nested element with the given id, given name, or given name and id.
vtkXMLDataElement::FindNestedElementWithNameAndAttribute
vtkXMLDataElement * FindNestedElementWithNameAndAttribute(const char *name, const char *att_name, const char *att_value)
Find the first nested element with the given id, given name, or given name and id.
vtkXMLDataElement::Name
char * Name
Definition: vtkXMLDataElement.h:285
vtkXMLDataElement::SetCharacterData
void SetCharacterData(const char *data, int length)
Set/Get the character data between XML start/end tags.
vtkXMLDataElement::GetWordTypeAttribute
int GetWordTypeAttribute(const char *name, int &value)
Get the attribute with the given name and converted to a word type.
vtkXMLDataElement::AddNestedElement
void AddNestedElement(vtkXMLDataElement *element)
Add nested element.
vtkXMLDataElement::GetScalarAttribute
int GetScalarAttribute(const char *name, long long &value)
vtkXMLDataElement::SetVectorAttribute
void SetVectorAttribute(const char *name, int length, const double *value)
Set the attribute with the given name.
vtkXMLDataParser
Used by vtkXMLReader to parse VTK XML files.
Definition: vtkXMLDataParser.h:32
vtkX3D::length
@ length
Definition: vtkX3D.h:393
vtkX3D::value
@ value
Definition: vtkX3D.h:220
vtkX3D::name
@ name
Definition: vtkX3D.h:219
vtkX3D::index
@ index
Definition: vtkX3D.h:246
vtkX3D::data
@ data
Definition: vtkX3D.h:315
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:64
vtkObject.h
VTK_ENCODING_UNKNOWN
#define VTK_ENCODING_UNKNOWN
Definition: vtkSystemIncludes.h:117
VTK_ENCODING_NONE
#define VTK_ENCODING_NONE
Definition: vtkSystemIncludes.h:97
VTK_FILEPATH
#define VTK_FILEPATH
Definition: vtkWrappingHints.h:34