ITK  6.0.0
Insight Toolkit
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
itk::ObjectFactoryBase Class Referenceabstract

#include <itkObjectFactoryBase.h>

Detailed Description

Create instances of classes using an object factory.

ObjectFactoryBase is used to create itk objects. The base class ObjectFactoryBase contains a static method CreateInstance() that is used to create itk objects from the list of registered ObjectFactoryBase sub-classes. The first time CreateInstance() is called, all dll's or shared libraries in the environment variable ITK_AUTOLOAD_PATH are loaded into the current process. The C function itkLoad is called on each dll. itkLoad should return an instance of the factory sub-class implemented in the shared library. ITK_AUTOLOAD_PATH is an environment variable containing a colon separated (semi-colon on win32) list of paths.

This can be use to override the creation of any object in ITK.

Definition at line 59 of file itkObjectFactoryBase.h.

+ Inheritance diagram for itk::ObjectFactoryBase:
+ Collaboration diagram for itk::ObjectFactoryBase:

Public Types

using ConstPointer = SmartPointer< const Self >
 
using InsertionPositionEnum = ObjectFactoryEnums::InsertionPosition
 
using Pointer = SmartPointer< Self >
 
using Self = ObjectFactoryBase
 
using Superclass = Object
 
- Public Types inherited from itk::Object
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = Object
 
using Superclass = LightObject
 
- Public Types inherited from itk::LightObject
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = LightObject
 

Public Member Functions

virtual void Disable (const char *className)
 
virtual std::list< std::string > GetClassOverrideDescriptions ()
 
virtual std::list< std::string > GetClassOverrideNames ()
 
virtual std::list< std::string > GetClassOverrideWithNames ()
 
virtual const char * GetDescription () const =0
 
virtual bool GetEnableFlag (const char *className, const char *subclassName)
 
virtual std::list< bool > GetEnableFlags ()
 
virtual const char * GetITKSourceVersion () const =0
 
const char * GetLibraryPath ()
 
const char * GetNameOfClass () const override
 
virtual void SetEnableFlag (bool flag, const char *className, const char *subclassName)
 
- Public Member Functions inherited from itk::Object
unsigned long AddObserver (const EventObject &event, Command *cmd) const
 
unsigned long AddObserver (const EventObject &event, std::function< void(const EventObject &)> function) const
 
LightObject::Pointer CreateAnother () const override
 
virtual void DebugOff () const
 
virtual void DebugOn () const
 
CommandGetCommand (unsigned long tag)
 
bool GetDebug () const
 
MetaDataDictionaryGetMetaDataDictionary ()
 
const MetaDataDictionaryGetMetaDataDictionary () const
 
virtual ModifiedTimeType GetMTime () const
 
const char * GetNameOfClass () const override
 
virtual const TimeStampGetTimeStamp () const
 
bool HasObserver (const EventObject &event) const
 
void InvokeEvent (const EventObject &)
 
void InvokeEvent (const EventObject &) const
 
virtual void Modified () const
 
void Register () const override
 
void RemoveAllObservers ()
 
void RemoveObserver (unsigned long tag) const
 
void SetDebug (bool debugFlag) const
 
void SetReferenceCount (int) override
 
void UnRegister () const noexcept override
 
void SetMetaDataDictionary (const MetaDataDictionary &rhs)
 
void SetMetaDataDictionary (MetaDataDictionary &&rrhs)
 
virtual void SetObjectName (std::string _arg)
 
virtual const std::string & GetObjectName () const
 
- Public Member Functions inherited from itk::LightObject
Pointer Clone () const
 
virtual Pointer CreateAnother () const
 
virtual void Delete ()
 
virtual const char * GetNameOfClass () const
 
virtual int GetReferenceCount () const
 
void Print (std::ostream &os, Indent indent=0) const
 
virtual void Register () const
 
virtual void SetReferenceCount (int)
 
virtual void UnRegister () const noexcept
 

Static Public Member Functions

