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. More...
 
using SharedPointerType = SharedPointer
 

Public Member Functions

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

Static Public Member Functions

static SharedPointerType createInstance (constructorArg)
 Initialisation function which needs to be provided by every subclass. More...
 
static SharedPointerType fromName (const std::string &name, constructorArg params)
 Function which can be used to retrieve an object specified by string name. More...
 
static std::vector< std::string > getAvailableClasses ()
 getAvailableClasses retrieves a list of all registered classes as their string-representation. More...
 
static std::string getName ()
 Returns the class's name. More...
 
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. More...
 

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.

Definition at line 46 of file AbstractFactoryMethod.h.

Member Typedef Documentation

◆ BaseFactory

using BaseFactory = Base

Definition at line 54 of file AbstractFactoryMethod.h.

◆ ConstructorArg

using ConstructorArg = constructorArg

Definition at line 55 of file AbstractFactoryMethod.h.

◆ initialisationFunction

typedef SharedPointerType(* initialisationFunction(constructorArg)

The function pointer type of subclass initialisation functions.

This matches the createInstance method.

Definition at line 71 of file AbstractFactoryMethod.h.

◆ SharedPointerType

using SharedPointerType = SharedPointer

Definition at line 56 of file AbstractFactoryMethod.h.

Member Function Documentation

◆ createInstance()

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.

Definition at line 127 of file AbstractFactoryMethod.h.

◆ fromName()

static SharedPointerType fromName ( const std::string &  name,
constructorArg  params 
)
inlinestatic

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

Definition at line 76 of file AbstractFactoryMethod.h.

◆ getAvailableClasses()

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.

Definition at line 99 of file AbstractFactoryMethod.h.

◆ getClassName()

std::string getClassName ( )
inline

getClassName returns the name that this instance was generated with.

Returns
name of class

Definition at line 62 of file AbstractFactoryMethod.h.

◆ getName()

static std::string getName ( )
inlinestatic

Returns the class's name.

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

Definition at line 117 of file AbstractFactoryMethod.h.

◆ registerClass()

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.

Definition at line 138 of file AbstractFactoryMethod.h.


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