ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkDOMNode.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 
31 namespace itk
32 {
33 
34 class DOMTextNode; // forward declaration
35 
53 class ITKIOXML_EXPORT DOMNode : public Object
54 {
55 public:
56  ITK_DISALLOW_COPY_AND_ASSIGN(DOMNode);
57 
59  using Self = DOMNode;
60  using Superclass = Object;
63 
65  itkNewMacro(Self);
66 
68  itkTypeMacro(DOMNode, Object);
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 = std::size_t;
84  using IdentifierType = int;
85  using OffsetType = int;
86 
88  virtual void SetParent( DOMNode* node );
89  DOMNode* GetParent();
90  const DOMNode* GetParent() const;
92 
94  itkSetMacro( Name, std::string& );
95  itkGetConstReferenceMacro( Name, std::string );
97 
99  itkSetMacro( ID, std::string& );
100  itkGetConstReferenceMacro( ID, std::string );
102 
104  virtual std::string GetAttribute( const std::string& key ) const;
105 
107  virtual bool HasAttribute( const std::string& key ) const;
108 
110  virtual void SetAttribute( const std::string& key, const std::string& value );
111 
113  virtual void RemoveAttribute( const std::string& key );
114 
119  virtual void GetAllAttributes( AttributesListType& output, bool keepOriginalOrder = true ) const;
120 
122  virtual void RemoveAllAttributes();
123 
125  virtual SizeType GetNumberOfChildren() const;
126 
128  virtual void GetAllChildren( ChildrenListType& output );
129 
131  virtual void GetAllChildren( ConstChildrenListType& output ) const;
132 
134  virtual void GetChildren( const std::string& tag, ChildrenListType& output );
135 
137  virtual void GetChildren( const std::string& tag, ConstChildrenListType& output ) const;
138 
140  virtual void RemoveAllChildren();
141 
143  virtual void AddChild( DOMNode* node, IdentifierType i=0 );
144 
146  virtual void AddChildAtBegin( DOMNode* node );
147 
149  virtual void AddChildAtEnd( DOMNode* node );
150 
152  virtual void SetChild( DOMNode* node, IdentifierType i=0 );
153 
155  virtual void RemoveChild( IdentifierType i=0 );
156 
158  virtual void RemoveAllAttributesAndChildren();
159 
161  virtual DOMNode* GetChild( IdentifierType i=0 );
162  virtual const DOMNode* GetChild( IdentifierType i=0 ) const;
164 
166  virtual DOMNode* GetChild( const std::string& tag, IdentifierType i=0 );
167  virtual const DOMNode* GetChild( const std::string& tag, IdentifierType i=0 ) const;
169 
171  virtual DOMNode* GetChildByID( const std::string& value );
172  virtual const DOMNode* GetChildByID( const std::string& value ) const;
174 
176  virtual DOMNode* GetSibling( OffsetType i );
177  virtual const DOMNode* GetSibling( OffsetType i ) const;
179 
181  virtual DOMNode* GetRoot();
182  virtual const DOMNode* GetRoot() const;
184 
186  virtual bool ShareRoot( const DOMNode* node ) const;
187 
205  virtual DOMNode* Find( const std::string& path );
206  virtual const DOMNode* Find( const std::string& path ) const;
208 
210  virtual std::string GetPath() const;
211 
213  virtual DOMTextNode* GetTextChild( IdentifierType i=0 );
214  virtual const DOMTextNode* GetTextChild( IdentifierType i=0 ) const;
216 
218  virtual void AddTextChild( const std::string& text, IdentifierType i=0 );
219 
221  virtual void AddTextChildAtBegin( const std::string& text );
222 
224  virtual void AddTextChildAtEnd( const std::string& text );
225 
227  virtual void SetTextChild( const std::string& text, IdentifierType i=0 );
228 
229 protected:
230  DOMNode();
231 
232 private:
234  DOMNode* m_Parent{ nullptr };
235 
237  std::string m_Name;
238 
240  std::string m_ID;
241 
243  using ChildrenContainer = std::vector<Pointer>;
245 
247  using AttributesContainer = std::map<AttributeKeyType,AttributeValueType>;
249 
251  using OrderedAttributesContainer = std::list<AttributeItemType*>;
253 
254 };
255 
256 } // namespace itk
257 
258 #include "itkDOMTextNode.h"
259 
260 #include "itkStringTools.h"
261 #include "itkFancyString.h"
262 
263 #endif // itkDOMNode_h
ChildrenContainer m_Children
Definition: itkDOMNode.h:244
std::string AttributeKeyType
Definition: itkDOMNode.h:75
Light weight base class for most itk classes.
int IdentifierType
Definition: itkDOMNode.h:84
OrderedAttributesContainer m_OrderedAttributes
Definition: itkDOMNode.h:252
Class to represent a special DOM node that holds a text string.
std::map< AttributeKeyType, AttributeValueType > AttributesContainer
Definition: itkDOMNode.h:247
std::list< AttributeItemType > AttributesListType
Definition: itkDOMNode.h:81
Class to represent a node in a Document Object Model (DOM) tree structure.
Definition: itkDOMNode.h:53
std::pair< const AttributeKeyType, AttributeValueType > AttributeItemType
Definition: itkDOMNode.h:78
std::string m_ID
Definition: itkDOMNode.h:240
std::vector< const DOMNode * > ConstChildrenListType
Definition: itkDOMNode.h:72
std::vector< Pointer > ChildrenContainer
Definition: itkDOMNode.h:243
int OffsetType
Definition: itkDOMNode.h:85
std::vector< DOMNode * > ChildrenListType
Definition: itkDOMNode.h:71
std::string m_Name
Definition: itkDOMNode.h:237
std::string AttributeValueType
Definition: itkDOMNode.h:76
Base class for most ITK classes.
Definition: itkObject.h:60
std::list< AttributeItemType * > OrderedAttributesContainer
Definition: itkDOMNode.h:251
std::vcl_size_t SizeType
Definition: itkDOMNode.h:83
AttributesContainer m_Attributes
Definition: itkDOMNode.h:248