ImFusion SDK 4.3
Factory< Base, Params > Class Template Reference

#include <AnatomyPlugin/include/ImFusion/AnatomyPlugin/GenericFactory.h>

Generic factory class for registering polymorphic types Usage: More...

Detailed Description

template<typename Base, typename... Params>
class ImFusion::AnatomyPlugin::Factory< Base, Params >

Generic factory class for registering polymorphic types Usage:

class BaseItem {
BaseItem(int value);
...
};
class DerivedItem : BaseItem {
DerivedItem();
void configure(const Properties& p);
...
};
using ItemFactory = Factory<BaseItem, int>;
ItemFactory factory;
Generic factory class for registering polymorphic types Usage:
Definition GenericFactory.h:159
Storage container for serialization of arbitrary types, internally backed by strings.
Definition Properties.h:50

In this situation you can register DerivedItems as follow: 1) Using the direct constructor:

factory.registerType<DerivedItem>("int_ctor");

2) Using a builder function:

auto builder = [](int value) {
p.setParam("value", value);
obj->configure(p);
return obj;
};
factory.registerType<DerivedItem>("property_ctor", builder);
void setParam(const std::string &name, const T &value, const T &defaultValue)
Set a parameter with arbitrary type and a default value.
Definition Properties.h:424
T make_unique(T... args)

Public Types

using CreatorRegistry = std::unordered_map<std::string, detail::Creator<Base, Params...>*>
 
template<typename Derived>
using Builder = typename detail::CreatorImpl<Derived, Base, Params...>::BuilderFunc
 

Public Member Functions

virtual std::unique_ptr< Basecreate (const std::string &name, Params &&... params) const
 
virtual std::vector< std::stringavailableTypes () const
 
virtual bool hasType (const std::string &name) const
 
template<typename Derived>
void registerType (const std::string &name, Builder< Derived > builder)
 register a creator function associated to a specific key
 
template<typename Derived, typename = typename std::enable_if<std::is_constructible<Derived, Params...>::value>::type>
void registerType (const std::string &name)
 Sfinae based register function for registration of object that can be directly constructed from Params...
 

Protected Attributes

CreatorRegistry m_registry
 

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close