static std::list< LightObject::PointerCreateAllInstance (const char *itkclassname)
 
static LightObject::Pointer CreateInstance (const char *itkclassname)
 
static std::list< ObjectFactoryBase * > GetRegisteredFactories ()
 
static void Initialize ()
 
static void RegisterFactoryInternal (ObjectFactoryBase *)
 
template<typename TFactory >
static void RegisterInternalFactoryOnce ()
 
static void ReHash ()
 
static void UnRegisterAllFactories ()
 
static void UnRegisterFactory (ObjectFactoryBase *)
 
static bool RegisterFactory (ObjectFactoryBase *, InsertionPositionEnum where=InsertionPositionEnum::INSERT_AT_BACK, vcl_size_t position=0)
 
static void SetStrictVersionChecking (bool)
 
static void StrictVersionCheckingOn ()
 
static void StrictVersionCheckingOff ()
 
static bool GetStrictVersionChecking ()
 
- Static Public Member Functions inherited from itk::Object
static bool GetGlobalWarningDisplay ()
 
static void GlobalWarningDisplayOff ()
 
static void GlobalWarningDisplayOn ()
 
static Pointer New ()
 
static void SetGlobalWarningDisplay (bool val)
 
- Static Public Member Functions inherited from itk::LightObject
static void BreakOnError ()
 
static Pointer New ()
 

Protected Member Functions

virtual std::list< LightObject::PointerCreateAllObject (const char *itkclassname)
 
virtual LightObject::Pointer CreateObject (const char *itkclassname)
 
 ObjectFactoryBase ()
 
void PrintSelf (std::ostream &os, Indent indent) const override
 
void RegisterOverride (const char *classOverride, const char *subclass, const char *description, bool enableFlag, CreateObjectFunctionBase *createFunction)
 
 ~ObjectFactoryBase () override
 
- Protected Member Functions inherited from itk::Object
 Object ()
 
bool PrintObservers (std::ostream &os, Indent indent) const
 
void PrintSelf (std::ostream &os, Indent indent) const override
 
virtual void SetTimeStamp (const TimeStamp &timeStamp)
 
 ~Object () override
 
- Protected Member Functions inherited from itk::LightObject
virtual LightObject::Pointer InternalClone () const
 
 LightObject ()
 
virtual void PrintHeader (std::ostream &os, Indent indent) const
 
virtual void PrintSelf (std::ostream &os, Indent indent) const
 
virtual void PrintTrailer (std::ostream &os, Indent indent) const
 
virtual ~LightObject ()
 

Static Private Member Functions

static void DeleteNonInternalFactory (ObjectFactoryBase *)
 
static void LoadDynamicFactories ()
 
static void LoadLibrariesInPath (const char *)
 

Private Attributes

unsigned long m_LibraryDate {}
 
void * m_LibraryHandle {}
 
std::string m_LibraryPath {}
 
const std::unique_ptr< OverrideMap > m_OverrideMap
 

Static Private Attributes

static ObjectFactoryBasePrivate * m_PimplGlobals
 
static void SynchronizeObjectFactoryBase (void *objectFactoryBasePrivate)
 
 itkGetGlobalDeclarationMacro (ObjectFactoryBasePrivate, PimplGlobals)
 

Additional Inherited Members

- Protected Attributes inherited from itk::LightObject
std::atomic< int > m_ReferenceCount {}
 

Member Typedef Documentation

◆ ConstPointer

Definition at line 68 of file itkObjectFactoryBase.h.

◆ InsertionPositionEnum

Definition at line 106 of file itkObjectFactoryBase.h.

◆ Pointer

Definition at line 67 of file itkObjectFactoryBase.h.

◆ Self

Standard class type aliases.

Definition at line 65 of file itkObjectFactoryBase.h.

◆ Superclass

Definition at line 66 of file itkObjectFactoryBase.h.

Constructor & Destructor Documentation

◆ ObjectFactoryBase()

