29#include <unordered_map>
31#include <boost/version.hpp>
35#if (BOOST_VERSION < 106701)
37#include <boost/functional/hash.hpp>
40#include <boost/container_hash/hash.hpp>
51 template <
class Base,
typename Identification,
class... Args>
55 virtual const Identification
getID()
const = 0;
60 make(
const Identification& s, Args&&... args)
63 auto itr = data().find(s);
73 <<
" was not registered!";
75 return itr->second(std::forward<Args>(args)...);
78 template <
typename Derived>
88 constexpr auto name = Derived::id;
89 Factory::data()[name] = [](Args... args) -> std::unique_ptr<Base>
90 {
return std::make_unique<Derived>(std::forward<Args>(args)...); };
110 explicit Registrar(Registration) : Base(Key{})
122 template <
typename T>
126 using FuncType = std::unique_ptr<Base> (*)(Args...);
134 static std::unordered_map<Identification, FuncType> s;
139 template <
class Base,
typename Identification1,
typename Identification2,
class... Args>
150 make(
const Identification1& f,
const Identification2& s, Args&&... args)
153 auto itr = data().find(std::make_pair(f, s));
154 ARMARX_CHECK(itr != data().end()) <<
"Product was not registered!";
155 return itr->second(std::forward<Args>(args)...);
158 template <
typename Derived>
168 constexpr auto name = std::make_pair(Derived::idDimOne, Derived::idDimTwo);
169 Factory2D::data()[name] = [](Args... args) -> std::unique_ptr<Base>
170 {
return std::make_unique<Derived>(std::forward<Args>(args)...); };
176 const Identification1
179 return Derived::idDimOne;
182 const Identification2
185 return Derived::idDimTwo;
196 explicit Registrar(Registration) : Base(Key{})
208 template <
typename T>
212 using FuncType = std::unique_ptr<Base> (*)(Args...);
220 static std::unordered_map<std::pair<Identification1, Identification2>,
222 boost::hash<std::pair<Identification1, Identification2>>>
static auto make(const Identification1 &f, const Identification2 &s, Args &&... args)
virtual const Identification2 getSecondID() const =0
virtual ~Factory2D()=default
virtual const Identification1 getFirstID() const =0
virtual ~Factory()=default
static auto make(const Identification &s, Args &&... args)
virtual const Identification getID() const =0
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
This file offers overloads of toIce() and fromIce() functions for STL container types.
const Identification1 getFirstID() const override
const Identification2 getSecondID() const override
static const bool registered
const Identification getID() const override
static const bool registered