ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkFEMP_h 00019 #define __itkFEMP_h 00020 00021 #include <iostream> 00022 00023 namespace itk 00024 { 00025 namespace fem 00026 { 00047 template <class T> 00048 class FEMP 00049 { 00050 public: 00051 00057 FEMP() : m_Data(0) 00058 { 00059 } 00060 00065 FEMP(const FEMP & x) 00066 { 00067 if( x.m_Data ) 00068 { 00069 #ifdef USE_FEM_CLONE 00070 m_Data = static_cast<T *>( x.m_Data->Clone().GetPointer() ); 00071 #else 00072 std::cout << "Create Another" << std::endl; 00073 m_Data = static_cast<T *>( x.m_Data->CreateAnother().GetPointer() ); 00074 #endif 00075 } 00076 else 00077 { 00078 m_Data = 0; 00079 } 00080 } 00082 00089 explicit FEMP(typename T::Pointer x) : m_Data(x) 00090 { 00091 } 00092 00096 ~FEMP() 00097 { 00098 m_Data = 0; 00099 } 00100 00104 const FEMP<T> & operator=(const FEMP<T> & rhs); 00105 00109 typename T::Pointer operator->() const 00110 { 00111 return m_Data; 00112 } 00113 00118 operator T *() const 00119 { 00120 return m_Data; 00121 } 00122 00127 bool IsNULL() const 00128 { 00129 return m_Data == 0; 00130 } 00131 00132 private: 00133 00137 typename T::Pointer m_Data; 00138 }; 00139 00140 template <class T> 00141 const FEMP<T> & FEMP<T>::operator=(const FEMP<T> & rhs) 00142 { 00144 if( &rhs != this ) 00145 { 00146 00150 m_Data = 0; 00151 00156 if( rhs.m_Data ) 00157 { 00158 #ifdef USE_FEM_CLONE 00159 m_Data = static_cast<T *>( rhs.m_Data->Clone().GetPointer() ); 00160 #else 00161 m_Data = static_cast<T *>( rhs.m_Data->CreateAnother().GetPointer() ); 00162 #endif 00163 00164 00165 } 00166 else 00167 { 00168 m_Data = 0; 00169 } 00170 } 00171 return *this; 00172 } 00173 00174 } 00175 } // end namespace itk::fem 00176 00177 #endif // #ifndef __itkFEMP_h 00178