ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkTreeContainer.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkTreeContainer_h
00019 #define __itkTreeContainer_h
00020 
00021 #include "itkTreeContainerBase.h"
00022 #include "itkPreOrderTreeIterator.h"
00023 
00024 namespace itk
00025 {
00037 template< class TValueType >
00038 class TreeContainer:public TreeContainerBase< TValueType >
00039 {
00040 public:
00041 
00043   typedef TreeContainerBase< TValueType > Superclass;
00044   typedef TreeContainer< TValueType >     Self;
00045   typedef SmartPointer< Self >            Pointer;
00046   typedef SmartPointer< const Self >      ConstPointer;
00047   typedef TValueType                      ValueType;
00048   typedef TreeNode< ValueType >           TreeNodeType;
00049 
00051   typedef TreeIteratorBase< Self >     IteratorType;
00052   typedef PreOrderTreeIterator< Self > PreOrderIteratorType;
00053 
00055   itkNewMacro(Self);
00056 
00058   itkTypeMacro(TreeContainer, TreeContainerBase);
00059 
00061   TreeContainer(int defaultChildrenCount);
00062 
00064   TreeContainer(TreeContainer< TValueType > & tree);
00065 
00067   virtual bool SetRoot(const TValueType element);
00068 
00070   bool SetRoot(IteratorType & pos);
00071 
00073   virtual bool SetRoot(TreeNode< TValueType > *node);
00074 
00076   bool Contains(const TValueType element);
00077 
00079   int Count() const;
00080 
00082   bool IsLeaf(const TValueType element);
00083 
00085   bool IsRoot(const TValueType element);
00086 
00088   bool Clear();
00089 
00091   bool operator==(TreeContainer< TValueType > & tree);
00092 
00094   bool Swap(IteratorType & v, IteratorType & w);
00095 
00097   const TreeNodeType * GetRoot() const { return m_Root.GetPointer(); }
00098 
00100   bool Add(const TValueType child, const TValueType parent);
00101 
00103   const TreeNodeType * GetNode(TValueType val) const;
00104 
00105 protected:
00106 
00107   TreeContainer();
00108   virtual ~TreeContainer();
00109 
00110   typename TreeNodeType::Pointer m_Root;
00111 
00112   int m_DefaultChildrenCount;
00113 
00114   void PrintSelf(std::ostream & os, Indent indent) const;
00115 };
00116 } // namespace itk
00117 
00118 // Define instantiation macro for this template.
00119 #define ITK_TEMPLATE_TreeContainer(_, EXPORT, TypeX, TypeY)     \
00120   namespace itk                                                 \
00121   {                                                             \
00122   _( 1 ( class EXPORT TreeContainer< ITK_TEMPLATE_1 TypeX > ) ) \
00123   namespace Templates                                           \
00124   {                                                             \
00125   typedef TreeContainer< ITK_TEMPLATE_1 TypeX >                 \
00126   TreeContainer##TypeY;                                       \
00127   }                                                             \
00128   }
00129 
00130 #if ITK_TEMPLATE_EXPLICIT
00131 #include "Templates/itkTreeContainer+-.h"
00132 #endif
00133 
00134 #if ITK_TEMPLATE_TXX
00135 #include "itkTreeContainer.hxx"
00136 #endif
00137 
00138 #endif
00139