AbstractFactoryMethod< Base, constructorArg, SharedPointer > Class Template Reference

A template that can be used as a superclass of a class hierarchy that wants to provide a factory method which allows instantiation of objects based on a string identifier. More...

#include <ArmarXCore/core/system/AbstractFactoryMethod.h>

Classes

struct  SubClassRegistry
 A helper struct to allow static initialisation of the subclass lookup table. More...
 

Public Types

using BaseFactory = Base
 
using ConstructorArg = constructorArg
 
typedef SharedPointerType(* initialisationFunction) (constructorArg)
 The function pointer type of subclass initialisation functions.
 
using SharedPointerType = SharedPointer
 

Public Member Functions

std::string getClassName ()
 getClassName returns the name that this instance was generated with.
 

Static Public Member Functions

static SharedPointerType createInstance (constructorArg)
 Initialisation function which needs to be provided by every subclass.
 
static SharedPointerType fromName (const std::string &name, constructorArg params)
 Function which can be used to retrieve an object specified by string name.
 
static std::vector< std::string > getAvailableClasses ()
 getAvailableClasses retrieves a list of all registered classes as their string-representation.
 
static std::string getName ()
 Returns the class's name.
 
static void registerClass (const std::string &name, initialisationFunction init)
 Statically called by subclasses to register their name and initialisation function so they can be found by fromName.
 

Detailed Description

template<typename Base, typename constructorArg, typename SharedPointer = std::shared_ptr<Base>>
class armarx::AbstractFactoryMethod< Base, constructorArg, SharedPointer >

A template that can be used as a superclass of a class hierarchy that wants to provide a factory method which allows instantiation of objects based on a string identifier.

The first template argument is the base class of your class hierarchy. The second argument is the parameter type for the initialisation function each subclass has to provide. If you need multiple constructor arguments it is recommended to use a boost::tuple.

Member Typedef Documentation

◆ BaseFactory

template<typename Base, typename constructorArg, typename SharedPointer = std::shared_ptr<Base>>
using BaseFactory = Base

◆ ConstructorArg

template<typename Base, typename constructorArg, typename SharedPointer = std::shared_ptr<Base>>
using ConstructorArg = constructorArg

◆ initialisationFunction

template<typename Base, typename constructorArg, typename SharedPointer = std::shared_ptr<Base>>
typedef SharedPointerType(* initialisationFunction) (constructorArg)

The function pointer type of subclass initialisation functions.

This matches the createInstance method.

◆ SharedPointerType

template<typename Base, typename constructorArg, typename SharedPointer = std::shared_ptr<Base>>
using SharedPointerType = SharedPointer

Member Function Documentation

◆ createInstance()

template<typename Base, typename constructorArg, typename SharedPointer = std::shared_ptr<Base>>
static SharedPointerType createInstance ( constructorArg )
inlinestatic

Initialisation function which needs to be provided by every subclass.

It calls the constructor and returns a shared_ptr to the resulting object.

◆ fromName()

template<typename Base, typename constructorArg, typename SharedPointer = std::shared_ptr<Base>>
static SharedPointerType fromName ( const std::string & name,
constructorArg params )
inlinestatic

Function which can be used to retrieve an object specified by string name.

◆ getAvailableClasses()

template<typename Base, typename constructorArg, typename SharedPointer = std::shared_ptr<Base>>
static std::vector< std::string > getAvailableClasses ( )
inlinestatic

getAvailableClasses retrieves a list of all registered classes as their string-representation.

Returns
list of available classes by their name.

◆ getClassName()

template<typename Base, typename constructorArg, typename SharedPointer = std::shared_ptr<Base>>
std::string getClassName ( )
inline

getClassName returns the name that this instance was generated with.

Returns
name of class

◆ getName()

template<typename Base, typename constructorArg, typename SharedPointer = std::shared_ptr<Base>>
static std::string getName ( )
inlinestatic

Returns the class's name.

This is used to identify the class which the user requests an instance of.

◆ registerClass()

template<typename Base, typename constructorArg, typename SharedPointer = std::shared_ptr<Base>>
static void registerClass ( const std::string & name,
initialisationFunction init )
inlinestatic

Statically called by subclasses to register their name and initialisation function so they can be found by fromName.


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