Factory of typed objects.
More...
#include <geogram/basic/factory.h>
|
typedef FactoryCreator::CreatorType | CreatorType |
|
|
void | ref () const |
| Increments the reference count. More...
|
|
void | unref () const |
| Decrements the reference count. More...
|
|
bool | is_shared () const |
| Check if the object is shared. More...
|
|
int | nb_refs () const |
| Gets the number of references that point to this object. More...
|
|
template<class FactoryCreator>
class GEO::Factory< FactoryCreator >
Factory of typed objects.
A Factory is a mechanism to create objects without knowing their types in advance. The object types that a Factory can instantiate belong to a type hierarchy whose base type is defined by Type
. The Factory uses a registry of creator functions bound to user-defined names. The user-defined names can be used to:
- register a creator function (see register_creator())
- create an object, using the creator function bound to the name (see create_object())
- Template Parameters
-
FactoryCreator | the type of the creator used to create objects in this Factory. FactoryCreator must define: |
- the type CreatorType type of the creation function
- a static template function create(...) used to actually create objects of a given concrete type
Definition at line 137 of file factory.h.
◆ find_creator()
template<class FactoryCreator >
static CreatorType GEO::Factory< FactoryCreator >::find_creator |
( |
const std::string & |
name | ) |
|
|
inlinestatic |
Finds a creator by name.
- Parameters
-
[in] | name | a user-defined name identifying a creator in the Factory |
- Return values
-
the | creator associated to name if name exists |
null | pointer otherwise |
Definition at line 171 of file factory.h.
◆ has_creator()
template<class FactoryCreator >
static bool GEO::Factory< FactoryCreator >::has_creator |
( |
const std::string & |
name | ) |
|
|
inlinestatic |
Tests whether the factory has a creator.
- Parameters
-
[in] | name | name of the creator |
- Return values
-
true | if creator name is registered in the factory |
false | otherwise |
Definition at line 196 of file factory.h.
◆ list_creators()
template<class FactoryCreator >
static void GEO::Factory< FactoryCreator >::list_creators |
( |
std::vector< std::string > & |
names | ) |
|
|
inlinestatic |
Lists all registered creators.
This stores the names of the registered creators to output vector names
.
- Parameters
-
[out] | names | output list of registered names |
Definition at line 183 of file factory.h.
◆ register_creator()
template<class FactoryCreator >
template<class ConcreteType >
static void GEO::Factory< FactoryCreator >::register_creator |
( |
const std::string & |
name | ) |
|
|
inlinestatic |
Registers a creator.
This creates a new creator for objects of type ConcreteType
and registers it with the user-defined name name
.
- Parameters
-
[in] | name | name of the ConcreteType creator in the Factory |
- Template Parameters
-
ConcreteType | the type of the objects to create |
- Usage example:
struct MyBaseClass { ... };
typedef Factory<MyBaseClass> MyFactory;
struct MyDerivedClass : MyBaseClass { ... };
MyFactory::register_creator<MyDerivedClass>("my_derived_class");
- See also
- RegisterCreator()
Definition at line 158 of file factory.h.
The documentation for this class was generated from the following file: