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);
67 <<
"Product for Factory " << meta::type_name<Base>() <<
" was not registered!";
72 <<
"Product " <<
s <<
" for Factory " << meta::type_name<Base>()
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)...); };
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>
143 virtual const Identification1
getFirstID()
const = 0;
145 virtual const Identification2
getSecondID()
const = 0;
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;
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>>>