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 itkTreeContainerBase_h 19 #define itkTreeContainerBase_h 20 21 #include "itkMacro.h" 22 #include <iostream> 23 #include "itkTreeNode.h" 24 25 namespace itk 26 { 27 /** \class TreeContainerBase 28 * \brief A base class for tree containers. 29 * 30 * \ingroup DataRepresentation 31 * \ingroup ITKCommon 32 */ 33 template< typename TValue > 34 class TreeContainerBase:public Object 35 { 36 public: 37 38 using Superclass = Object; 39 using Self = TreeContainerBase; 40 using Pointer = SmartPointer< Self >; 41 using ConstPointer = SmartPointer< const Self >; 42 43 using ValueType = TValue; 44 45 /** Run-time type information (and related methods). */ 46 itkTypeMacro(TreeContainerBase, Object); 47 48 /** Set the root element. 49 * A new node is created and the element is added to the node */ 50 virtual bool SetRoot(const TValue element) = 0; 51 52 /** Set the root has a node */ 53 virtual bool SetRoot(TreeNode< TValue > *node) = 0; 54 55 /** Return true if the tree contains the element */ 56 virtual bool Contains(const TValue element) = 0; 57 58 /** Return the number of nodes in the tree */ 59 virtual int Count() const = 0; 60 61 /** Return if the element is a leaf */ 62 virtual bool IsLeaf(const TValue element) = 0; 63 64 /** Return if the element is root */ 65 virtual bool IsRoot(const TValue element) = 0; 66 67 /** Clear the tree */ 68 virtual bool Clear() = 0; 69 70 /** Get the root as a node */ 71 virtual const TreeNode< TValue > * GetRoot() const = 0; 72 73 /** Set if the tree is a subtree */ SetSubtree(bool val)74 void SetSubtree(bool val) { m_SubTree = val; } 75 76 protected: 77 TreeContainerBase()78 TreeContainerBase() {} 79 ~TreeContainerBase() override = default; 80 bool m_SubTree{false}; 81 }; 82 } // namespace itk 83 84 #endif 85