00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkTreeNode.h,v $ 00005 Language: C++ 00006 Date: $Date: 2005/01/21 20:13:31 $ 00007 Version: $Revision: 1.6 $ 00008 00009 Copyright (c) Insight Software Consortium. All rights reserved. 00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 #ifndef __itkTreeNode_h 00018 #define __itkTreeNode_h 00019 00020 #include <vector> 00021 #include <algorithm> 00022 #include <iostream> 00023 #include <itkObject.h> 00024 00025 namespace itk 00026 { 00040 template <class TValueType> 00041 class TreeNode : public Object 00042 { 00043 00044 public: 00045 00047 typedef Object Superclass; 00048 typedef TreeNode<TValueType> Self; 00049 typedef SmartPointer<Self> Pointer; 00050 typedef SmartPointer<const Self> ConstPointer; 00051 typedef std::vector<Pointer> ChildrenListType; 00052 00054 itkNewMacro( Self ); 00055 00057 itkTypeMacro( TreeNode, Object ); 00058 00060 const TValueType& Get() const; 00061 00063 TValueType Set(const TValueType data); 00064 00066 TreeNode<TValueType>* GetChild( int number ) const; 00067 00069 TreeNode<TValueType>* GetParent( ) const; 00070 00072 bool HasChildren( ) const; 00073 00075 bool HasParent( ) const; 00076 00078 void SetParent( TreeNode<TValueType>* n ); 00079 00081 int CountChildren( ) const; 00082 00084 bool Remove( TreeNode<TValueType> *n ); 00085 00087 unsigned int GetNumberOfChildren(unsigned int depth=0, char * name=NULL ) const; 00088 00090 bool ReplaceChild( TreeNode<TValueType> *oldChild, TreeNode<TValueType> *newChild ); 00091 00093 int ChildPosition( const TreeNode<TValueType> *node ) const; 00095 int ChildPosition( TValueType node ) const; 00096 00098 void AddChild( TreeNode<TValueType> *node ); 00099 00101 virtual void AddChild( int number, TreeNode<TValueType> *node ); 00102 00104 virtual ChildrenListType* GetChildren( unsigned int depth=0, char * name=NULL) const; 00105 00107 virtual ChildrenListType& GetChildrenList() {return m_Children;} 00108 00110 //virtual void SetData(TValueType data) {m_Data = data;} 00111 00112 protected: 00113 00114 TreeNode(); 00115 virtual ~TreeNode(); 00116 TValueType m_Data; 00117 Self* m_Parent; 00118 ChildrenListType m_Children; 00119 private: 00120 TreeNode(const Self&); //purposely not implemented 00121 void operator=(const Self&); //purposely not implemented 00122 }; 00123 00124 } // end namespace itk 00125 00126 #ifndef ITK_MANUAL_INSTANTIATION 00127 #include "itkTreeNode.txx" 00128 #endif 00129 00130 #endif