itk::ObjectFactoryBase::ObjectFactoryBase ( )
protected

◆ ~ObjectFactoryBase()

itk::ObjectFactoryBase::~ObjectFactoryBase ( )
overrideprotected

Member Function Documentation

◆ CreateAllInstance()

static std::list< LightObject::Pointer > itk::ObjectFactoryBase::CreateAllInstance ( const char *  itkclassname)
static

Create and return all possible instances of the named itk object. Each loaded ObjectFactoryBase will be asked in the order the factory was in the ITK_AUTOLOAD_PATH. All created objects will be returned in the list.

◆ CreateAllObject()

virtual std::list< LightObject::Pointer > itk::ObjectFactoryBase::CreateAllObject ( const char *  itkclassname)
protectedvirtual

This method creates all the objects with the class override of itkclass name, which are provide by this object

◆ CreateInstance()

static LightObject::Pointer itk::ObjectFactoryBase::CreateInstance ( const char *  itkclassname)
static

Create and return an instance of the named itk object. Each loaded ObjectFactoryBase will be asked in the order the factory was in the ITK_AUTOLOAD_PATH. After the first factory returns the object no other factories are asked.

Note
The object returned by CreateInstance will have a reference count of 2, instead of 1. So in order to avoid memory leaks, one may need to call object->UnRegister().

Referenced by itk::ObjectFactory< T >::Create(), and itk::TransformFactoryBase::RegisterTransform().

◆ CreateObject()

virtual LightObject::Pointer itk::ObjectFactoryBase::CreateObject ( const char *  itkclassname)
protectedvirtual

This method is provided by sub-classes of ObjectFactoryBase. It should create the named itk object or return 0 if that object is not supported by the factory implementation.

◆ DeleteNonInternalFactory()

static void itk::ObjectFactoryBase::DeleteNonInternalFactory ( ObjectFactoryBase )
staticprivate

◆ Disable()

virtual void itk::ObjectFactoryBase::Disable ( const char *  className)
virtual

Set all enable flags for the given class to 0. This will mean that the factory will stop producing class with the given name.

◆ GetClassOverrideDescriptions()

virtual std::list< std::string > itk::ObjectFactoryBase::GetClassOverrideDescriptions ( )
virtual

Return a list of descriptions for class overrides.

◆ GetClassOverrideNames()

virtual std::list< std::string > itk::ObjectFactoryBase::GetClassOverrideNames ( )
virtual

Return a list of classes that this factory overrides.

◆ GetClassOverrideWithNames()

virtual std::list< std::string > itk::ObjectFactoryBase::GetClassOverrideWithNames ( )
virtual

Return a list of the names of classes that override classes.

◆ GetDescription()

virtual const char * itk::ObjectFactoryBase::GetDescription ( ) const
pure virtual

◆ GetEnableFlag()

virtual bool itk::ObjectFactoryBase::GetEnableFlag ( const char *  className,
const char *  subclassName 
)
virtual

Get the Enable flag for the specific override of className.

◆ GetEnableFlags()

virtual std::list< bool > itk::ObjectFactoryBase::GetEnableFlags ( )
virtual

Return a list of enable flags.

◆ GetITKSourceVersion()

virtual const char * itk::ObjectFactoryBase::GetITKSourceVersion ( ) const
pure virtual

All sub-classes of ObjectFactoryBase should must return the version of ITK they were built with. This should be implemented with the macro ITK_SOURCE_VERSION and NOT a call to Version::GetITKSourceVersion. As the version needs to be compiled into the file as a string constant. This is critical to determine possible incompatible dynamic factory loads.

