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
[legend]

Public Member Functions

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

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

Friends

class Registrar< BaseClass >
 

Additional Inherited Members

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

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

Definition at line 61 of file factory.h.

Constructor & Destructor Documentation

◆ Factory()

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

Private Constructor.

Definition at line 114 of file factory.h.

Member Function Documentation

◆ CreateInstance()

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

Definition at line 88 of file factory.h.

◆ GetDeclaredClasses()

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

Lists the valid implementations which are available and registered.

Definition at line 102 of file factory.h.

◆ 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

Definition at line 67 of file factory.h.

◆ 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

Definition at line 76 of file factory.h.

Friends And Related Function Documentation

◆ Registrar< BaseClass >

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

Definition at line 64 of file factory.h.

Member Data Documentation

◆ base_type_

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

Definition at line 120 of file factory.h.

◆ 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.

Definition at line 119 of file factory.h.


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


exotica_core
Author(s): Yiming Yang, Michael Camilleri
autogenerated on Fri Aug 2 2024 08:43:03