![]() |
Orfeo Toolbox
3.16
|
Create objects of derived classes by specifying a class ID. More...
#include <itkFEMObjectFactory.h>
Inheritance diagram for itk::fem::FEMObjectFactory< T >:
Collaboration diagram for itk::fem::FEMObjectFactory< T >:Classes | |
| class | Dummy |
| This class is defined in FEMObjectFactory just to get rid of some warnings about destructor being private in gcc. More... | |
Static Public Member Functions | |
| static int | ClassName2ID (StrClassName str) |
| static T::Pointer | Create (int id) |
| static StrClassName | ID2ClassName (int id) |
| static int | Register (COF f, const char *str) |
Private Types | |
| typedef T::Pointer(* | COF )() |
| typedef std::vector< std::pair < COF, StrClassName > > | COF_Array |
| typedef COF_Array::value_type | COF_Array_value_type |
| typedef std::string | StrClassName |
Private Member Functions | |
| FEMObjectFactory () | |
| FEMObjectFactory (const FEMObjectFactory &) | |
| ~FEMObjectFactory () | |
Static Private Member Functions | |
| static void | CleanUP () |
| static FEMObjectFactory & | Instance () |
Private Attributes | |
| COF_Array | cofs_ |
| SimpleFastMutexLock | m_MutexLock |
Static Private Attributes | |
| static FEMObjectFactory * | obj = 0 |
Friends | |
| class | Dummy |
Create objects of derived classes by specifying a class ID.
ObjectFactory is used to create various objects of derived classes by specifying an ID of a derived class. Before the objects can be created by object factory, you should first call the Register method for each class:
int ID_Derived=FEMObjectFactory<BaseClass>.Register( NewDerivedClass, "NewDerivedClassName" );
NewDerivedClass: Function that creates a new instance of a derived class and returns a pointer to it as a pointer to the base class. Normally you should define this function as:
You should also put the NewDerivedClass function in an anonymous namespace and make it static. So a complete registration of a derived class looks like:
Definition at line 66 of file itkFEMObjectFactory.h.
|
private |
Type that holds a pointer to function which can create a new object of a derived class.
Definition at line 72 of file itkFEMObjectFactory.h.
|
private |
Type that holds an array of pairs of the COF pointers to functions and class names.
Definition at line 82 of file itkFEMObjectFactory.h.
|
private |
Definition at line 83 of file itkFEMObjectFactory.h.
|
private |
Type that holds class name as a string.
Definition at line 77 of file itkFEMObjectFactory.h.
|
private |
Private constructor. This class is implemented as a singleton, so we don't allow anybody from outside to construct it.
Definition at line 202 of file itkFEMObjectFactory.h.
|
private |
Private copy constructor.
Definition at line 205 of file itkFEMObjectFactory.h.
|
private |
Private destructor.
Definition at line 208 of file itkFEMObjectFactory.h.
|
inlinestatic |
Find the ID of the class with specified name (this is a slow function). If you have to create many objects of the same class, obtain the class ID with this function first and then use that ID with the Create member function.
Definition at line 125 of file itkFEMObjectFactory.h.
|
staticprivate |
Deletes the object in obj member. This function is called when application finishes (atexit() function).
Definition at line 239 of file itkFEMObjectFactory.h.
|
inlinestatic |
Create a new object based on class identifier id and return a pointer to it.
Definition at line 90 of file itkFEMObjectFactory.h.
|
inlinestatic |
Return the name of the class (as a string) for the given ID.
Definition at line 114 of file itkFEMObjectFactory.h.
|
inlinestaticprivate |
Access to the only instance of the FEMObjectFactory object.
Create a new FEMObjectFactory object if we don't have it already.
Make sure that the object that ws just created is also destroyed when program finishes.
Return the actual FEMObjectFactory object
Definition at line 215 of file itkFEMObjectFactory.h.
Referenced by itk::fem::FEMObjectFactory< FEMLightObject >::ClassName2ID(), itk::fem::FEMObjectFactory< FEMLightObject >::Create(), itk::fem::FEMObjectFactory< FEMLightObject >::ID2ClassName(), and itk::fem::FEMObjectFactory< FEMLightObject >::Register().
|
inlinestatic |
Register the class with the factory. A pointer to a 'create' function and class name as a string must be provided. Function returns the newly assigned ID of the class, which can be later used to create objects of that class.
Definition at line 101 of file itkFEMObjectFactory.h.
|
friend |
By defining a Dummy friend class, some warnings in gcc about destructor being private are eliminated.
Definition at line 193 of file itkFEMObjectFactory.h.
|
private |
Array that stores pairs of create functions and class names.
Definition at line 141 of file itkFEMObjectFactory.h.
Referenced by itk::fem::FEMObjectFactory< FEMLightObject >::ClassName2ID(), itk::fem::FEMObjectFactory< FEMLightObject >::Create(), itk::fem::FEMObjectFactory< FEMLightObject >::ID2ClassName(), and itk::fem::FEMObjectFactory< FEMLightObject >::Register().
|
mutableprivate |
Mutex lock to protect modification to the cofs_ array during class registration.
Definition at line 147 of file itkFEMObjectFactory.h.
Referenced by itk::fem::FEMObjectFactory< FEMLightObject >::Register().
|
staticprivate |
Pointer to the only instance of the FEMObjectFactory class.
Definition at line 179 of file itkFEMObjectFactory.h.