29 #include <unordered_map>
30 #include <boost/version.hpp>
32 #if (BOOST_VERSION < 106701)
34 #include <boost/functional/hash.hpp>
37 #include <boost/container_hash/hash.hpp>
49 template <
class Base,
typename Identification,
class... Args>
54 virtual const Identification
getID()
const = 0;
58 static auto make(
const Identification&
s, Args&& ... args)
61 auto itr = data().find(
s);
64 ARMARX_CHECK(itr != data().end()) <<
"Product for Factory " << meta::type_name<Base>()
65 <<
" was not registered!";
68 ARMARX_CHECK(itr != data().end()) <<
"Product " <<
s <<
" for Factory " << meta::type_name<Base>()
69 <<
" was not registered!";
71 return itr->second(std::forward<Args>(args)...);
74 template <
typename Derived>
83 constexpr
auto name = Derived::id;
84 Factory::data()[name] = [](Args... args) -> std::unique_ptr<Base>
86 return std::make_unique<Derived>(std::forward<Args>(args)...);
93 const Identification
getID()
const override
122 template <
typename T>
friend
126 using FuncType = std::unique_ptr<Base> (*)(Args...);
133 static std::unordered_map<Identification, FuncType>
s;
138 template <
class Base,
typename Identification1,
typename Identification2,
class... Args>
143 virtual const Identification1
getFirstID()
const = 0;
145 virtual const Identification2
getSecondID()
const = 0;
149 static auto make(
const Identification1& f,
const Identification2&
s, Args&& ... args)
152 auto itr = data().find(std::make_pair(f,
s));
153 ARMARX_CHECK(itr != data().end()) <<
"Product was not registered!";
154 return itr->second(std::forward<Args>(args)...);
157 template <
typename Derived>
166 constexpr
auto name = std::make_pair(Derived::idDimOne, Derived::idDimTwo);
167 Factory2D::data()[name] = [](Args... args) -> std::unique_ptr<Base>
169 return std::make_unique<Derived>(std::forward<Args>(args)...);
178 return Derived::idDimOne;
183 return Derived::idDimTwo;
210 template <
typename T>
friend
214 using FuncType = std::unique_ptr<Base> (*)(Args...);
221 static std::unordered_map<std::pair<Identification1, Identification2>, FuncType,
222 boost::hash<std::pair<Identification1, Identification2>>>
s;