iMSTK
Interactive Medical Simulation Toolkit
Public Types | Static Public Member Functions | List of all members
imstk::ObjectFactory< T, Args > Class Template Reference

Generic Factory class that can take objects with constructor parameters. More...

#include <imstkFactory.h>

Public Types

using BaseType = T
 
using Creator = std::function< T(Args...)>
 Type of the function to generate a new object.
 

Static Public Member Functions

static T create (const std::string &name, Args &&... args)
 tries to construct the object give name, it will forward the given paramters More...
 
static void add (const std::string &name, Creator c)
 adds a new creation function to the factory More...
 
static bool contains (const std::string &name)
 
static const std::vector< std::string > getNames ()
 

Detailed Description

template<typename T, class ... Args>
class imstk::ObjectFactory< T, Args >

Generic Factory class that can take objects with constructor parameters.

All the objects in the factory need to be convertible to a common base class

Template Parameters
TThe base class type, is also the return type of create()
ArgsParameter pack argument for the list of params used to pass into create

Definition at line 24 of file imstkFactory.h.

Member Function Documentation

◆ add()

template<typename T, class ... Args>
static void imstk::ObjectFactory< T, Args >::add ( const std::string &  name,
Creator  c 
)
inlinestatic

adds a new creation function to the factory

Parameters
nameName to use, will overwrite an already defined name
cfunction to be called when create() is called with the given name

Definition at line 44 of file imstkFactory.h.

Here is the caller graph for this function:

◆ contains()

template<typename T, class ... Args>
static bool imstk::ObjectFactory< T, Args >::contains ( const std::string &  name)
inlinestatic
Returns
true if the name can be found in the registry

Definition at line 50 of file imstkFactory.h.

◆ create()

template<typename T, class ... Args>
static T imstk::ObjectFactory< T, Args >::create ( const std::string &  name,
Args &&...  args 
)
inlinestatic

tries to construct the object give name, it will forward the given paramters

Parameters
nameName to use for lookup
argsparameters to pass into the creation function
Exceptions
ifname was not registered

Definition at line 35 of file imstkFactory.h.

◆ getNames()

template<typename T, class ... Args>
static const std::vector<std::string> imstk::ObjectFactory< T, Args >::getNames ( )
inlinestatic
Returns
a list of all registered names in the registry

Definition at line 56 of file imstkFactory.h.


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