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 #include "vtkStdString.h" // needed for vtkStdString.
28 
29 class vtkCollection;
30 class vtkPVXMLParser;
31 
32 struct vtkPVXMLElementInternals;
33 
34 class VTKPVVTKEXTENSIONSCORE_EXPORT vtkPVXMLElement : public vtkObject
35 {
36 public:
37  vtkTypeMacro(vtkPVXMLElement, vtkObject);
38  void PrintSelf(ostream& os, vtkIndent indent) override;
39  static vtkPVXMLElement* New();
40 
42 
46  vtkSetStringMacro(Name);
47  vtkGetStringMacro(Name);
49 
51 
55  vtkGetStringMacro(Id);
57 
62  const char* GetAttribute(const char* name) { return this->GetAttributeOrDefault(name, NULL); }
63 
68  const char* GetAttributeOrEmpty(const char* name)
69  {
70  return this->GetAttributeOrDefault(name, "");
71  }
72 
77  const char* GetAttributeOrDefault(const char* name, const char* notFound);
78 
82  const char* GetCharacterData();
83 
85 
89  int GetScalarAttribute(const char* name, int* value);
90  int GetScalarAttribute(const char* name, float* value);
91  int GetScalarAttribute(const char* name, double* value);
92 #if defined(VTK_USE_64BIT_IDS)
93  int GetScalarAttribute(const char* name, vtkIdType* value);
94 #endif
95 
96 
98 
102  int GetVectorAttribute(const char* name, int length, int* value);
103  int GetVectorAttribute(const char* name, int length, float* value);
104  int GetVectorAttribute(const char* name, int length, double* value);
105 #if defined(VTK_USE_64BIT_IDS)
106  int GetVectorAttribute(const char* name, int length, vtkIdType* value);
107 #endif
108 
109 
111 
115  int GetCharacterDataAsVector(int length, int* value);
116  int GetCharacterDataAsVector(int length, float* value);
117  int GetCharacterDataAsVector(int length, double* value);
118 #if defined(VTK_USE_64BIT_IDS)
119  int GetCharacterDataAsVector(int length, vtkIdType* value);
120 #endif
121 
122 
126  vtkPVXMLElement* GetParent();
127 
131  unsigned int GetNumberOfNestedElements();
132 
136  vtkPVXMLElement* GetNestedElement(unsigned int index);
137 
143  vtkPVXMLElement* FindNestedElement(const char* id);
144 
148  vtkPVXMLElement* FindNestedElementByName(const char* name);
149 
153  void FindNestedElementByName(const char* name, vtkCollection* elements);
154 
158  void RemoveAllNestedElements();
159 
163  void RemoveNestedElement(vtkPVXMLElement*);
164 
168  void ReplaceNestedElement(vtkPVXMLElement* elementToReplace, vtkPVXMLElement* element);
169 
173  vtkPVXMLElement* LookupElement(const char* id);
174 
176 
179  void AddAttribute(const char* attrName, const char* attrValue);
180  void AddAttribute(const char* attrName, unsigned int attrValue);
181  void AddAttribute(const char* attrName, double attrValue);
182  void AddAttribute(const char* attrName, double attrValue, int precision);
183  void AddAttribute(const char* attrName, int attrValue);
184 #if defined(VTK_USE_64BIT_IDS)
185  void AddAttribute(const char* attrName, vtkIdType attrValue);
186 #endif
187 
188 
192  void RemoveAttribute(const char* attrName);
193 
201  void SetAttribute(const char* attrName, const char* attrValue);
202 
204 
209  void AddNestedElement(vtkPVXMLElement* element, int setPrent);
210  void AddNestedElement(vtkPVXMLElement* element);
212 
214 
217  void PrintXML(ostream& os, vtkIndent indent);
218  void PrintXML();
220 
229  void Merge(vtkPVXMLElement* element, const char* attributeName);
230 
232 
239  void GetElementsByName(const char* name, vtkCollection* elements);
240  void GetElementsByName(const char* name, vtkCollection* elements, bool recursively);
242 
246  static vtkStdString Encode(const char* plaintext);
247 
253  bool Equals(vtkPVXMLElement* other);
254 
258  void CopyTo(vtkPVXMLElement* other);
259 
263  void CopyAttributesTo(vtkPVXMLElement* other);
264 
265 protected:
266  vtkPVXMLElement();
267  ~vtkPVXMLElement() override;
268 
269  vtkPVXMLElementInternals* Internal;
270 
271  char* Name;
272  char* Id;
273 
274  // The parent of this element.
276 
277  // Method used by vtkPVXMLParser to setup the element.
278  vtkSetStringMacro(Id);
279  void ReadXMLAttributes(const char** atts);
280  void AddCharacterData(const char* data, int length);
281 
282  // Internal utility methods.
283  vtkPVXMLElement* LookupElementInScope(const char* id);
284  vtkPVXMLElement* LookupElementUpScope(const char* id);
285  void SetParent(vtkPVXMLElement* parent);
286 
287  friend class vtkPVXMLParser;
288 
289 private:
290  vtkPVXMLElement(const vtkPVXMLElement&) = delete;
291  void operator=(const vtkPVXMLElement&) = delete;
292 };
293 
294 #endif
const char * GetAttributeOrEmpty(const char *name)
Get the attribute with the given name.
void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
int vtkIdType
const char * GetAttribute(const char *name)
Get the attribute with the given name.
name
vtkPVXMLElement * Parent
vtkPVXMLElementInternals * Internal
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()
void operator=(const vtkObjectBase &)