Exotica
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
exotica::Factory< BaseClass > Class Template Reference

Templated Object factory for Default-constructible classes. The Factory is itself a singleton. More...

#include <factory.h>

Inheritance diagram for exotica::Factory< BaseClass >:
Inheritance graph
Collaboration diagram for exotica::Factory< BaseClass >:
Collaboration graph

Public Member Functions

void RegisterType (const std::string &type, BaseClass *(*creator_function)())
 Registers a new derived class type. More...
 
std::shared_ptr< BaseClass > CreateInstance (const std::string &type)
 
std::vector< std::string > GetDeclaredClasses ()
 Lists the valid implementations which are available and registered. More...
 
- Public Member Functions inherited from exotica::Object
 Object ()
 
virtual ~Object ()
 
virtual std::string type () const
 Type Information wrapper: must be virtual so that it is polymorphic... More...
 
std::string GetObjectName ()
 
void InstantiateObject (const Initializer &init)
 
virtual std::string Print (const std::string &prepend) const
 

Static Public Member Functions

static Factory< BaseClass > & Instance (void)
 Singleton implementation: returns a reference to a singleton instance of the instantiated class. More...
 

Private Member Functions

 Factory ()
 Private Constructor. More...
 

Private Attributes

std::map< std::string, BaseClass *(*)()> type_registry_
 The Map containing the register of the different types of classes. More...
 
std::string base_type_
 

Friends

class Registrar< BaseClass >
 

Additional Inherited Members

- Public Attributes inherited from exotica::Object
std::string ns_
 
std::string object_name_
 
bool debug_
 

Detailed Description

template<class BaseClass>
class exotica::Factory< BaseClass >

Templated Object factory for Default-constructible classes. The Factory is itself a singleton.

Parameters
BaseClassThe Base Object type

Constructor & Destructor Documentation

◆ Factory()

template<class BaseClass >
exotica::Factory< BaseClass >::Factory ( )
inlineexplicitprivate

Private Constructor.

Member Function Documentation

◆ CreateInstance()

template<class BaseClass >
std::shared_ptr<BaseClass> exotica::Factory< BaseClass >::CreateInstance ( const std::string &  type)
inline

◆ GetDeclaredClasses()

template<class BaseClass >
std::vector<std::string> exotica::Factory< BaseClass >::GetDeclaredClasses ( )
inline

Lists the valid implementations which are available and registered.

◆ Instance()

template<class BaseClass >
static Factory<BaseClass>& exotica::Factory< BaseClass >::Instance ( void  )
inlinestatic

Singleton implementation: returns a reference to a singleton instance of the instantiated class.

< Declared static so will only be created once

< At other times, just return the reference to it

◆ RegisterType()

template<class BaseClass >
void exotica::Factory< BaseClass >::RegisterType ( const std::string &  type,
BaseClass *(*)()  creator_function 
)
inline

Registers a new derived class type.

Parameters
type[in]The name of the class (string): must be a unique identifier
creator[in]A pointer to the creator function

< If it does not already exist

Friends And Related Function Documentation

◆ Registrar< BaseClass >

template<class BaseClass >
friend class Registrar< BaseClass >
friend

Member Data Documentation

◆ base_type_

template<class BaseClass >
std::string exotica::Factory< BaseClass >::base_type_
private

◆ type_registry_

template<class BaseClass >
std::map<std::string, BaseClass* (*)()> exotica::Factory< BaseClass >::type_registry_
private

The Map containing the register of the different types of classes.


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