ITK  4.4.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 
25 #include <string>
26 #include <vector>
27 #include <list>
28 #include <map>
29 
30 namespace itk
31 {
32 
33 class DOMTextNode; // forward declaration
34 
52 class DOMNode : public Object
53 {
54 public:
55 
57  typedef DOMNode Self;
58  typedef Object Superclass;
61 
63  itkNewMacro(Self);
64 
66  itkTypeMacro(DOMNode, Object);
67 
69  typedef std::vector<DOMNode*> ChildrenListType;
70  typedef std::vector<const DOMNode*> ConstChildrenListType;
71 
73  typedef std::string AttributeKeyType;
74  typedef std::string AttributeValueType;
75 
76  typedef std::pair<const AttributeKeyType,AttributeValueType> AttributeItemType;
77 
79  typedef std::list<AttributeItemType> AttributesListType;
80 
81  typedef std::size_t SizeType;
82  typedef int IdentifierType;
83  typedef int OffsetType;
84 
86  virtual void SetParent( DOMNode* node );
87  DOMNode* GetParent();
88  const DOMNode* GetParent() const;
90 
92  itkSetMacro( Name, std::string& );
93  itkGetConstReferenceMacro( Name, std::string );
95 
97  itkSetMacro( ID, std::string& );
98  itkGetConstReferenceMacro( ID, std::string );
100 
102  virtual std::string GetAttribute( const std::string& key ) const;
103 
105  virtual bool HasAttribute( const std::string& key ) const;
106 
108  virtual void SetAttribute( const std::string& key, const std::string& value );
109 
111  virtual void RemoveAttribute( const std::string& key );
112 
117  virtual void GetAllAttributes( AttributesListType& output, bool keepOriginalOrder = true ) const;
118 
120  virtual void RemoveAllAttributes();
121 
123  virtual SizeType GetNumberOfChildren() const;
124 
126  virtual void GetAllChildren( ChildrenListType& output );
127 
129  virtual void GetAllChildren( ConstChildrenListType& output ) const;
130 
132  virtual void GetChildren( const std::string& tag, ChildrenListType& output );
133 
135  virtual void GetChildren( const std::string& tag, ConstChildrenListType& output ) const;
136 
138  virtual void RemoveAllChildren();
139 
141  virtual void AddChild( DOMNode* node, IdentifierType i=0 );
142 
144  virtual void AddChildAtBegin( DOMNode* node );
145 
147  virtual void AddChildAtEnd( DOMNode* node );
148 
150  virtual void SetChild( DOMNode* node, IdentifierType i=0 );
151 
153  virtual void RemoveChild( IdentifierType i=0 );
154 
156  virtual void RemoveAllAttributesAndChildren();
157 
159  virtual DOMNode* GetChild( IdentifierType i=0 );
160  virtual const DOMNode* GetChild( IdentifierType i=0 ) const;
162 
164  virtual DOMNode* GetChild( const std::string& tag, IdentifierType i=0 );
165  virtual const DOMNode* GetChild( const std::string& tag, IdentifierType i=0 ) const;
167 
169  virtual DOMNode* GetChildByID( const std::string& value );
170  virtual const DOMNode* GetChildByID( const std::string& value ) const;
172 
174  virtual DOMNode* GetSibling( OffsetType i );
175  virtual const DOMNode* GetSibling( OffsetType i ) const;
177 
179  virtual DOMNode* GetRoot();
180  virtual const DOMNode* GetRoot() const;
182 
184  virtual bool ShareRoot( const DOMNode* node ) const;
185 
203  virtual DOMNode* Find( const std::string& path );
204  virtual const DOMNode* Find( const std::string& path ) const;
206 
208  virtual std::string GetPath() const;
209 
211  virtual DOMTextNode* GetTextChild( IdentifierType i=0 );
212  virtual const DOMTextNode* GetTextChild( IdentifierType i=0 ) const;
214 
216  virtual void AddTextChild( const std::string& text, IdentifierType i=0 );
217 
219  virtual void AddTextChildAtBegin( const std::string& text );
220 
222  virtual void AddTextChildAtEnd( const std::string& text );
223 
225  virtual void SetTextChild( const std::string& text, IdentifierType i=0 );
226 
227 protected:
228  DOMNode();
229 
230 private:
233 
235  std::string m_Name;
236 
238  std::string m_ID;
239 
241  typedef std::vector<Pointer> ChildrenContainer;
243 
245  typedef std::map<AttributeKeyType,AttributeValueType> AttributesContainer;
247 
249  typedef std::list<AttributeItemType*> OrderedAttributesContainer;
251 
252  DOMNode(const Self &); //purposely not implemented
253  void operator=(const Self &); //purposely not implemented
254 };
255 
256 } // namespace itk
257 
258 #include "itkDOMTextNode.h"
259 
260 #include "itkStringTools.h"
261 #include "itkFancyString.h"
262 
263 #endif // __itkDOMNode_h
264