VR-Engage  2.2
Loading...
Searching...
No Matches
makVre::DtFactory< BASE_T > Class Template Reference

Detailed Description

template<typename BASE_T>
class makVre::DtFactory< BASE_T >

This template provides a factory for creating objects that inherit from a common base class. It maintains a map of creator objects indexed by name.

Template Parameters
BASE_TThe base type that all created objects will inherit from

#include <factory.h>

Inheritance diagram for makVre::DtFactory< BASE_T >:
[legend]

Public Types

using CreatorMap = std::map<std::string, DtBaseCreator<BASE_T>*>
 

Public Member Functions

 DtFactory ()
 
virtual ~DtFactory ()
 
template<typename CREATE_T>
void addCreator (std::string name="")
 
BASE_T * create (std::string name)
 
CreatorMapcreatorMap ()
 

Protected Attributes

CreatorMap myCreators
 

Member Typedef Documentation

◆ CreatorMap

template<typename BASE_T>
using makVre::DtFactory< BASE_T >::CreatorMap = std::map<std::string, DtBaseCreator<BASE_T>*>

Type alias for the map of creators.

Constructor & Destructor Documentation

◆ DtFactory()

template<typename BASE_T>
makVre::DtFactory< BASE_T >::DtFactory ( )
inline

Default constructor.

◆ ~DtFactory()

template<typename BASE_T>
virtual makVre::DtFactory< BASE_T >::~DtFactory ( )
inlinevirtual

Virtual destructor.

Cleans up all registered creators

Member Function Documentation

◆ addCreator()

template<typename BASE_T>
template<typename CREATE_T>
void makVre::DtFactory< BASE_T >::addCreator ( std::string name = "")
inline

Registers a creator for a specific type.

Adds a creator to the factory, allowing objects of that type to be created by name. If a creator with the same name already exists, it will be replaced, but a warning will only be logged if the new creator is of a different type.

Template Parameters
CREATE_TThe concrete type to register, must inherit from BASE_T
Parameters
nameThe name to register the creator under. If empty, the typeid name is used.

◆ create()

template<typename BASE_T>
BASE_T * makVre::DtFactory< BASE_T >::create ( std::string name)
inline

Creates an object by name.

Parameters
nameThe registered name of the creator to use
Returns
A pointer to the newly created object, or NULL if no creator is found

◆ creatorMap()

template<typename BASE_T>
CreatorMap & makVre::DtFactory< BASE_T >::creatorMap ( )
inline

Gets the map of registered creators.

Returns
A reference to the map of creators

Member Data Documentation

◆ myCreators

template<typename BASE_T>
CreatorMap makVre::DtFactory< BASE_T >::myCreators
protected

Map of creator objects indexed by name.


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