ITK  5.1.0
Insight Toolkit
itkTreeIteratorClone.h
Go to the documentation of this file.
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 itkTreeIteratorClone_h
19 #define itkTreeIteratorClone_h
20 
21 #include "itkMacro.h"
22 #include <iostream>
23 
24 namespace itk
25 {
31 template <typename TObjectType>
33 {
34 public:
37  using ObjectType = TObjectType;
38 
41 
44  {
45  m_Pointer = nullptr;
46  if (p.m_Pointer != nullptr)
47  {
48  m_Pointer = p.m_Pointer->Clone();
49  }
50  }
52 
55  {
56  m_Pointer = 0;
57  if (p != nullptr)
58  {
59  m_Pointer = p->Clone();
60  }
61  }
63 
66  {
67  m_Pointer = nullptr;
68  m_Pointer = const_cast<ObjectType *>(&p)->Clone();
69  }
71 
74  {
75  delete m_Pointer;
76  m_Pointer = nullptr;
77  }
78 
80  ObjectType * operator->() const { return m_Pointer; }
81 
83  bool
84  IsNotNull() const
85  {
86  return m_Pointer != 0;
87  }
88  bool
89  IsNull() const
90  {
91  return m_Pointer == 0;
92  }
94 
96  template <typename TR>
97  bool
98  operator==(TR r) const
99  {
100  return (m_Pointer == (ObjectType *)(r));
101  }
102 
103  template <typename TR>
104  bool
105  operator!=(TR r) const
106  {
107  return (m_Pointer != (ObjectType *)(r));
108  }
109 
111  ObjectType *
112  GetPointer() const
113  {
114  return m_Pointer;
115  }
116 
118  bool
119  operator<(const TreeIteratorClone & r) const
120  {
121  return (void *)m_Pointer < (void *)r.m_Pointer;
122  }
123 
125  bool
126  operator>(const TreeIteratorClone & r) const
127  {
128  return (void *)m_Pointer > (void *)r.m_Pointer;
129  }
130 
132  bool
133  operator<=(const TreeIteratorClone & r) const
134  {
135  return (void *)m_Pointer <= (void *)r.m_Pointer;
136  }
137 
139  bool
140  operator>=(const TreeIteratorClone & r) const
141  {
142  return (void *)m_Pointer >= (void *)r.m_Pointer;
143  }
144 
148  {
149  return this->operator=(r.GetPointer());
150  }
151 
155  {
156  if (m_Pointer != r)
157  {
158  delete m_Pointer;
159  m_Pointer = nullptr;
160  if (r != nullptr)
161  {
162  m_Pointer = const_cast<ObjectType *>(r)->Clone();
163  }
164  }
165  return *this;
166  }
168 
169  Self &
171  {
172  if (m_Pointer)
173  {
174  ++(*m_Pointer);
175  }
176  return *this;
177  }
178 
179  const Self
181  {
182  if (m_Pointer)
183  {
184  const Self oldValue(m_Pointer); // create a copy of the iterator behind
185  // the pointer (Clone())
186  ++(*m_Pointer);
187  return oldValue;
188  }
189  }
190 
192  ObjectType *
193  Print(std::ostream & os) const
194  {
195  // This prints the object pointed to by the pointer
196  (*m_Pointer).Print(os);
197  return m_Pointer;
198  }
200 
201 private:
204 };
205 
206 template <typename T>
207 std::ostream &
208 operator<<(std::ostream & os, const TreeIteratorClone<T> p)
209 {
210  p.Print(os);
211  return os;
212 }
213 } // end namespace itk
214 
215 #endif
itk::TreeIteratorClone
Definition: itkTreeIteratorClone.h:32
itk::TreeIteratorClone::operator++
Self & operator++()
Definition: itkTreeIteratorClone.h:170
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:211
itk::TreeIteratorClone::operator=
TreeIteratorClone & operator=(const ObjectType *r)
Definition: itkTreeIteratorClone.h:154
itk::TreeIteratorClone::TreeIteratorClone
TreeIteratorClone(const TreeIteratorClone< ObjectType > &p)
Definition: itkTreeIteratorClone.h:43
itk::TreeIteratorClone::TreeIteratorClone
TreeIteratorClone(const ObjectType &p)
Definition: itkTreeIteratorClone.h:65
itk::TreeIteratorClone::TreeIteratorClone
TreeIteratorClone(ObjectType *p)
Definition: itkTreeIteratorClone.h:54
itk::TreeIteratorClone::IsNotNull
bool IsNotNull() const
Definition: itkTreeIteratorClone.h:84
itk::TreeIteratorClone::operator==
bool operator==(TR r) const
Definition: itkTreeIteratorClone.h:98
itk::TreeIteratorClone::operator<
bool operator<(const TreeIteratorClone &r) const
Definition: itkTreeIteratorClone.h:119
itk::TreeIteratorClone::ObjectType
TObjectType ObjectType
Definition: itkTreeIteratorClone.h:37
itk::TreeIteratorClone::operator>=
bool operator>=(const TreeIteratorClone &r) const
Definition: itkTreeIteratorClone.h:140
itk::TreeIteratorClone::operator++
const Self operator++(int)
Definition: itkTreeIteratorClone.h:180
itk::TreeIteratorClone::operator>
bool operator>(const TreeIteratorClone &r) const
Definition: itkTreeIteratorClone.h:126
itkMacro.h
itk::TreeIteratorClone::TreeIteratorClone
TreeIteratorClone()
Definition: itkTreeIteratorClone.h:40
itk::TreeIteratorClone::Self
TreeIteratorClone< TObjectType > Self
Definition: itkTreeIteratorClone.h:36
itk::TreeIteratorClone::m_Pointer
ObjectType * m_Pointer
Definition: itkTreeIteratorClone.h:203
itk::TreeIteratorClone::operator=
TreeIteratorClone & operator=(const TreeIteratorClone &r)
Definition: itkTreeIteratorClone.h:147
itk::TreeIteratorClone::GetPointer
ObjectType * GetPointer() const
Definition: itkTreeIteratorClone.h:112
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::TreeIteratorClone::operator<=
bool operator<=(const TreeIteratorClone &r) const
Definition: itkTreeIteratorClone.h:133
itk::TreeIteratorClone::operator!=
bool operator!=(TR r) const
Definition: itkTreeIteratorClone.h:105
itk::TreeIteratorClone::IsNull
bool IsNull() const
Definition: itkTreeIteratorClone.h:89
itk::TreeIteratorClone::operator->
ObjectType * operator->() const
Definition: itkTreeIteratorClone.h:80
itk::TreeIteratorClone::Print
ObjectType * Print(std::ostream &os) const
Definition: itkTreeIteratorClone.h:193
itk::TreeIteratorClone::~TreeIteratorClone
~TreeIteratorClone()
Definition: itkTreeIteratorClone.h:73