vtkPVXMLElement.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-License-Identifier: BSD-3-Clause
10 #ifndef vtkPVXMLElement_h
11 #define vtkPVXMLElement_h
12 
13 #include "vtkObject.h"
14 #include "vtkPVVTKExtensionsCoreModule.h" // needed for export macro
15 
16 #include <string> // for std::string
17 
18 class vtkCollection;
19 class vtkPVXMLParser;
20 
21 struct vtkPVXMLElementInternals;
22 
24 {
25 public:
26  vtkTypeMacro(vtkPVXMLElement, vtkObject);
27  void PrintSelf(ostream& os, vtkIndent indent) override;
28  static vtkPVXMLElement* New();
29 
31 
35  vtkSetStringMacro(Name);
36  vtkGetStringMacro(Name);
38 
40 
44  vtkGetStringMacro(Id);
46 
51  const char* GetAttribute(const char* name) { return this->GetAttributeOrDefault(name, nullptr); }
52 
57  const char* GetAttributeOrEmpty(const char* name)
58  {
59  return this->GetAttributeOrDefault(name, "");
60  }
61 
66  const char* GetAttributeOrDefault(const char* name, const char* notFound);
67 
71  const char* GetCharacterData();
72 
74 
78  int GetScalarAttribute(const char* name, int* value);
79  int GetScalarAttribute(const char* name, float* value);
80  int GetScalarAttribute(const char* name, double* value);
81 #if defined(VTK_USE_64BIT_IDS)
82  int GetScalarAttribute(const char* name, vtkIdType* value);
83 #endif
84 
87 
91  int GetVectorAttribute(const char* name, int length, int* value);
92  int GetVectorAttribute(const char* name, int length, float* value);
93  int GetVectorAttribute(const char* name, int length, double* value);
94 #if defined(VTK_USE_64BIT_IDS)
95  int GetVectorAttribute(const char* name, int length, vtkIdType* value);
96 #endif
97 
100 
104  int GetCharacterDataAsVector(int length, int* value);
105  int GetCharacterDataAsVector(int length, float* value);
106  int GetCharacterDataAsVector(int length, double* value);
107 #if defined(VTK_USE_64BIT_IDS)
108  int GetCharacterDataAsVector(int length, vtkIdType* value);
109 #endif
110 
115  vtkPVXMLElement* GetParent();
116 
120  unsigned int GetNumberOfNestedElements();
121 
125  vtkPVXMLElement* GetNestedElement(unsigned int index);
126 
132  vtkPVXMLElement* FindNestedElement(const char* id);
133 
137  vtkPVXMLElement* FindNestedElementByName(const char* name);
138 
142  void FindNestedElementByName(const char* name, vtkCollection* elements);
143 
147  void RemoveAllNestedElements();
148 
152  void RemoveNestedElement(vtkPVXMLElement*);
153 
157  void ReplaceNestedElement(vtkPVXMLElement* elementToReplace, vtkPVXMLElement* element);
158 
162  vtkPVXMLElement* LookupElement(const char* id);
163 
165 
168  void AddAttribute(const char* attrName, const char* attrValue);
169  void AddAttribute(const char* attrName, unsigned int attrValue);
170  void AddAttribute(const char* attrName, double attrValue);
171  void AddAttribute(const char* attrName, double attrValue, int precision);
172  void AddAttribute(const char* attrName, int attrValue);
173 #if defined(VTK_USE_64BIT_IDS)
174  void AddAttribute(const char* attrName, vtkIdType attrValue);
175 #endif
176 
181  void RemoveAttribute(const char* attrName);
182 
190  void SetAttribute(const char* attrName, const char* attrValue);
191 
193 
198  void AddNestedElement(vtkPVXMLElement* element, int setPrent);
199  void AddNestedElement(vtkPVXMLElement* element);
201 
203 
206  void PrintXML(ostream& os, vtkIndent indent);
207  void PrintXML();
209 
218  void Merge(vtkPVXMLElement* element, const char* attributeName);
219 
221 
228  void GetElementsByName(const char* name, vtkCollection* elements);
229  void GetElementsByName(const char* name, vtkCollection* elements, bool recursively);
231 
235  static std::string Encode(const char* plaintext);
236 
242  bool Equals(vtkPVXMLElement* other);
243 
247  void CopyTo(vtkPVXMLElement* other);
248 
252  void CopyAttributesTo(vtkPVXMLElement* other);
253 
254 protected:
255  vtkPVXMLElement();
256  ~vtkPVXMLElement() override;
257 
258  vtkPVXMLElementInternals* Internal;
259 
260  char* Name;
261  char* Id;
262 
263  // The parent of this element.
265 
266  // Method used by vtkPVXMLParser to setup the element.
267  vtkSetStringMacro(Id);
268  void ReadXMLAttributes(const char** atts);
269  void AddCharacterData(const char* data, int length);
270 
271  // Internal utility methods.
272  vtkPVXMLElement* LookupElementInScope(const char* id);
273  vtkPVXMLElement* LookupElementUpScope(const char* id);
274  void SetParent(vtkPVXMLElement* parent);
275 
276  friend class vtkPVXMLParser;
277 
278 private:
279  vtkPVXMLElement(const vtkPVXMLElement&) = delete;
280  void operator=(const vtkPVXMLElement&) = delete;
281 };
282 
283 #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 &)