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 itkChildTreeIterator_h
19 #define itkChildTreeIterator_h
20 
21 #include "itkTreeIteratorBase.h"
22 
23 namespace itk
24 {
25 template< typename TTreeType >
26 class ITK_TEMPLATE_EXPORT ChildTreeIterator:public TreeIteratorBase< TTreeType >
27 {
28 public:
29 
30   /** Typedefs */
31   using Self = ChildTreeIterator;
32   using Superclass = TreeIteratorBase< TTreeType >;
33   using TreeType = TTreeType;
34   using ValueType = typename TTreeType::ValueType;
35   using TreeNodeType = typename Superclass::TreeNodeType;
36   using ChildIdentifier = typename TreeNodeType::ChildIdentifier;
37   using NodeType = typename Superclass::NodeType;
38 
39   /** Constructor */
40   ChildTreeIterator(TreeType *tree, const TreeNodeType *start = nullptr);
41 
42   /** Constructor */
43   ChildTreeIterator(const TreeIteratorBase< TTreeType > & iterator);
44 
45   /** Get the type of the iterator */
46   NodeType GetType() const override;
47 
48   /** Go to a specific child node */
49   bool GoToChild(ChildIdentifier number = 0) override;
50 
51   /** Go to a parent node */
52   bool GoToParent() override;
53 
54   /** Clone function */
55   TreeIteratorBase< TTreeType > * Clone() override;
56 
57   /** operator = */
58   Self & operator=(Superclass & iterator)
59   {
60     if(this != &iterator)
61       {
62       Superclass::operator=(iterator);
63       auto & it = static_cast< ChildTreeIterator< TTreeType > & >( iterator );
64       m_ListPosition = it.m_ListPosition;
65       m_ParentNode = it.m_ParentNode;
66       }
67     return *this;
68   }
69 
70 protected:
71 
72   /** Get the next value */
73   const ValueType & Next() override;
74 
75   /** Return true if the next value exists */
76   bool HasNext() const override;
77 
78 private:
79 
80   mutable ChildIdentifier  m_ListPosition;
81   TreeNodeType *           m_ParentNode;
82 };
83 
84 } // end namespace itk
85 
86 #ifndef ITK_MANUAL_INSTANTIATION
87 #include "itkChildTreeIterator.hxx"
88 #endif
89 
90 #endif
91