vtkPVXMLElement.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: vtkPVXMLElement.h
5 
6  Copyright (c) Kitware, Inc.
7  All rights reserved.
8  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 =========================================================================*/
22 #ifndef vtkPVXMLElement_h
23 #define vtkPVXMLElement_h
24 
25 #include "vtkObject.h"
26 #include "vtkPVVTKExtensionsCoreModule.h" // needed for export macro
27 
28 #include <string> // for std::string
29 
30 class vtkCollection;
31 class vtkPVXMLParser;
32 
33 struct vtkPVXMLElementInternals;
34 
36 {
37 public:
38  vtkTypeMacro(vtkPVXMLElement, vtkObject);
39  void PrintSelf(ostream& os, vtkIndent indent) override;
40  static vtkPVXMLElement* New();
41 
43 
47  vtkSetStringMacro(Name);
48  vtkGetStringMacro(Name);
50 
52 
56  vtkGetStringMacro(Id);
58 
63  const char* GetAttribute(const char* name) { return this->GetAttributeOrDefault(name, nullptr); }
64 
69  const char* GetAttributeOrEmpty(const char* name)
70  {
71  return this->GetAttributeOrDefault(name, "");
72  }
73 
78  const char* GetAttributeOrDefault(const char* name, const char* notFound);
79 
83  const char* GetCharacterData();
84 
86 
90  int GetScalarAttribute(const char* name, int* value);
91  int GetScalarAttribute(const char* name, float* value);
92  int GetScalarAttribute(const char* name, double* value);
93 #if defined(VTK_USE_64BIT_IDS)
94  int GetScalarAttribute(const char* name, vtkIdType* value);
95 #endif
96 
99 
103  int GetVectorAttribute(const char* name, int length, int* value);
104  int GetVectorAttribute(const char* name, int length, float* value);
105  int GetVectorAttribute(const char* name, int length, double* value);
106 #if defined(VTK_USE_64BIT_IDS)
107  int GetVectorAttribute(const char* name, int length, vtkIdType* value);
108 #endif
109 
112 
116  int GetCharacterDataAsVector(int length, int* value);
117  int GetCharacterDataAsVector(int length, float* value);
118  int GetCharacterDataAsVector(int length, double* value);
119 #if defined(VTK_USE_64BIT_IDS)
120  int GetCharacterDataAsVector(int length, vtkIdType* value);
121 #endif
122 
127  vtkPVXMLElement* GetParent();
128 
132  unsigned int GetNumberOfNestedElements();
133 
137  vtkPVXMLElement* GetNestedElement(unsigned int index);
138 
144  vtkPVXMLElement* FindNestedElement(const char* id);
145 
149  vtkPVXMLElement* FindNestedElementByName(const char* name);
150 
154  void FindNestedElementByName(const char* name, vtkCollection* elements);
155 
159  void RemoveAllNestedElements();
160 
164  void RemoveNestedElement(vtkPVXMLElement*);
165 
169  void ReplaceNestedElement(vtkPVXMLElement* elementToReplace, vtkPVXMLElement* element);
170 
174  vtkPVXMLElement* LookupElement(const char* id);
175 
177 
180  void AddAttribute(const char* attrName, const char* attrValue);
181  void AddAttribute(const char* attrName, unsigned int attrValue);
182  void AddAttribute(const char* attrName, double attrValue);
183  void AddAttribute(const char* attrName, double attrValue, int precision);
184  void AddAttribute(const char* attrName, int attrValue);
185 #if defined(VTK_USE_64BIT_IDS)
186  void AddAttribute(const char* attrName, vtkIdType attrValue);
187 #endif
188 
193  void RemoveAttribute(const char* attrName);
194 
202  void SetAttribute(const char* attrName, const char* attrValue);
203 
205 
210  void AddNestedElement(vtkPVXMLElement* element, int setPrent);
211  void AddNestedElement(vtkPVXMLElement* element);
213 
215 
218  void PrintXML(ostream& os, vtkIndent indent);
219  void PrintXML();
221 
230  void Merge(vtkPVXMLElement* element, const char* attributeName);
231 
233 
240  void GetElementsByName(const char* name, vtkCollection* elements);
241  void GetElementsByName(const char* name, vtkCollection* elements, bool recursively);
243 
247  static std::string Encode(const char* plaintext);
248 
254  bool Equals(vtkPVXMLElement* other);
255 
259  void CopyTo(vtkPVXMLElement* other);
260 
264  void CopyAttributesTo(vtkPVXMLElement* other);
265 
266 protected:
267  vtkPVXMLElement();
268  ~vtkPVXMLElement() override;
269 
270  vtkPVXMLElementInternals* Internal;
271 
272  char* Name;
273  char* Id;
274 
275  // The parent of this element.
277 
278  // Method used by vtkPVXMLParser to setup the element.
279  vtkSetStringMacro(Id);
280  void ReadXMLAttributes(const char** atts);
281  void AddCharacterData(const char* data, int length);
282 
283  // Internal utility methods.
284  vtkPVXMLElement* LookupElementInScope(const char* id);
285  vtkPVXMLElement* LookupElementUpScope(const char* id);
286  void SetParent(vtkPVXMLElement* parent);
287 
288  friend class vtkPVXMLParser;
289 
290 private:
291  vtkPVXMLElement(const vtkPVXMLElement&) = delete;
292  void operator=(const vtkPVXMLElement&) = delete;
293 };
294 
295 #endif
#define VTKPVVTKEXTENSIONSCORE_EXPORT
const char * GetAttributeOrEmpty(const char *name)
Get the attribute with the given name.
void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
length
int vtkIdType
const char * GetAttribute(const char *name)
Get the attribute with the given name.
name
vtkPVXMLElement * Parent
vtkPVXMLElementInternals * Internal
value
This is used by vtkPVXMLParser to represent an XML document starting at the root element.
This is a subclass of vtkXMLParser that constructs a representation of parsed XML using vtkPVXMLEleme...
static vtkObject * New()
index
void operator=(const vtkObjectBase &)