ITK  6.0.0
Insight Toolkit
itkDOMNode.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18
19#ifndef itkDOMNode_h
20#define itkDOMNode_h
21
22#include "itkObject.h"
23#include "itkObjectFactory.h"
24#include "ITKIOXMLExport.h"
25
26#include <string>
27#include <vector>
28#include <list>
29#include <map>
30
31namespace itk
32{
33
34class DOMTextNode; // forward declaration
35
53class ITKIOXML_EXPORT DOMNode : public Object
54{
55public:
56 ITK_DISALLOW_COPY_AND_MOVE(DOMNode);
57
59 using Self = DOMNode;
63
65 itkNewMacro(Self);
66
68 itkOverrideGetNameOfClassMacro(DOMNode);
69
71 using ChildrenListType = std::vector<DOMNode *>;
72 using ConstChildrenListType = std::vector<const DOMNode *>;
73
75 using AttributeKeyType = std::string;
76 using AttributeValueType = std::string;
77
78 using AttributeItemType = std::pair<const AttributeKeyType, AttributeValueType>;
79
81 using AttributesListType = std::list<AttributeItemType>;
82
83 using SizeType = size_t;
84 using IdentifierType = int;
85 using OffsetType = int;
86
88 virtual void
90 DOMNode *
92 const DOMNode *
93 GetParent() const;
97 itkSetMacro(Name, const std::string &);
98 itkGetConstReferenceMacro(Name, std::string);
102 itkSetMacro(ID, const std::string &);
103 itkGetConstReferenceMacro(ID, std::string);
107 virtual std::string
108 GetAttribute(const std::string & key) const;
109
111 virtual bool
112 HasAttribute(const std::string & key) const;
113
115 virtual void
116 SetAttribute(const std::string & key, const std::string & value);
117
119 virtual void
120 RemoveAttribute(const std::string & key);
121
126 virtual void
127 GetAllAttributes(AttributesListType & output, bool keepOriginalOrder = true) const;
128
130 virtual void
132
134 virtual SizeType
136
138 virtual void
140
142 virtual void
144
146 virtual void
147 GetChildren(const std::string & tag, ChildrenListType & output);
148
150 virtual void
151 GetChildren(const std::string & tag, ConstChildrenListType & output) const;
152
154 virtual void
156
158 virtual void
160
162 virtual void
164
166 virtual void
168
170 virtual void
172
174 virtual void
176
178 virtual void
180
182 virtual DOMNode *
184 virtual const DOMNode *
190 virtual DOMNode *
191 GetChild(const std::string & tag, IdentifierType i = 0);
192 virtual const DOMNode *
193 GetChild(const std::string & tag, IdentifierType i = 0) const;
197 virtual DOMNode *
198 GetChildByID(const std::string & value);
199 virtual const DOMNode *
200 GetChildByID(const std::string & value) const;
204 virtual DOMNode *
206 virtual const DOMNode *
211 virtual DOMNode *
213 virtual const DOMNode *
214 GetRoot() const;
218 virtual bool
219 ShareRoot(const DOMNode * node) const;
220
238 virtual DOMNode *
239 Find(const std::string & path);
240 virtual const DOMNode *
241 Find(const std::string & path) const;
245 virtual std::string
246 GetPath() const;
247
249 virtual DOMTextNode *
251 virtual const DOMTextNode *
256 virtual void
257 AddTextChild(const std::string & text, IdentifierType i = 0);
258
260 virtual void
261 AddTextChildAtBegin(const std::string & text);
262
264 virtual void
265 AddTextChildAtEnd(const std::string & text);
266
268 virtual void
269 SetTextChild(const std::string & text, IdentifierType i = 0);
270
271protected:
273
274private:
276 DOMNode * m_Parent{ nullptr };
277
279 std::string m_Name{};
280
282 std::string m_ID{};
283
285 using ChildrenContainer = std::vector<Pointer>;
286 ChildrenContainer m_Children{};
287
289 using AttributesContainer = std::map<AttributeKeyType, AttributeValueType>;
290 AttributesContainer m_Attributes{};
291
293 using OrderedAttributesContainer = std::list<AttributeItemType *>;
294 OrderedAttributesContainer m_OrderedAttributes{};
295};
296
297} // namespace itk
298
299#include "itkDOMTextNode.h"
300
301#include "itkStringTools.h"
302#include "itkFancyString.h"
303
304#endif // itkDOMNode_h
Class to represent a node in a Document Object Model (DOM) tree structure.
Definition: itkDOMNode.h:54
std::map< AttributeKeyType, AttributeValueType > AttributesContainer
Definition: itkDOMNode.h:289
std::vector< const DOMNode * > ConstChildrenListType
Definition: itkDOMNode.h:72
virtual void GetAllChildren(ConstChildrenListType &output) const
virtual std::string GetPath() const
virtual bool ShareRoot(const DOMNode *node) const
virtual void RemoveAllChildren()
DOMNode * GetParent()
virtual DOMNode * GetChild(const std::string &tag, IdentifierType i=0)
virtual void AddChild(DOMNode *node, IdentifierType i=0)
virtual const DOMNode * GetChild(const std::string &tag, IdentifierType i=0) const
virtual void SetAttribute(const std::string &key, const std::string &value)
virtual void RemoveAllAttributesAndChildren()
virtual void SetParent(DOMNode *node)
virtual bool HasAttribute(const std::string &key) const
virtual const DOMNode * GetChildByID(const std::string &value) const
virtual void SetChild(DOMNode *node, IdentifierType i=0)
virtual DOMTextNode * GetTextChild(IdentifierType i=0)
const DOMNode * GetParent() const
virtual void AddTextChild(const std::string &text, IdentifierType i=0)
virtual std::string GetAttribute(const std::string &key) const
virtual SizeType GetNumberOfChildren() const
std::vector< DOMNode * > ChildrenListType
Definition: itkDOMNode.h:71
virtual void GetAllAttributes(AttributesListType &output, bool keepOriginalOrder=true) const
virtual void GetAllChildren(ChildrenListType &output)
virtual DOMNode * GetChildByID(const std::string &value)
virtual void SetTextChild(const std::string &text, IdentifierType i=0)
virtual void GetChildren(const std::string &tag, ChildrenListType &output)
virtual const DOMTextNode * GetTextChild(IdentifierType i=0) const
virtual void AddChildAtBegin(DOMNode *node)
virtual void RemoveChild(IdentifierType i=0)
virtual const DOMNode * GetSibling(OffsetType i) const
virtual void AddTextChildAtBegin(const std::string &text)
virtual void GetChildren(const std::string &tag, ConstChildrenListType &output) const
std::pair< const AttributeKeyType, AttributeValueType > AttributeItemType
Definition: itkDOMNode.h:78
std::list< AttributeItemType > AttributesListType
Definition: itkDOMNode.h:81
virtual void RemoveAttribute(const std::string &key)
virtual DOMNode * GetChild(IdentifierType i=0)
std::list< AttributeItemType * > OrderedAttributesContainer
Definition: itkDOMNode.h:293
std::string AttributeKeyType
Definition: itkDOMNode.h:75
std::string AttributeValueType
Definition: itkDOMNode.h:76
virtual void AddTextChildAtEnd(const std::string &text)
virtual const DOMNode * GetRoot() const
std::vector< Pointer > ChildrenContainer
Definition: itkDOMNode.h:285
int OffsetType
Definition: itkDOMNode.h:85
virtual DOMNode * GetSibling(OffsetType i)
virtual const DOMNode * Find(const std::string &path) const
virtual DOMNode * Find(const std::string &path)
virtual void AddChildAtEnd(DOMNode *node)
int IdentifierType
Definition: itkDOMNode.h:84
virtual void RemoveAllAttributes()
vcl_size_t SizeType
Definition: itkDOMNode.h:83
virtual DOMNode * GetRoot()
virtual const DOMNode * GetChild(IdentifierType i=0) const
Class to represent a special DOM node that holds a text string.
Light weight base class for most itk classes.
Base class for most ITK classes.
Definition: itkObject.h:62
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....