Implemented in itk::GPUImageFactory, itk::SpatialObjectFactoryBase, itk::FFTImageFilterFactory< TFFTImageFilter, TInput, TOutput >, itk::GPUGradientAnisotropicDiffusionImageFilterFactory, itk::GPUMeanImageFilterFactory, itk::GPUBinaryThresholdImageFilterFactory, itk::FFTDiscreteGaussianImageFilterFactory, itk::BioRadImageIOFactory, itk::BMPImageIOFactory, itk::Bruker2dseqImageIOFactory, itk::GDCMImageIOFactory, itk::GE4ImageIOFactory, itk::GE5ImageIOFactory, itk::GEAdwImageIOFactory, itk::GiplImageIOFactory, itk::HDF5ImageIOFactory, itk::JPEGImageIOFactory, itk::JPEG2000ImageIOFactory, itk::LSMImageIOFactory, itk::BYUMeshIOFactory, itk::FreeSurferAsciiMeshIOFactory, itk::FreeSurferBinaryMeshIOFactory, itk::GiftiMeshIOFactory, itk::OBJMeshIOFactory, itk::OFFMeshIOFactory, itk::VTKPolyDataMeshIOFactory, itk::MetaImageIOFactory, itk::MINCImageIOFactory, itk::MRCImageIOFactory, itk::NiftiImageIOFactory, itk::NrrdImageIOFactory, itk::PNGImageIOFactory, itk::RawImageIOFactory< TPixel, VImageDimension >, itk::SiemensVisionImageIOFactory, itk::StimulateImageIOFactory, itk::TIFFImageIOFactory, itk::TransformFactoryBase, itk::HDF5TransformIOFactory, itk::TxtTransformIOFactory, itk::MatlabTransformIOFactory, itk::VTKImageIOFactory, itk::VoxBoCUBImageIOFactory, itk::GPUDemonsRegistrationFilterFactory, and itk::FileListVideoIOFactory.

◆ GetLibraryPath()

const char * itk::ObjectFactoryBase::GetLibraryPath ( )

This returns the path to a dynamically loaded factory.

◆ GetNameOfClass()

const char * itk::ObjectFactoryBase::GetNameOfClass ( ) const
overridevirtual

◆ GetRegisteredFactories()

static std::list< ObjectFactoryBase * > itk::ObjectFactoryBase::GetRegisteredFactories ( )
static

Return the list of all registered factories. This is NOT a copy, do not remove items from this list!

◆ GetStrictVersionChecking()

static bool itk::ObjectFactoryBase::GetStrictVersionChecking ( )
static

Require the ITK version of this application to exactly match the ITK version used to compile a dynamic library. When this is set to true, if the versions do not match, an exception will be thrown. When this is false, and the versions do not match, only a warning message is printed out in the console, and the factory is still registered.

◆ Initialize()

static void itk::ObjectFactoryBase::Initialize ( )
static

Initialize the static members of ObjectFactoryBase.

◆ itkGetGlobalDeclarationMacro()

itk::ObjectFactoryBase::itkGetGlobalDeclarationMacro ( ObjectFactoryBasePrivate  ,
PimplGlobals   
)
private

Set/Get the pointer to ObjectFactoryBasePrivate. No concurrent thread safe.

◆ LoadDynamicFactories()

static void itk::ObjectFactoryBase::LoadDynamicFactories ( )
staticprivate

Load dynamic factories from the ITK_AUTOLOAD_PATH

◆ LoadLibrariesInPath()

static void itk::ObjectFactoryBase::LoadLibrariesInPath ( const char *  )
staticprivate

Load all dynamic libraries in the given path

◆ PrintSelf()

void itk::ObjectFactoryBase::PrintSelf ( std::ostream &  os,
Indent  indent 
) const
overrideprotectedvirtual

◆ RegisterFactory()

static bool itk::ObjectFactoryBase::RegisterFactory ( ObjectFactoryBase ,
InsertionPositionEnum  where = InsertionPositionEnum::INSERT_AT_BACK,
vcl_size_t  position = 0 
)
static

Register a factory so it can be used to create itk objects.

When InsertionPositionEnum::INSERT_AT_POSITION is selected, a third argument must be provided
with the actual integer number of the intended position. The position
number must be in the range [0, numberOfRegisteredFactories-1].

