ITK  4.9.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 #include "itkMacro.h"
23 
24 namespace itk
25 {
26 namespace fem
27 {
48 template <typename T>
49 class FEMP
50 {
51 public:
52 
58  FEMP() : m_Data(0)
59  {
60  }
61 
66  FEMP(const FEMP & x)
67  {
68  if( x.m_Data )
69  {
70 #ifdef USE_FEM_CLONE
71  m_Data = static_cast<T *>( x.m_Data->Clone().GetPointer() );
72 #else
73  std::cout << "Create Another" << std::endl;
74  m_Data = static_cast<T *>( x.m_Data->CreateAnother().GetPointer() );
75 #endif
76  }
77  else
78  {
79  m_Data = ITK_NULLPTR;
80  }
81  }
83 
90  explicit FEMP(typename T::Pointer x) : m_Data(x)
91  {
92  }
93 
98  {
99  m_Data = ITK_NULLPTR;
100  }
101 
105  const FEMP<T> & operator=(const FEMP<T> & rhs);
106 
110  typename T::Pointer operator->() const
111  {
112  return m_Data;
113  }
114 
119  operator T *() const
120  {
121  return m_Data;
122  }
123 
128  bool IsNULL() const
129  {
130  return m_Data == 0;
131  }
132 
133 private:
134 
138  typename T::Pointer m_Data;
139 };
140 
141 template <typename T>
142 const FEMP<T> & FEMP<T>::operator=(const FEMP<T> & rhs)
143 {
145  if( &rhs != this )
146  {
147 
151  m_Data = ITK_NULLPTR;
152 
157  if( rhs.m_Data )
158  {
159 #ifdef USE_FEM_CLONE
160  m_Data = static_cast<T *>( rhs.m_Data->Clone().GetPointer() );
161 #else
162  m_Data = static_cast<T *>( rhs.m_Data->CreateAnother().GetPointer() );
163 #endif
164 
165 
166  }
167  else
168  {
169  m_Data = ITK_NULLPTR;
170  }
171  }
172  return *this;
173 }
174 
175 }
176 } // end namespace itk::fem
177 
178 #endif // #ifndef itkFEMP_h
Pointer used to store polymorphic elements in STL arrays.
Definition: itkFEMP.h:49
T::Pointer m_Data
Definition: itkFEMP.h:138
const FEMP< T > & operator=(const FEMP< T > &rhs)
Definition: itkFEMP.h:142
FEMP(typename T::Pointer x)
Definition: itkFEMP.h:90
bool IsNULL() const
Definition: itkFEMP.h:128
FEMP(const FEMP &x)
Definition: itkFEMP.h:66
T::Pointer operator->() const
Definition: itkFEMP.h:110