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 =========================================================================*/
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:
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 
215  const char* name, const char* id);
217  const char* name, const char* att_name, const char* att_value);
219 
225 
230 
232 
235  vtkGetMacro(XMLByteIndex, vtkTypeInt64);
236  vtkSetMacro(XMLByteIndex, vtkTypeInt64);
238 
246  virtual int IsEqualTo(vtkXMLDataElement *elem);
247 
254  virtual void DeepCopy(vtkXMLDataElement *elem);
255 
257 
265  vtkSetClampMacro(AttributeEncoding,int,VTK_ENCODING_NONE,VTK_ENCODING_UNKNOWN);
266  vtkGetMacro(AttributeEncoding, int);
268 
270 
273  void PrintXML(ostream& os, vtkIndent indent);
274  void PrintXML(const char* fname);
276 
278 
286  vtkGetMacro(CharacterDataWidth,int);
287  vtkSetMacro(CharacterDataWidth,int);
289 
290 protected:
292  ~vtkXMLDataElement() override;
293 
294  // The name of the element from the XML file.
295  char* Name;
296  // The value of the "id" attribute, if any was given.
297  char* Id;
298 
300 
301  // Data inside of the tag's open and close. ie <X> character data </X>
302  char* CharacterData; // Null terminated buffer.
303  size_t CharacterDataBlockSize; // Allocation size if buffer needs expand
304  size_t CharacterDataBufferSize; // Allocated size.
305  size_t EndOfCharacterData; // Number of bytes used.
306 
307  // Tags that have specialized character data handlers
308  // can set this flag to improve performance. The default is unset.
310 
311  // Get/Set the stream position of the elements inline data.
312  vtkGetMacro(InlineDataPosition,vtkTypeInt64);
313  vtkSetMacro(InlineDataPosition,vtkTypeInt64);
314  // The offset into the XML stream where the inline data begins.
315  vtkTypeInt64 InlineDataPosition;
316  // The offset into the XML stream where the element begins.
317  vtkTypeInt64 XMLByteIndex;
318 
319  // The raw property name/value pairs read from the XML attributes.
325 
326  // The set of nested elements.
330  // The parent of this element.
332 
333  // Internal utility methods.
336  static int IsSpace(char c);
337  void PrintCharacterData(ostream &os,vtkIndent indent);
338  static void PrintWithEscapedData(ostream& os, const char* data);
339 
340  friend class vtkXMLDataParser;
341  friend class vtkXMLMaterialParser;
342 
343 private:
344  vtkXMLDataElement(const vtkXMLDataElement&) = delete;
345  void operator=(const vtkXMLDataElement&) = delete;
346 };
347 
348 //----------------------------------------------------------------------------
349 inline
351 {
352  if (this->IgnoreCharacterData){ return; }
353  // This is the index where we start to put the new data at.
354  size_t eod=this->EndOfCharacterData-1;
355  // Check if the new data will write off the end. If it does
356  // resize the character data buffer.
357  this->EndOfCharacterData+=length;
359  {
360  while(this->EndOfCharacterData>=this->CharacterDataBufferSize)
361  {
363  }
364  this->CharacterData
365  = static_cast<char *>(realloc(this->CharacterData,this->CharacterDataBufferSize));
366  }
367  // put the new data at the end of the buffer, and null terminate.
368  char *pCD=this->CharacterData+eod;
369  memmove(pCD,data,length);
370  pCD[length]='\0';
371  return;
372 }
373 
374 #endif
vtkXMLDataElement::AttributeValues
char ** AttributeValues
Definition: vtkXMLDataElement.h:321
vtkXMLDataElement::GetVectorAttribute
int GetVectorAttribute(const char *name, int length, double *value)
vtkXMLDataElement::SetUnsignedLongAttribute
void SetUnsignedLongAttribute(const char *name, unsigned long value)
vtkXMLDataElement::AddNestedElement
void AddNestedElement(vtkXMLDataElement *element)
Add nested element.
vtkXMLDataElement::AttributeNames
char ** AttributeNames
Definition: vtkXMLDataElement.h:320
vtkXMLDataElement::GetVectorAttribute
int GetVectorAttribute(const char *name, int length, unsigned long *value)
vtkXMLDataElement::CharacterDataBufferSize
size_t CharacterDataBufferSize
Definition: vtkXMLDataElement.h:304
vtkXMLDataElement::AttributeEncoding
int AttributeEncoding
Definition: vtkXMLDataElement.h:324
vtkXMLDataElement::RemoveNestedElement
virtual void RemoveNestedElement(vtkXMLDataElement *)
Remove nested element.
vtkXMLDataElement::PrintXML
void PrintXML(ostream &os, vtkIndent indent)
Prints element tree as XML.
vtkXMLDataElement::NestedElements
vtkXMLDataElement ** NestedElements
Definition: vtkXMLDataElement.h:329
vtkX3D::value
@ value
Definition: vtkX3D.h:220
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::SetIntAttribute
void SetIntAttribute(const char *name, int value)
Set the attribute with the given name.
vtkXMLDataElement::SetName
virtual void SetName(const char *_arg)
vtkXMLDataElement::SetAttribute
void SetAttribute(const char *name, const char *value)
Set the attribute with the given name and value.
vtkX3D::data
@ data
Definition: vtkX3D.h:315
VTK_ENCODING_NONE
#define VTK_ENCODING_NONE
Definition: vtkSystemIncludes.h:140
vtkXMLDataElement::LookupElementInScope
vtkXMLDataElement * LookupElementInScope(const char *id)
vtkXMLDataElement::FindNestedElementWithNameAndId
vtkXMLDataElement * FindNestedElementWithNameAndId(const char *name, const char *id)
vtkXMLDataElement::XMLByteIndex
vtkTypeInt64 XMLByteIndex
Definition: vtkXMLDataElement.h:317
vtkXMLDataElement::GetAttributeValue
const char * GetAttributeValue(int idx)
Get the n-th attribute value.
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:60
vtkXMLDataElement::SetVectorAttribute
void SetVectorAttribute(const char *name, int length, long long const *value)
vtkXMLDataElement::GetScalarAttribute
int GetScalarAttribute(const char *name, unsigned long long &value)
vtkX3D::length
@ length
Definition: vtkX3D.h:393
vtkXMLDataElement::FindNestedElement
vtkXMLDataElement * FindNestedElement(const char *id)
Find the first nested element with the given id, given name, or given name and id.
vtkXMLDataElement::~vtkXMLDataElement
~vtkXMLDataElement() override
vtkXMLDataElement::Parent
vtkXMLDataElement * Parent
Definition: vtkXMLDataElement.h:331
vtkXMLDataElement::GetScalarAttribute
int GetScalarAttribute(const char *name, int &value)
Get the attribute with the given name and converted to a scalar value.
vtkXMLDataElement::LookupElementUpScope
vtkXMLDataElement * LookupElementUpScope(const char *id)
vtkXMLDataElement::LookupElement
vtkXMLDataElement * LookupElement(const char *id)
Lookup the element with the given id, starting at this scope.
vtkXMLDataElement::CharacterDataBlockSize
size_t CharacterDataBlockSize
Definition: vtkXMLDataElement.h:303
vtkXMLDataElement::GetWordTypeAttribute
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_...
vtkXMLDataElement::AddCharacterData
void AddCharacterData(const char *c, size_t length)
Definition: vtkXMLDataElement.h:350
vtkXMLDataElement::GetScalarAttribute
int GetScalarAttribute(const char *name, long long &value)
vtkXMLDataElement::GetVectorAttribute
int GetVectorAttribute(const char *name, int length, unsigned long long *value)
vtkXMLDataElement::FindNestedElementWithName
vtkXMLDataElement * FindNestedElementWithName(const char *name)
vtkXMLDataElement::CharacterDataWidth
int CharacterDataWidth
Definition: vtkXMLDataElement.h:299
vtkXMLDataElement::PrintXML
void PrintXML(const char *fname)
vtkXMLDataElement::SetVectorAttribute
void SetVectorAttribute(const char *name, int length, const float *value)
vtkXMLDataElement::NumberOfAttributes
int NumberOfAttributes
Definition: vtkXMLDataElement.h:322
vtkXMLDataElement::IsEqualTo
virtual int IsEqualTo(vtkXMLDataElement *elem)
Check if the instance has the same name, attributes, character data and nested elements contents than...
vtkXMLDataElement::SetDoubleAttribute
void SetDoubleAttribute(const char *name, double value)
vtkXMLDataElement::SetVectorAttribute
void SetVectorAttribute(const char *name, int length, unsigned long long const *value)
vtkXMLDataElement::CharacterData
char * CharacterData
Definition: vtkXMLDataElement.h:302
vtkXMLDataElement::GetNestedElement
vtkXMLDataElement * GetNestedElement(int index)
Get the element nested in this one at the given index.
vtkXMLDataElement::RemoveAttribute
virtual void RemoveAttribute(const char *name)
Remove one or all attributes.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkXMLDataElement::RemoveAllAttributes
virtual void RemoveAllAttributes()
vtkXMLDataElement::SetVectorAttribute
void SetVectorAttribute(const char *name, int length, const double *value)
vtkXMLDataElement
Represents an XML element and those nested inside.
Definition: vtkXMLDataElement.h:37
vtkXMLDataElement::GetScalarAttribute
int GetScalarAttribute(const char *name, unsigned long &value)
vtkXMLDataElement::New
static vtkXMLDataElement * New()
vtkXMLDataElement::GetVectorAttribute
int GetVectorAttribute(const char *name, int length, long *value)
vtkX3D::name
@ name
Definition: vtkX3D.h:219
vtkObject.h
vtkXMLDataElement::SetVectorAttribute
void SetVectorAttribute(const char *name, int length, const int *value)
Set the attribute with the given name.
vtkXMLDataElement::PrintCharacterData
void PrintCharacterData(ostream &os, vtkIndent indent)
vtkXMLDataElement::LookupElementWithName
vtkXMLDataElement * LookupElementWithName(const char *name)
Find the first nested element with given name.
vtkXMLDataElement::IgnoreCharacterData
int IgnoreCharacterData
Definition: vtkXMLDataElement.h:309
vtkXMLDataElement::NumberOfNestedElements
int NumberOfNestedElements
Definition: vtkXMLDataElement.h:327
vtkXMLDataElement::PrintWithEscapedData
static void PrintWithEscapedData(ostream &os, const char *data)
vtkXMLDataElement::SetCharacterData
void SetCharacterData(const char *c, int length)
Set/Get the character data between XML start/end tags.
vtkXMLDataElement::RemoveAllNestedElements
virtual void RemoveAllNestedElements()
Remove all nested elements.
VTK_ENCODING_UNKNOWN
#define VTK_ENCODING_UNKNOWN
Definition: vtkSystemIncludes.h:160
vtkXMLDataElement::SetParent
void SetParent(vtkXMLDataElement *parent)
vtkXMLDataElement::GetVectorAttribute
int GetVectorAttribute(const char *name, int length, float *value)
vtkXMLDataElement::FindNestedElementWithNameAndAttribute
vtkXMLDataElement * FindNestedElementWithNameAndAttribute(const char *name, const char *att_name, const char *att_value)
vtkXMLDataElement::GetAttributeName
const char * GetAttributeName(int idx)
Get the n-th attribute name.
vtkXMLDataElement::Name
char * Name
Definition: vtkXMLDataElement.h:295
vtkXMLDataElement::NestedElementsSize
int NestedElementsSize
Definition: vtkXMLDataElement.h:328
vtkXMLDataElement::vtkXMLDataElement
vtkXMLDataElement()
vtkXMLDataElement::SetVectorAttribute
void SetVectorAttribute(const char *name, int length, const unsigned long *value)
vtkXMLDataElement::GetVectorAttribute
int GetVectorAttribute(const char *name, int length, long long *value)
vtkXMLDataElement::GetNumberOfNestedElements
int GetNumberOfNestedElements()
Get the number of elements nested in this one.
vtkXMLDataElement::EndOfCharacterData
size_t EndOfCharacterData
Definition: vtkXMLDataElement.h:305
vtkXMLDataElement::GetScalarAttribute
int GetScalarAttribute(const char *name, double &value)
vtkXMLDataElement::SetFloatAttribute
void SetFloatAttribute(const char *name, float value)
vtkXMLDataElement::GetScalarAttribute
int GetScalarAttribute(const char *name, long &value)
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, float &value)
vtkX3D::index
@ index
Definition: vtkX3D.h:246
vtkXMLDataElement::IsSpace
static int IsSpace(char c)
vtkXMLDataElement::GetRoot
virtual vtkXMLDataElement * GetRoot()
Get root of the XML tree this element is part of.
vtkXMLDataElement::AttributesSize
int AttributesSize
Definition: vtkXMLDataElement.h:323
vtkXMLDataElement::GetAttribute
const char * GetAttribute(const char *name)
Get the attribute with the given name.
vtkXMLDataElement::GetParent
vtkXMLDataElement * GetParent()
Set/Get the parent of this element.
vtkXMLDataParser
Used by vtkXMLReader to parse VTK XML files.
Definition: vtkXMLDataParser.h:40
vtkXMLDataElement::DeepCopy
virtual void DeepCopy(vtkXMLDataElement *elem)
Copy this element from another of the same type (elem), recursively.
vtkXMLDataElement::InlineDataPosition
vtkTypeInt64 InlineDataPosition
Definition: vtkXMLDataElement.h:313
vtkXMLDataElement::Id
char * Id
Definition: vtkXMLDataElement.h:297