ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkTreeNode.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 #ifndef itkTreeNode_h
19 #define itkTreeNode_h
20 
21 #include <vector>
22 #include <algorithm>
23 #include <iostream>
24 #include "itkObject.h"
25 #include "itkObjectFactory.h"
26 #include "itkIntTypes.h"
27 
28 namespace itk
29 {
42 template< typename TValue >
43 class ITK_TEMPLATE_EXPORT TreeNode:public Object
44 {
45 public:
46  ITK_DISALLOW_COPY_AND_ASSIGN(TreeNode);
47 
49  using Superclass = Object;
53  using ChildrenListType = std::vector< Pointer >;
55 
57  itkNewMacro(Self);
58 
60  itkTypeMacro(TreeNode, Object);
61 
63  const TValue & Get() const;
64 
66  TValue Set(const TValue data);
67 
69  Self * GetChild(ChildIdentifier number) const;
70 
72  Self * GetParent() const;
73 
75  bool HasChildren() const;
76 
78  bool HasParent() const;
79 
81  void SetParent(Self *n);
82 
84  ChildIdentifier CountChildren() const;
85 
87  bool Remove(Self *n);
88 
90  ChildIdentifier GetNumberOfChildren(unsigned int depth = 0, char *name = nullptr) const;
91 
93  bool ReplaceChild(Self *oldChild, Self *newChild);
94 
96  ChildIdentifier ChildPosition(const Self *node) const;
97 
99  ChildIdentifier ChildPosition(TValue node) const;
100 
102  void AddChild(Self *node);
103 
105  virtual void AddChild(ChildIdentifier number, Self *node);
106 
108 #if !defined( ITK_WRAPPING_PARSER )
109  virtual ChildrenListType * GetChildren(unsigned int depth = 0, char *name = nullptr) const;
110 
111 #endif
112 
114 #if !defined( ITK_WRAPPING_PARSER )
115  virtual ChildrenListType & GetChildrenList() { return m_Children; }
116 #endif
117 
119  //virtual void SetData(TValue data) {m_Data = data;}
120 
121 protected:
122 
123  TreeNode() = default;
124  ~TreeNode() override;
125 
126  TValue m_Data;
127  Self *m_Parent{nullptr};
128 
130 };
131 } // end namespace itk
132 
133 #ifndef ITK_MANUAL_INSTANTIATION
134 #include "itkTreeNode.hxx"
135 #endif
136 
137 #endif
Light weight base class for most itk classes.
Represents a node in a tree.
Definition: itkTreeNode.h:43
::itk::OffsetValueType ChildIdentifier
Definition: itkTreeNode.h:54
std::vector< Pointer > ChildrenListType
Definition: itkTreeNode.h:53
virtual ChildrenListType & GetChildrenList()
Definition: itkTreeNode.h:115
ChildrenListType m_Children
Definition: itkTreeNode.h:129
Base class for most ITK classes.
Definition: itkObject.h:60
signed long OffsetValueType
Definition: itkIntTypes.h:94