Usage should be any of the following:

itk::ObjectFactoryBase::RegisterFactory( newFactory1 ); // at back
itk::ObjectFactoryBase::RegisterFactory( newFactory2, InsertionPositionEnum::INSERT_AT_FRONT );
itk::ObjectFactoryBase::RegisterFactory( newFactory3, InsertionPositionEnum::INSERT_AT_BACK );
itk::ObjectFactoryBase::RegisterFactory( newFactory4, InsertionPositionEnum::INSERT_AT_POSITION, 5 );

If the position value is out of range, an exception will be
thrown.
Returns true if the factory was successfully registered.
Returns false if factory is already loaded.

Referenced by itk::SpatialObjectFactoryBase::GetFactory(), itk::GPUImageFactory::RegisterOneFactory(), itk::GPUGradientAnisotropicDiffusionImageFilterFactory::RegisterOneFactory(), itk::GPUMeanImageFilterFactory::RegisterOneFactory(), itk::GPUBinaryThresholdImageFilterFactory::RegisterOneFactory(), itk::RawImageIOFactory< TPixel, VImageDimension >::RegisterOneFactory(), itk::VoxBoCUBImageIOFactory::RegisterOneFactory(), and itk::GPUDemonsRegistrationFilterFactory::RegisterOneFactory().

◆ RegisterFactoryInternal()

static void itk::ObjectFactoryBase::RegisterFactoryInternal ( ObjectFactoryBase )
static

Register a factory so it can be used to create itk objects. This method is intended to be called only for built-in default factories, not for loadable factories.

Factories that are registered with this method will be registered after ReHash.

Referenced by itk::FFTImageFilterFactory< TFFTImageFilter, TInput, TOutput >::RegisterOneFactory(), itk::FFTDiscreteGaussianImageFilterFactory::RegisterOneFactory(), itk::BioRadImageIOFactory::RegisterOneFactory(), itk::BMPImageIOFactory::RegisterOneFactory(), itk::Bruker2dseqImageIOFactory::RegisterOneFactory(), itk::GDCMImageIOFactory::RegisterOneFactory(), itk::GE4ImageIOFactory::RegisterOneFactory(), itk::GE5ImageIOFactory::RegisterOneFactory(), itk::GEAdwImageIOFactory::RegisterOneFactory(), itk::GiplImageIOFactory::RegisterOneFactory(), itk::HDF5ImageIOFactory::RegisterOneFactory(), itk::JPEGImageIOFactory::RegisterOneFactory(), itk::JPEG2000ImageIOFactory::RegisterOneFactory(), itk::LSMImageIOFactory::RegisterOneFactory(), itk::BYUMeshIOFactory::RegisterOneFactory(), itk::FreeSurferAsciiMeshIOFactory::RegisterOneFactory(), itk::FreeSurferBinaryMeshIOFactory::RegisterOneFactory(), itk::GiftiMeshIOFactory::RegisterOneFactory(), itk::OBJMeshIOFactory::RegisterOneFactory(), itk::OFFMeshIOFactory::RegisterOneFactory(), itk::VTKPolyDataMeshIOFactory::RegisterOneFactory(), itk::MetaImageIOFactory::RegisterOneFactory(), itk::MINCImageIOFactory::RegisterOneFactory(), itk::MRCImageIOFactory::RegisterOneFactory(), itk::NiftiImageIOFactory::RegisterOneFactory(), itk::NrrdImageIOFactory::RegisterOneFactory(), itk::PNGImageIOFactory::RegisterOneFactory(), itk::SiemensVisionImageIOFactory::RegisterOneFactory(), itk::StimulateImageIOFactory::RegisterOneFactory(), itk::TIFFImageIOFactory::RegisterOneFactory(), itk::HDF5TransformIOFactory::RegisterOneFactory(), itk::TxtTransformIOFactory::RegisterOneFactory(), itk::MatlabTransformIOFactory::RegisterOneFactory(), itk::VTKImageIOFactory::RegisterOneFactory(), and itk::FileListVideoIOFactory::RegisterOneFactory().

