SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
|
A Factory is a class that constructs instances of registered classes which all inherit a common BaseType. More...
#include <Factory.h>
Public Member Functions | |
template<typename Type > | |
bool | registerType () |
Register a Type to the factory. | |
bool | registerType (Metadata &&metadata) |
Register a Typeusing the Type's Metadata. | |
template<typename Tuple > | |
bool | registerTypes () |
Register a tuple of Types. | |
template<typename Type > | |
bool | unregisterType () |
Unregister a Type. | |
bool | unregisterType (const std::string &typeName) |
Unregister a Type using its type name. | |
bool | unregisterType (const std::size_t &typeIndex) |
Unregister a Type using its type index. | |
template<typename Tuple > | |
bool | unregisterTypes () |
Unregister a tuple of Types. | |
template<typename Type > | |
bool | contains () const |
Determine whether or not a Type is available. | |
bool | contains (const std::string &typeName) const |
Determine whether or not a Type is available using its type name. | |
bool | contains (const std::size_t typeIndex) const |
Determine whether or not a Type is available using its type index. | |
template<typename Type , typename... Args> | |
std::unique_ptr< Type > | create (Args &&... args) const |
Create an instance of a Type. | |
template<typename... Args> | |
std::unique_ptr< BaseType > | createFromName (const std::string &typeName, Args &&... args) const |
Create an instance of a Type using its type name. | |
template<typename... Args> | |
std::unique_ptr< BaseType > | createFromIndex (const std::size_t &typeIndex, Args &&... args) const |
Create an instance of a Type using its type name. | |
template<typename Type , typename... Args> | |
std::shared_ptr< Type > | make (Args &&... args) const |
Make a shared instance of a Type. | |
template<typename... Args> | |
std::shared_ptr< BaseType > | makeFromName (const std::string &typeName, Args &&... args) const |
Make a shared instance of a Type using its type name. | |
template<typename... Args> | |
std::shared_ptr< BaseType > | makeFromIndex (const std::size_t &typeIndex, Args &&... args) const |
Create an instance of a Type using its type name. | |
template<typename TagType > | |
Interface< TagType, true > | get () const |
Access a convenience Interface for creating objects that singles out one of the three modes of creation: by type, by type name and by type index. | |
A Factory is a class that constructs instances of registered classes which all inherit a common BaseType.
A class can be created by keying off of its type (as a template parameter), its type-index (an integer hash of its type name), or its type name. Additionally, instance constructors with several input signatures (InputTypes) of arbitrary length can be provided to the Factory instance at compile-time.
The factory provides two sets of calls:
create
return unique pointers to the instances they create.make
return shared pointers to the instances they create.The latter is sometimes necessary as some compilers are unable to properly convert unique pointers to shared pointers (i.e., when an explicit default deleter is used).
Here is an example of its use: