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 /*========================================================================= 00019 * 00020 * Portions of this file are subject to the VTK Toolkit Version 3 copyright. 00021 * 00022 * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00023 * 00024 * For complete copyright, license and disclaimer of warranty information 00025 * please refer to the NOTICE file at the top of the ITK source tree. 00026 * 00027 *=========================================================================*/ 00028 #ifndef __itkFEMFactoryBase_h 00029 #define __itkFEMFactoryBase_h 00030 00031 #include "itkObjectFactoryBase.h" 00032 00033 namespace itk 00034 { 00041 class ITK_EXPORT FEMFactoryBase : public ObjectFactoryBase 00042 { 00043 public: 00045 typedef FEMFactoryBase Self; 00046 typedef ObjectFactoryBase Superclass; 00047 typedef SmartPointer<Self> Pointer; 00048 typedef SmartPointer<const Self> ConstPointer; 00049 00051 virtual const char * GetITKSourceVersion(void) const; 00052 00053 virtual const char * GetDescription(void) const; 00054 00056 itkTypeMacro(FEMFactoryBase, ObjectFactoryBase); 00057 00059 itkFactorylessNewMacro(Self); 00060 00062 static void RegisterDefaultTypes(); //HACK: This should not have a public interface since it does nothing except during instantiation of the class. 00063 00065 static FEMFactoryBase * GetFactory() 00066 { 00067 if( m_Factory == 0 ) 00068 { 00069 m_CreationLock.Lock(); 00070 //Need to make sure that during gaining access 00071 //to the lock that some other thread did not 00072 //initialize the singleton. 00073 if( m_Factory == 0 ) 00074 { 00075 // Make and register the factory 00076 FEMFactoryBase::Pointer p = FEMFactoryBase::New(); 00077 if( p.IsNull() ) 00078 { 00079 std::ostringstream message; 00080 message << "itk::ERROR: " << "FEMFactoryBase" 00081 << " instance not created"; 00082 ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); 00083 throw e_; /* Explicit naming to work around for Intel compiler bug. */ 00084 } 00085 ObjectFactoryBase::RegisterFactory( p ); 00086 m_Factory = p.GetPointer(); 00087 } 00088 m_CreationLock.Unlock(); 00089 m_Factory->RegisterDefaultTypes(); //Not initialzie all default types. 00090 } 00091 return m_Factory; 00092 } 00094 00095 void RegisterType(const char* classOverride, 00096 const char* overrideClassName, 00097 const char* description, 00098 bool enableFlag, 00099 CreateObjectFunctionBase* createFunction) 00100 { 00101 this->RegisterOverride( classOverride, overrideClassName, description, enableFlag, createFunction ); 00102 } 00103 00104 protected: 00105 FEMFactoryBase(); 00106 virtual ~FEMFactoryBase(); 00107 private: 00108 FEMFactoryBase(const Self &); // purposely not implemented 00109 void operator=(const Self &); // purposely not implemented 00110 00111 static SimpleFastMutexLock m_CreationLock; 00112 static FEMFactoryBase* m_Factory; 00113 }; 00114 } // end namespace itk 00115 00116 #endif 00117