◆ RegisterInternalFactoryOnce()

template<typename TFactory >
static void itk::ObjectFactoryBase::RegisterInternalFactoryOnce ( )
inlinestatic

Registers the specified internal factory only once, even when RegisterInternalFactoryOnce<TFactory>() is called multiple times (possibly even by multiple threads) for the very same factory.

Definition at line 217 of file itkObjectFactoryBase.h.

References New().

◆ RegisterOverride()

void itk::ObjectFactoryBase::RegisterOverride ( const char *  classOverride,
const char *  subclass,
const char *  description,
bool  enableFlag,
CreateObjectFunctionBase createFunction 
)
protected

◆ ReHash()

static void itk::ObjectFactoryBase::ReHash ( )
static

Re-check the ITK_AUTOLOAD_PATH for new factory libraries. This calls UnRegisterAll before re-loading.

◆ SetEnableFlag()

virtual void itk::ObjectFactoryBase::SetEnableFlag ( bool  flag,
const char *  className,
const char *  subclassName 
)
virtual

Set the Enable flag for the specific override of className.

◆ SetStrictVersionChecking()

static void itk::ObjectFactoryBase::SetStrictVersionChecking ( bool  )
static

Require the ITK version of this application to exactly match the ITK version used to compile a dynamic library. When this is set to true, if the versions do not match, an exception will be thrown. When this is false, and the versions do not match, only a warning message is printed out in the console, and the factory is still registered.

◆ StrictVersionCheckingOff()

static void itk::ObjectFactoryBase::StrictVersionCheckingOff ( )
static

Require the ITK version of this application to exactly match the ITK version used to compile a dynamic library. When this is set to true, if the versions do not match, an exception will be thrown. When this is false, and the versions do not match, only a warning message is printed out in the console, and the factory is still registered.

◆ StrictVersionCheckingOn()

static void itk::ObjectFactoryBase::StrictVersionCheckingOn ( )
static

Require the ITK version of this application to exactly match the ITK version used to compile a dynamic library. When this is set to true, if the versions do not match, an exception will be thrown. When this is false, and the versions do not match, only a warning message is printed out in the console, and the factory is still registered.

◆ SynchronizeObjectFactoryBase()

static void itk::ObjectFactoryBase::SynchronizeObjectFactoryBase ( void *  objectFactoryBasePrivate)
staticprivate

Set/Get the pointer to ObjectFactoryBasePrivate. No concurrent thread safe.

◆ UnRegisterAllFactories()

static void itk::ObjectFactoryBase::UnRegisterAllFactories ( )
static

Unregister all factories.

◆ UnRegisterFactory()

static void itk::ObjectFactoryBase::UnRegisterFactory ( ObjectFactoryBase )
static

Remove a factory from the list of registered factories.

Member Data Documentation

◆ m_LibraryDate

unsigned long itk::ObjectFactoryBase::m_LibraryDate {}
private

Definition at line 288 of file itkObjectFactoryBase.h.

◆ m_LibraryHandle

void* itk::ObjectFactoryBase::m_LibraryHandle {}
private

Member variables for a factory set by the base class at load or register time

Definition at line 287 of file itkObjectFactoryBase.h.

◆ m_LibraryPath

std::string itk::ObjectFactoryBase::m_LibraryPath {}
private

Definition at line 289 of file itkObjectFactoryBase.h.

◆ m_OverrideMap

const std::unique_ptr<OverrideMap> itk::ObjectFactoryBase::m_OverrideMap
private

Definition at line 272 of file itkObjectFactoryBase.h.

◆ m_PimplGlobals

ObjectFactoryBasePrivate* itk::ObjectFactoryBase::m_PimplGlobals
staticprivate

Definition at line 291 of file itkObjectFactoryBase.h.


The documentation for this class was generated from the following file: