Go to the documentation of this file.
30 #ifndef EXOTICA_CORE_FACTORY_H_
31 #define EXOTICA_CORE_FACTORY_H_
40 #include <pluginlib/class_list_macros.h>
47 #define EXOTICA_CORE_REGISTER(BASE, TYPE, DERIV) \
48 static exotica::Registrar<BASE> EX_UNIQ(object_registrar_, __LINE__)("exotica/" TYPE, []() -> BASE* { return new DERIV(); }, #BASE); \
49 PLUGINLIB_EXPORT_CLASS(DERIV, BASE)
51 #define EXOTICA_CORE_REGISTER_CORE(BASE, TYPE, DERIV) static exotica::Registrar<BASE> EX_UNIQ(object_registrar_, __LINE__)("exotica/" TYPE, []() -> BASE* { return new DERIV(); }, #BASE);
55 template <
typename BaseClass>
60 template <
class BaseClass>
84 ThrowPretty(
"Trying to register already existing type '" <<
type <<
"'!");
93 return std::shared_ptr<BaseClass>(it->second());
104 std::vector<std::string> DeclaredClasses;
107 DeclaredClasses.push_back(it->first);
109 return DeclaredClasses;
126 template <
typename BaseClass>
133 Registrar(
const std::string& name, BaseClass* (*creator)(),
const std::string& base_type)
141 #endif // EXOTICA_CORE_FACTORY_H_
virtual std::string type() const
Type Information wrapper: must be virtual so that it is polymorphic...
Definition: object.h:61
void RegisterType(const std::string &type, BaseClass *(*creator_function)())
Registers a new derived class type.
Definition: factory.h:76
Templated Object factory for Default-constructible classes. The Factory is itself a singleton.
Definition: factory.h:61
Definition: cartpole_dynamics_solver.h:38
static Factory< BaseClass > & Instance(void)
Singleton implementation: returns a reference to a singleton instance of the instantiated class.
Definition: factory.h:67
std::string base_type_
Definition: factory.h:120
Registration Class for the object type: Also templated:
Definition: factory.h:56
#define ThrowPretty(m)
Definition: exception.h:36
Registrar(const std::string &name, BaseClass *(*creator)(), const std::string &base_type)
Public Constructor which is only used to register the new task type.
Definition: factory.h:133
std::map< std::string, BaseClass *(*)()> type_registry_
The Map containing the register of the different types of classes.
Definition: factory.h:119
std::shared_ptr< BaseClass > CreateInstance(const std::string &type)
Definition: factory.h:88
std::vector< std::string > GetDeclaredClasses()
Lists the valid implementations which are available and registered.
Definition: factory.h:102