KWStyle - itkTreeIteratorClone.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkTreeIteratorClone.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:48 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 #ifndef __itkTreeIteratorClone_h
18 #define __itkTreeIteratorClone_h
19
20 #include "itkMacro.h"
21 #include <iostream>
22
23 namespace itk
24 {
25
26 template <class TObjectType>
27 class ITK_EXPORT TreeIteratorClone 
28 {
29 public:
30   
31   /** Typedefs */
32   typedef TreeIteratorClone<TObjectType> Self;
33 TDA   typedef TObjectType ObjectType;
34   
35   /** Constructor  */
36   TreeIteratorClone () 
37     { 
38     m_Pointer = 0; 
39     }
40
41   /** Copy constructor  */
42   TreeIteratorClone (const TreeIteratorClone<ObjectType> &p)
43     { 
44
45     if(p.m_Pointer != NULL)
46       {
47       m_Pointer = p.m_Pointer->Clone();
48       }
49     }
50   
51   /** Constructor to pointer p  */
52   TreeIteratorClone (ObjectType *p)
53     { 
54     m_Pointer = 0;
55     if(p!=NULL)
56       {
57       m_Pointer=p->Clone();
58       }
59     }                             
60
61   /** Constructor to reference p  */
62   TreeIteratorClone (const ObjectType &p)
63     { 
64     m_Pointer = 0;
65     m_Pointer=const_cast<ObjectType*>(&p)->Clone();
66     }                             
67   
68   /** Destructor  */
69   ~TreeIteratorClone ()
70     {
71     delete m_Pointer;
72     m_Pointer = 0;
73     }
74   
75   /** Overload operator ->  */
76   ObjectType *operator -> () const
77     { return m_Pointer; }
78
79   /** Test if the pointer has been initialized */
80   bool IsNotNull() const
81 IND **{ return m_Pointer != 0; }
82   bool IsNull() const
83 IND **{ return m_Pointer == 0; }
84
85   /** Template comparison operators. */
86   template <typename R>
87   bool operator == ( R r ) const
88     { return (m_Pointer == (ObjectType*)(r) ); }
89
90   template <typename R>
91   bool operator != ( R r ) const
92     { return (m_Pointer != (ObjectType*)(r) ); }
93     
94   /** Access function to pointer. */
95   ObjectType *GetPointer () const 
96     { return m_Pointer; }
97   
98   /** Comparison of pointers. Less than comparison.  */
99   bool operator < (const TreeIteratorClone &r) const
100     { return (void*)m_Pointer < (void*) r.m_Pointer; }
101   
102   /** Comparison of pointers. Greater than comparison.  */
103   bool operator > (const TreeIteratorClone &r) const
104     { return (void*)m_Pointer > (void*) r.m_Pointer; }
105
106   /** Comparison of pointers. Less than or equal to comparison.  */
107   bool operator <= (const TreeIteratorClone &r) const
108     { return (void*)m_Pointer <= (void*) r.m_Pointer; }
109
110   /** Comparison of pointers. Greater than or equal to comparison.  */
111   bool operator >= (const TreeIteratorClone &r) const
112     { return (void*)m_Pointer >= (void*) r.m_Pointer; }
113
114   /** Overload operator assignment.  */
115   TreeIteratorClone &operator = (const TreeIteratorClone &r)
116     { return this->operator = (r.GetPointer()); }
117   
118   /** Overload operator assignment.  */
119   TreeIteratorClone &operator = (const ObjectType *r)
120     {                                                              
121     if (m_Pointer != r)
122       {
123       delete m_Pointer;
124       m_Pointer = 0;  
125       if(r!=NULL) 
126 IND ********m_Pointer=const_cast<ObjectType*>(r)->Clone();
127       }
128     return *this;
129     }
130
131   Self &
132   operator++()
133     {
134     if(m_Pointer)
135 IND ******++(*m_Pointer);
136     return *this;
137     }
138   
139   /** Function to print object pointed to  */
140   ObjectType *Print (std::ostream& os) const 
141     { 
142     // This prints the object pointed to by the pointer  
143     (*m_Pointer).Print(os);  
144     return m_Pointer;
145     } 
146
147 private:
148   /** The pointer to the object referrred to by this smart pointer. */
149   ObjectType* m_Pointer;
150 };  
151
152
153 template <typename T>
154 std::ostream& operator<< (std::ostream& os, TreeIteratorClone<T> p) 
155 {
156   p.Print(os); 
157   return os;
158 }
159
160 // end namespace itk
161   
162 #endif
163

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:51PM
© Kitware Inc.