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);
41 
43 
45  virtual void SetName (const char* _arg);
47 
49 
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 #ifdef VTK_TYPE_USE_LONG_LONG
108  int GetScalarAttribute(const char* name, long long& value);
109  int GetVectorAttribute(const char* name, int length, long long* value);
110  void SetVectorAttribute(const char* name, int length, long long const* value);
111  int GetScalarAttribute(const char* name, unsigned long long& value);
112  int GetVectorAttribute(const char* name, int length, unsigned long long* value);
113  void SetVectorAttribute(const char* name, int length, unsigned long long const* value);
114 #endif
115 #ifdef VTK_TYPE_USE___INT64
116  int GetScalarAttribute(const char* name, __int64& value);
117  int GetVectorAttribute(const char* name, int length, __int64* value);
118  void SetVectorAttribute(const char* name, int length, __int64 const* value);
119  int GetScalarAttribute(const char* name, unsigned __int64& value);
120  int GetVectorAttribute(const char* name, int length, unsigned __int64* value);
121  void SetVectorAttribute(const char* name, int length, unsigned __int64 const* value);
122 #endif
123  //ETX
124 
127  int GetWordTypeAttribute(const char* name, int& value);
128 
130 
131  vtkGetMacro(NumberOfAttributes, int);
133 
135  const char* GetAttributeName(int idx);
136 
139  const char* GetAttributeValue(int idx);
140 
142 
143  virtual void RemoveAttribute(const char *name);
144  virtual void RemoveAllAttributes();
146 
148 
152 
155 
158 
161 
164 
167 
169  virtual void RemoveAllNestedElements();
170 
172 
178  const char* name, const char* id);
180  const char* name, const char* att_name, const char* att_value);
182 
186 
189 
191 
193  vtkGetMacro(XMLByteIndex, vtkTypeInt64);
194  vtkSetMacro(XMLByteIndex, vtkTypeInt64);
196 
201  virtual int IsEqualTo(vtkXMLDataElement *elem);
202 
206  virtual void DeepCopy(vtkXMLDataElement *elem);
207 
209 
215  vtkGetMacro(AttributeEncoding, int);
217 
219 
220  void PrintXML(ostream& os, vtkIndent indent);
221  void PrintXML(const char* fname);
223 
225 
230  vtkGetMacro(CharacterDataWidth,int);
231  vtkSetMacro(CharacterDataWidth,int);
233 
234 protected:
237 
238  // The name of the element from the XML file.
239  char* Name;
240  // The value of the "id" attribute, if any was given.
241  char* Id;
242 
244 
245  // Data inside of the tag's open and close. ie <X> character data </X>
246  char* CharacterData; // Null terminated buffer.
247  size_t CharacterDataBlockSize; // Allocation size if buffer needs expand
248  size_t CharacterDataBufferSize; // Allocated size.
249  size_t EndOfCharacterData; // Number of bytes used.
250 
251  // Tags that have specialized character data handlers
252  // can set this flag to improve performance. The default is unset.
254 
255  // Get/Set the stream position of the elements inline data.
256  vtkGetMacro(InlineDataPosition,vtkTypeInt64);
257  vtkSetMacro(InlineDataPosition,vtkTypeInt64);
258  // The offset into the XML stream where the inline data begins.
259  vtkTypeInt64 InlineDataPosition;
260  // The offset into the XML stream where the element begins.
261  vtkTypeInt64 XMLByteIndex;
262 
263  // The raw property name/value pairs read from the XML attributes.
269 
270  // The set of nested elements.
274  // The parent of this element.
276 
277  // Internal utility methods.
280  static int IsSpace(char c);
281  void PrintCharacterData(ostream &os,vtkIndent indent);
282  static void PrintWithEscapedData(ostream& os, const char* data);
283 
284  //BTX
285  friend class vtkXMLDataParser;
286  friend class vtkXMLMaterialParser;
287  //ETX
288 
289 private:
290  vtkXMLDataElement(const vtkXMLDataElement&); // Not implemented.
291  void operator=(const vtkXMLDataElement&); // Not implemented.
292 };
293 
294 //----------------------------------------------------------------------------
295 inline
297 {
298  if (this->IgnoreCharacterData){ return; }
299  // This is the index where we start to put the new data at.
300  size_t eod=this->EndOfCharacterData-1;
301  // Check if the new data will write off the end. If it does
302  // resize the character data buffer.
303  this->EndOfCharacterData+=length;
305  {
306  while(this->EndOfCharacterData>=this->CharacterDataBufferSize)
307  {
309  }
310  this->CharacterData
311  = static_cast<char *>(realloc(this->CharacterData,this->CharacterDataBufferSize));
312  }
313  // put the new data at the end of the buffer, and null terminate.
314  char *pCD=this->CharacterData+eod;
315  memmove(pCD,data,length);
316  pCD[length]='\0';
317  return;
318 }
319 
320 #endif
vtkXMLDataElement::AttributeValues
char ** AttributeValues
Definition: vtkXMLDataElement.h:265
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)
vtkXMLDataElement::AttributeNames
char ** AttributeNames
Definition: vtkXMLDataElement.h:264
vtkgl::data
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: vtkgl.h:11339
vtkXMLDataElement::GetVectorAttribute
int GetVectorAttribute(const char *name, int length, unsigned long *value)
vtkXMLDataElement::CharacterDataBufferSize
size_t CharacterDataBufferSize
Definition: vtkXMLDataElement.h:248
vtkXMLDataElement::AttributeEncoding
int AttributeEncoding
Definition: vtkXMLDataElement.h:268
vtkXMLDataElement::RemoveNestedElement
virtual void RemoveNestedElement(vtkXMLDataElement *)
vtkXMLDataElement::PrintXML
void PrintXML(ostream &os, vtkIndent indent)
vtkXMLDataElement::NestedElements
vtkXMLDataElement ** NestedElements
Definition: vtkXMLDataElement.h:273
vtkXMLDataElement::GetVectorAttribute
int GetVectorAttribute(const char *name, int length, int *value)
vtkXMLDataElement::SetIntAttribute
void SetIntAttribute(const char *name, int value)
vtkXMLDataElement::SetName
virtual void SetName(const char *_arg)
vtkCommonDataModelModule.h
vtkXMLDataElement::SetAttribute
void SetAttribute(const char *name, const char *value)
VTK_ENCODING_NONE
#define VTK_ENCODING_NONE
Definition: vtkSystemIncludes.h:137
vtkXMLDataElement::LookupElementInScope
vtkXMLDataElement * LookupElementInScope(const char *id)
vtkXMLDataElement::FindNestedElementWithNameAndId
vtkXMLDataElement * FindNestedElementWithNameAndId(const char *name, const char *id)
vtkTypeMacro
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:642
vtkXMLDataElement::XMLByteIndex
vtkTypeInt64 XMLByteIndex
Definition: vtkXMLDataElement.h:261
vtkXMLDataElement::GetAttributeValue
const char * GetAttributeValue(int idx)
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkXMLDataElement::FindNestedElement
vtkXMLDataElement * FindNestedElement(const char *id)
vtkXMLDataElement::Parent
vtkXMLDataElement * Parent
Definition: vtkXMLDataElement.h:275
vtkgl::length
GLuint GLsizei GLsizei * length
Definition: vtkgl.h:11992
vtkXMLDataElement::GetScalarAttribute
int GetScalarAttribute(const char *name, int &value)
vtkXMLDataElement::LookupElementUpScope
vtkXMLDataElement * LookupElementUpScope(const char *id)
vtkXMLDataElement::LookupElement
vtkXMLDataElement * LookupElement(const char *id)
vtkXMLDataElement::CharacterDataBlockSize
size_t CharacterDataBlockSize
Definition: vtkXMLDataElement.h:247
vtkXMLDataElement::GetWordTypeAttribute
int GetWordTypeAttribute(const char *name, int &value)
vtkXMLDataElement::AddCharacterData
void AddCharacterData(const char *c, size_t length)
Definition: vtkXMLDataElement.h:296
vtkXMLDataElement::FindNestedElementWithName
vtkXMLDataElement * FindNestedElementWithName(const char *name)
vtkSetClampMacro
#define vtkSetClampMacro(name, type, min, max)
Definition: vtkSetGet.h:143
vtkgl::name
GLuint const GLchar * name
Definition: vtkgl.h:11983
vtkXMLDataElement::CharacterDataWidth
int CharacterDataWidth
Definition: vtkXMLDataElement.h:243
vtkXMLDataElement::PrintXML
void PrintXML(const char *fname)
vtkgl::value
GLsizei const GLfloat * value
Definition: vtkgl.h:12021
vtkXMLDataElement::SetVectorAttribute
void SetVectorAttribute(const char *name, int length, const float *value)
vtkXMLDataElement::NumberOfAttributes
int NumberOfAttributes
Definition: vtkXMLDataElement.h:266
vtkgl::c
const GLubyte * c
Definition: vtkgl.h:15720
vtkXMLDataElement::IsEqualTo
virtual int IsEqualTo(vtkXMLDataElement *elem)
vtkXMLDataElement::SetDoubleAttribute
void SetDoubleAttribute(const char *name, double value)
vtkXMLDataElement::CharacterData
char * CharacterData
Definition: vtkXMLDataElement.h:246
vtkXMLDataElement::GetNestedElement
vtkXMLDataElement * GetNestedElement(int index)
vtkXMLDataElement::RemoveAttribute
virtual void RemoveAttribute(const char *name)
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkSetStringMacro
#define vtkSetStringMacro(name)
Definition: vtkSetGet.h:104
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:36
vtkGetMacro
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:93
vtkGetStringMacro
vtkGetStringMacro(ExtensionsString)
vtkXMLDataElement::GetScalarAttribute
int GetScalarAttribute(const char *name, unsigned long &value)
vtkXMLDataElement::New
static vtkXMLDataElement * New()
vtkObject.h
vtkXMLDataElement::SetVectorAttribute
void SetVectorAttribute(const char *name, int length, const int *value)
vtkXMLDataElement::PrintCharacterData
void PrintCharacterData(ostream &os, vtkIndent indent)
vtkXMLDataElement::LookupElementWithName
vtkXMLDataElement * LookupElementWithName(const char *name)
vtkXMLDataElement::IgnoreCharacterData
int IgnoreCharacterData
Definition: vtkXMLDataElement.h:253
vtkSetMacro
vtkSetMacro(IgnoreDriverBugs, bool)
vtkXMLDataElement::NumberOfNestedElements
int NumberOfNestedElements
Definition: vtkXMLDataElement.h:271
vtkgl::index
GLuint index
Definition: vtkgl.h:11983
vtkXMLDataElement::PrintWithEscapedData
static void PrintWithEscapedData(ostream &os, const char *data)
vtkXMLDataElement::~vtkXMLDataElement
~vtkXMLDataElement()
vtkXMLDataElement::SetCharacterData
void SetCharacterData(const char *c, int length)
vtkXMLDataElement::RemoveAllNestedElements
virtual void RemoveAllNestedElements()
VTK_ENCODING_UNKNOWN
#define VTK_ENCODING_UNKNOWN
Definition: vtkSystemIncludes.h:157
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)
vtkXMLDataElement::Name
char * Name
Definition: vtkXMLDataElement.h:239
vtkXMLDataElement::NestedElementsSize
int NestedElementsSize
Definition: vtkXMLDataElement.h:272
vtkXMLDataElement::vtkXMLDataElement
vtkXMLDataElement()
vtkXMLDataElement::SetVectorAttribute
void SetVectorAttribute(const char *name, int length, const unsigned long *value)
vtkXMLDataElement::GetNumberOfNestedElements
int GetNumberOfNestedElements()
VTKCOMMONDATAMODEL_EXPORT
#define VTKCOMMONDATAMODEL_EXPORT
Definition: vtkCommonDataModelModule.h:15
vtkXMLDataElement::EndOfCharacterData
size_t EndOfCharacterData
Definition: vtkXMLDataElement.h:249
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, float &value)
vtkXMLDataElement::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
vtkXMLDataElement::IsSpace
static int IsSpace(char c)
vtkXMLDataElement::GetRoot
virtual vtkXMLDataElement * GetRoot()
vtkXMLDataElement::AttributesSize
int AttributesSize
Definition: vtkXMLDataElement.h:267
vtkXMLDataElement::GetAttribute
const char * GetAttribute(const char *name)
vtkXMLDataElement::GetParent
vtkXMLDataElement * GetParent()
vtkXMLDataParser
Used by vtkXMLReader to parse VTK XML files.
Definition: vtkXMLDataParser.h:42
vtkXMLDataElement::DeepCopy
virtual void DeepCopy(vtkXMLDataElement *elem)
vtkXMLDataElement::InlineDataPosition
vtkTypeInt64 InlineDataPosition
Definition: vtkXMLDataElement.h:257
vtkXMLDataElement::Id
char * Id
Definition: vtkXMLDataElement.h:241