ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkTreeNode.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 __itkTreeNode_h
00019 #define __itkTreeNode_h
00020 
00021 #include <vector>
00022 #include <algorithm>
00023 #include <iostream>
00024 #include "itkObject.h"
00025 #include "itkObjectFactory.h"
00026 #include "itkIntTypes.h"
00027 
00028 namespace itk
00029 {
00042 template< class TValueType >
00043 class TreeNode:public Object
00044 {
00045 public:
00046 
00048   typedef Object                     Superclass;
00049   typedef TreeNode< TValueType >     Self;
00050   typedef SmartPointer< Self >       Pointer;
00051   typedef SmartPointer< const Self > ConstPointer;
00052   typedef std::vector< Pointer >     ChildrenListType;
00053   typedef ::itk::OffsetValueType     ChildIdentifier;
00054 
00056   itkNewMacro(Self);
00057 
00059   itkTypeMacro(TreeNode, Object);
00060 
00062   const TValueType & Get() const;
00063 
00065   TValueType Set(const TValueType data);
00066 
00068   TreeNode< TValueType > * GetChild(ChildIdentifier number) const;
00069 
00071   TreeNode< TValueType > * GetParent() const;
00072 
00074   bool HasChildren() const;
00075 
00077   bool HasParent() const;
00078 
00080   void SetParent(TreeNode< TValueType > *n);
00081 
00083   ChildIdentifier CountChildren() const;
00084 
00086   bool Remove(TreeNode< TValueType > *n);
00087 
00089   ChildIdentifier GetNumberOfChildren(unsigned int depth = 0, char *name = NULL) const;
00090 
00092   bool ReplaceChild(TreeNode< TValueType > *oldChild, TreeNode< TValueType > *newChild);
00093 
00095   ChildIdentifier ChildPosition(const TreeNode< TValueType > *node) const;
00096 
00098   ChildIdentifier ChildPosition(TValueType node) const;
00099 
00101   void AddChild(TreeNode< TValueType > *node);
00102 
00104   virtual void AddChild(ChildIdentifier number, TreeNode< TValueType > *node);
00105 
00107 #if !defined( CABLE_CONFIGURATION )
00108   virtual ChildrenListType * GetChildren(unsigned int depth = 0, char *name = NULL) const;
00109 
00110 #endif
00111 
00113 #if !defined( CABLE_CONFIGURATION )
00114   virtual ChildrenListType & GetChildrenList() { return m_Children; }
00115 #endif
00116 
00118   //virtual void SetData(TValueType data) {m_Data = data;}
00119 protected:
00120 
00121   TreeNode();
00122   virtual ~TreeNode();
00123   TValueType m_Data;
00124 
00125   Self *m_Parent;
00126 
00127   ChildrenListType m_Children;
00128 private:
00129   TreeNode(const Self &);       //purposely not implemented
00130   void operator=(const Self &); //purposely not implemented
00131 };
00132 } // end namespace itk
00133 
00134 // Define instantiation macro for this template.
00135 #define ITK_TEMPLATE_TreeNode(_, EXPORT, TypeX, TypeY)     \
00136   namespace itk                                            \
00137   {                                                        \
00138   _( 1 ( class EXPORT TreeNode< ITK_TEMPLATE_1 TypeX > ) ) \
00139   namespace Templates                                      \
00140   {                                                        \
00141   typedef TreeNode< ITK_TEMPLATE_1 TypeX >                 \
00142   TreeNode##TypeY;                                       \
00143   }                                                        \
00144   }
00145 
00146 #if ITK_TEMPLATE_EXPLICIT
00147 #include "Templates/itkTreeNode+-.h"
00148 #endif
00149 
00150 #if ITK_TEMPLATE_TXX
00151 #include "itkTreeNode.hxx"
00152 #endif
00153 
00154 #endif
00155