ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkFEMP.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 __itkFEMP_h
19 #define __itkFEMP_h
20 
21 #include <iostream>
22 
23 namespace itk
24 {
25 namespace fem
26 {
47 template <class T>
48 class FEMP
49 {
50 public:
51 
57  FEMP() : m_Data(0)
58  {
59  }
60 
65  FEMP(const FEMP & x)
66  {
67  if( x.m_Data )
68  {
69 #ifdef USE_FEM_CLONE
70  m_Data = static_cast<T *>( x.m_Data->Clone().GetPointer() );
71 #else
72  std::cout << "Create Another" << std::endl;
73  m_Data = static_cast<T *>( x.m_Data->CreateAnother().GetPointer() );
74 #endif
75  }
76  else
77  {
78  m_Data = 0;
79  }
80  }
82 
89  explicit FEMP(typename T::Pointer x) : m_Data(x)
90  {
91  }
92 
97  {
98  m_Data = 0;
99  }
100 
104  const FEMP<T> & operator=(const FEMP<T> & rhs);
105 
109  typename T::Pointer operator->() const
110  {
111  return m_Data;
112  }
113 
118  operator T *() const
119  {
120  return m_Data;
121  }
122 
127  bool IsNULL() const
128  {
129  return m_Data == 0;
130  }
131 
132 private:
133 
137  typename T::Pointer m_Data;
138 };
139 
140 template <class T>
141 const FEMP<T> & FEMP<T>::operator=(const FEMP<T> & rhs)
142 {
144  if( &rhs != this )
145  {
146 
150  m_Data = 0;
151 
156  if( rhs.m_Data )
157  {
158 #ifdef USE_FEM_CLONE
159  m_Data = static_cast<T *>( rhs.m_Data->Clone().GetPointer() );
160 #else
161  m_Data = static_cast<T *>( rhs.m_Data->CreateAnother().GetPointer() );
162 #endif
163 
164 
165  }
166  else
167  {
168  m_Data = 0;
169  }
170  }
171  return *this;
172 }
173 
174 }
175 } // end namespace itk::fem
176 
177 #endif // #ifndef __itkFEMP_h
178