30 #ifndef EXOTICA_CORE_FACTORY_H_ 31 #define EXOTICA_CORE_FACTORY_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_
std::map< std::string, BaseClass *(*)()> type_registry_
The Map containing the register of the different types of classes.
Registration Class for the object type: Also templated:
std::shared_ptr< BaseClass > CreateInstance(const std::string &type)
Templated Object factory for Default-constructible classes. The Factory is itself a singleton...
Registrar(const std::string &name, BaseClass *(*creator)(), const std::string &base_type)
Public Constructor which is only used to register the new task type.
virtual std::string type() const
Type Information wrapper: must be virtual so that it is polymorphic...
void RegisterType(const std::string &type, BaseClass *(*creator_function)())
Registers a new derived class type.
std::vector< std::string > GetDeclaredClasses()
Lists the valid implementations which are available and registered.
static Factory< BaseClass > & Instance(void)
Singleton implementation: returns a reference to a singleton instance of the instantiated class...