ParaView
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 "vtkPVCommonModule.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 VTKPVCOMMON_EXPORT vtkPVXMLElement : public vtkObject
35 {
36 public:
37  vtkTypeMacro(vtkPVXMLElement, vtkObject);
38  void PrintSelf(ostream& os, vtkIndent indent);
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  vtkPVXMLElement* LookupElement(const char* id);
169 
171 
174  void AddAttribute(const char* attrName, const char* attrValue);
175  void AddAttribute(const char* attrName, unsigned int attrValue);
176  void AddAttribute(const char* attrName, double attrValue);
177  void AddAttribute(const char* attrName, double attrValue, int precision);
178  void AddAttribute(const char* attrName, int attrValue);
179 #if defined(VTK_USE_64BIT_IDS)
180  void AddAttribute(const char* attrName, vtkIdType attrValue);
181 #endif
182 
183 
187  void RemoveAttribute(const char* attrName);
188 
196  void SetAttribute(const char* attrName, const char* attrValue);
197 
199 
204  void AddNestedElement(vtkPVXMLElement* element, int setPrent);
205  void AddNestedElement(vtkPVXMLElement* element);
207 
209 
212  void PrintXML(ostream& os, vtkIndent indent);
213  void PrintXML();
215 
224  void Merge(vtkPVXMLElement* element, const char* attributeName);
225 
227 
234  void GetElementsByName(const char* name, vtkCollection* elements);
235  void GetElementsByName(const char* name, vtkCollection* elements, bool recursively);
237 
241  static vtkStdString Encode(const char* plaintext);
242 
248  bool Equals(vtkPVXMLElement* other);
249 
253  void CopyTo(vtkPVXMLElement* other);
254 
258  void CopyAttributesTo(vtkPVXMLElement* other);
259 
260 protected:
261  vtkPVXMLElement();
262  ~vtkPVXMLElement();
263 
264  vtkPVXMLElementInternals* Internal;
265 
266  char* Name;
267  char* Id;
268 
269  // The parent of this element.
271 
272  // Method used by vtkPVXMLParser to setup the element.
273  vtkSetStringMacro(Id);
274  void ReadXMLAttributes(const char** atts);
275  void AddCharacterData(const char* data, int length);
276 
277  // Internal utility methods.
278  vtkPVXMLElement* LookupElementInScope(const char* id);
279  vtkPVXMLElement* LookupElementUpScope(const char* id);
280  void SetParent(vtkPVXMLElement* parent);
281 
282  friend class vtkPVXMLParser;
283 
284 private:
285  vtkPVXMLElement(const vtkPVXMLElement&) VTK_DELETE_FUNCTION;
286  void operator=(const vtkPVXMLElement&) VTK_DELETE_FUNCTION;
287 };
288 
289 #endif
const char * GetAttributeOrEmpty(const char *name)
Get the attribute with the given name.
const char * GetAttribute(const char *name)
Get the attribute with the given 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...