ITK  4.13.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 
58  typedef DOMNode Self;
59  typedef Object Superclass;
62 
64  itkNewMacro(Self);
65 
67  itkTypeMacro(DOMNode, Object);
68 
70  typedef std::vector<DOMNode*> ChildrenListType;
71  typedef std::vector<const DOMNode*> ConstChildrenListType;
72 
74  typedef std::string AttributeKeyType;
75  typedef std::string AttributeValueType;
76 
77  typedef std::pair<const AttributeKeyType,AttributeValueType> AttributeItemType;
78 
80  typedef std::list<AttributeItemType> AttributesListType;
81 
82  typedef std::size_t SizeType;
83  typedef int IdentifierType;
84  typedef int OffsetType;
85 
87  virtual void SetParent( DOMNode* node );
88  DOMNode* GetParent();
89  const DOMNode* GetParent() const;
91 
93  itkSetMacro( Name, std::string& );
94  itkGetConstReferenceMacro( Name, std::string );
96 
98  itkSetMacro( ID, std::string& );
99  itkGetConstReferenceMacro( ID, std::string );
101 
103  virtual std::string GetAttribute( const std::string& key ) const;
104 
106  virtual bool HasAttribute( const std::string& key ) const;
107 
109  virtual void SetAttribute( const std::string& key, const std::string& value );
110 
112  virtual void RemoveAttribute( const std::string& key );
113 
118  virtual void GetAllAttributes( AttributesListType& output, bool keepOriginalOrder = true ) const;
119 
121  virtual void RemoveAllAttributes();
122 
124  virtual SizeType GetNumberOfChildren() const;
125 
127  virtual void GetAllChildren( ChildrenListType& output );
128 
130  virtual void GetAllChildren( ConstChildrenListType& output ) const;
131 
133  virtual void GetChildren( const std::string& tag, ChildrenListType& output );
134 
136  virtual void GetChildren( const std::string& tag, ConstChildrenListType& output ) const;
137 
139  virtual void RemoveAllChildren();
140 
142  virtual void AddChild( DOMNode* node, IdentifierType i=0 );
143 
145  virtual void AddChildAtBegin( DOMNode* node );
146 
148  virtual void AddChildAtEnd( DOMNode* node );
149 
151  virtual void SetChild( DOMNode* node, IdentifierType i=0 );
152 
154  virtual void RemoveChild( IdentifierType i=0 );
155 
157  virtual void RemoveAllAttributesAndChildren();
158 
160  virtual DOMNode* GetChild( IdentifierType i=0 );
161  virtual const DOMNode* GetChild( IdentifierType i=0 ) const;
163 
165  virtual DOMNode* GetChild( const std::string& tag, IdentifierType i=0 );
166  virtual const DOMNode* GetChild( const std::string& tag, IdentifierType i=0 ) const;
168 
170  virtual DOMNode* GetChildByID( const std::string& value );
171  virtual const DOMNode* GetChildByID( const std::string& value ) const;
173 
175  virtual DOMNode* GetSibling( OffsetType i );
176  virtual const DOMNode* GetSibling( OffsetType i ) const;
178 
180  virtual DOMNode* GetRoot();
181  virtual const DOMNode* GetRoot() const;
183 
185  virtual bool ShareRoot( const DOMNode* node ) const;
186 
204  virtual DOMNode* Find( const std::string& path );
205  virtual const DOMNode* Find( const std::string& path ) const;
207 
209  virtual std::string GetPath() const;
210 
212  virtual DOMTextNode* GetTextChild( IdentifierType i=0 );
213  virtual const DOMTextNode* GetTextChild( IdentifierType i=0 ) const;
215 
217  virtual void AddTextChild( const std::string& text, IdentifierType i=0 );
218 
220  virtual void AddTextChildAtBegin( const std::string& text );
221 
223  virtual void AddTextChildAtEnd( const std::string& text );
224 
226  virtual void SetTextChild( const std::string& text, IdentifierType i=0 );
227 
228 protected:
229  DOMNode();
230 
231 private:
234 
236  std::string m_Name;
237 
239  std::string m_ID;
240 
242  typedef std::vector<Pointer> ChildrenContainer;
244 
246  typedef std::map<AttributeKeyType,AttributeValueType> AttributesContainer;
248 
250  typedef std::list<AttributeItemType*> OrderedAttributesContainer;
252 
253  ITK_DISALLOW_COPY_AND_ASSIGN(DOMNode);
254 };
255 
256 } // namespace itk
257 
258 #include "itkDOMTextNode.h"
259 
260 #include "itkStringTools.h"
261 #include "itkFancyString.h"
262 
263 #endif // itkDOMNode_h
std::map< AttributeKeyType, AttributeValueType > AttributesContainer
Definition: itkDOMNode.h:246
std::vcl_size_t SizeType
Definition: itkDOMNode.h:82
ChildrenContainer m_Children
Definition: itkDOMNode.h:243
SmartPointer< const Self > ConstPointer
Definition: itkDOMNode.h:61
Light weight base class for most itk classes.
OrderedAttributesContainer m_OrderedAttributes
Definition: itkDOMNode.h:251
Class to represent a special DOM node that holds a text string.
Class to represent a node in a Document Object Model (DOM) tree structure.
Definition: itkDOMNode.h:53
std::vector< const DOMNode * > ConstChildrenListType
Definition: itkDOMNode.h:71
Object Superclass
Definition: itkDOMNode.h:59
int OffsetType
Definition: itkDOMNode.h:84
std::string AttributeValueType
Definition: itkDOMNode.h:75
std::list< AttributeItemType * > OrderedAttributesContainer
Definition: itkDOMNode.h:250
std::string m_ID
Definition: itkDOMNode.h:239
std::pair< const AttributeKeyType, AttributeValueType > AttributeItemType
Definition: itkDOMNode.h:77
std::vector< DOMNode * > ChildrenListType
Definition: itkDOMNode.h:67
std::vector< Pointer > ChildrenContainer
Definition: itkDOMNode.h:242
SmartPointer< Self > Pointer
Definition: itkDOMNode.h:60
DOMNode * m_Parent
Definition: itkDOMNode.h:233
DOMNode Self
Definition: itkDOMNode.h:58
std::string m_Name
Definition: itkDOMNode.h:236
std::list< AttributeItemType > AttributesListType
Definition: itkDOMNode.h:80
Base class for most ITK classes.
Definition: itkObject.h:59
std::string AttributeKeyType
Definition: itkDOMNode.h:74
AttributesContainer m_Attributes
Definition: itkDOMNode.h:247
int IdentifierType
Definition: itkDOMNode.h:83