52 #ifndef LIB_MULTIFACT_H 53 #define LIB_MULTIFACT_H 78 template<
typename TAR>
83 typedef TAR ResultType;
85 template<
class FUN,
typename... ARGS>
87 wrap (FUN create, ARGS&&... args) noexcept
89 return create(std::forward<ARGS>(args)...);
98 template<
typename RAW>
101 using RawType =
typename std::remove_pointer<RAW>::type;
102 using BareType = RawType *;
105 template<
class FUN,
typename... ARGS>
107 wrap (FUN create, ARGS&&... args)
109 return ResultType (create(std::forward<ARGS>(args)...));
125 template<
typename TAR>
128 template<
typename RAW>
132 using BareType = RAW;
133 using ResultType = TAR;
135 using WrapFunc = std::function<ResultType(BareType)>;
138 defineFinalWrapper (WrapFunc&& fun)
140 this->wrapper_ = fun;
143 template<
class FUN,
typename... ARGS>
145 wrap (FUN create, ARGS&&... args)
147 return wrapper_(std::forward<BareType> (create(std::forward<ARGS>(args)...)));
165 template<
typename SIG,
typename ID>
168 typedef std::function<SIG> FactoryFunc;
172 select (ID
const&
id)
177 return producerTable_[id];
181 defineProduction (ID
const&
id, FactoryFunc fun)
183 producerTable_[id] = fun;
189 bool empty ()
const {
return producerTable_.empty(); }
190 bool contains (ID
id)
const {
return util::contains (producerTable_,
id); }
193 std::map<ID, FactoryFunc> producerTable_;
202 template<
typename TY
203 ,
template<
class>
class Wrapper
207 using WrapFunctor = Wrapper<TY>;
208 using BareProduct =
typename WrapFunctor::BareType;
211 typedef BareProduct SIG_Fab(
void);
213 enum{ ARGUMENT_CNT = 0 };
219 template<
typename RET
221 ,
template<
class>
class Wrapper
225 using WrapFunctor = Wrapper<RET>;
226 using BareProduct =
typename WrapFunctor::BareType;
229 typedef BareProduct SIG_Fab(ARGS...);
231 enum{ ARGUMENT_CNT =
sizeof...(ARGS)};
249 template<
typename SIG
251 ,
template<
class>
class Wrapper =
PassAsIs 254 :
public FabConfig<SIG,Wrapper>::WrapFunctor
257 using SIG_Fab =
typename _Conf::SIG_Fab;
264 using Creator =
typename _Fab::FactoryFunc;
267 selectProducer (ID
const&
id)
269 return funcTable_.select(
id);
274 using Product =
typename _Conf::WrappedProduct;
285 template<
typename... ARGS>
287 operator() (ID
const&
id, ARGS&& ...args)
289 static_assert (
sizeof...(ARGS) == _Conf::ARGUMENT_CNT,
290 "MultiFac instance invoked with the wrong number " 291 "of fabrication arguments. See template parameter SIG");
293 Creator& creator = selectProducer (
id);
294 return this->wrap (creator, std::forward<ARGS>(args)...);
298 template<
typename... ARGS>
302 return this->operator() (
id, std::forward<ARGS>(args)...);
309 template<
typename FUNC>
313 funcTable_.defineProduction (
id, fun);
329 createSingleton_accessFunction()
331 return std::bind (&SingleFact::operator()
332 , static_cast<SingleFact*>(
this));
345 bool empty ()
const {
return funcTable_.empty(); }
346 bool contains (ID
id)
const {
return funcTable_.contains (
id); }
Dummy "wrapper", to perform the fabrication and return the unaltered product.
Policy: use a custom functor to finish the generated product.
Access point to singletons and other kinds of dependencies designated by type.
lib::TypedContext< Goal::Result > ResultType
Context used for generating type-IDs to denote the specific result types of issued queries...
Implementation namespace for support and library code.
Derived specific exceptions within Lumiera's exception hierarchy.
Factory for creating a family of objects by ID.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Singleton services and Dependency Injection.
void defineProduction(ID id, FUNC &&fun)
to set up a production line, associated with a specific ID
Lumiera error handling (C++ interface).
Table of registered production functions for MultiFact.
Wrapper taking ownership, by wrapping into smart-ptr.
Convenience shortcut for automatically setting up a production line, to fabricate a singleton instanc...
Product invokeFactory(ID const &id, ARGS &&...args)
more legible alias for the function operator