ITK  5.1.0
Insight 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 &
64  Get() const;
65 
67  TValue
68  Set(const TValue data);
69 
71  Self *
72  GetChild(ChildIdentifier number) const;
73 
75  Self *
76  GetParent() const;
77 
79  bool
80  HasChildren() const;
81 
83  bool
84  HasParent() const;
85 
87  void
88  SetParent(Self * n);
89 
92  CountChildren() const;
93 
95  bool
96  Remove(Self * n);
97 
100  GetNumberOfChildren(unsigned int depth = 0, char * name = nullptr) const;
101 
103  bool
104  ReplaceChild(Self * oldChild, Self * newChild);
105 
108  ChildPosition(const Self * node) const;
109 
112  ChildPosition(TValue node) const;
113 
115  void
116  AddChild(Self * node);
117 
119  virtual void
120  AddChild(ChildIdentifier number, Self * node);
121 
123 #if !defined(ITK_WRAPPING_PARSER)
124  virtual ChildrenListType *
125  GetChildren(unsigned int depth = 0, char * name = nullptr) const;
126 
127 #endif
128 
130 #if !defined(ITK_WRAPPING_PARSER)
131  virtual ChildrenListType &
133  {
134  return m_Children;
135  }
136 #endif
137 
139  // virtual void SetData(TValue data) {m_Data = data;}
140 
141 protected:
142  TreeNode() = default;
143  ~TreeNode() override;
144 
145  TValue m_Data;
146  Self * m_Parent{ nullptr };
147 
149 };
150 } // end namespace itk
151 
152 #ifndef ITK_MANUAL_INSTANTIATION
153 # include "itkTreeNode.hxx"
154 #endif
155 
156 #endif
itk::TreeNode
Represents a node in a tree.
Definition: itkTreeNode.h:43
itkObjectFactory.h
itk::TreeNode::ChildIdentifier
::itk::OffsetValueType ChildIdentifier
Definition: itkTreeNode.h:54
itk::SmartPointer< Self >
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::TreeNode::ChildrenListType
std::vector< Pointer > ChildrenListType
Definition: itkTreeNode.h:53
itk::TreeNode::GetChildrenList
virtual ChildrenListType & GetChildrenList()
Definition: itkTreeNode.h:132
itkIntTypes.h
itkObject.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::OffsetValueType
signed long OffsetValueType
Definition: itkIntTypes.h:94
itk::TreeNode::m_Data
TValue m_Data
Definition: itkTreeNode.h:145
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:60
itk::TreeNode::m_Children
ChildrenListType m_Children
Definition: itkTreeNode.h:148