61 #ifndef LIB_MULTIFACT_H 62 #define LIB_MULTIFACT_H 87 template<
typename TAR>
92 typedef TAR ResultType;
94 template<
class FUN,
typename... ARGS>
96 wrap (FUN create, ARGS&&... args) noexcept
98 return create(std::forward<ARGS>(args)...);
107 template<
typename RAW>
110 using RawType =
typename std::remove_pointer<RAW>::type;
111 using BareType = RawType *;
114 template<
class FUN,
typename... ARGS>
116 wrap (FUN create, ARGS&&... args)
118 return ResultType (create(std::forward<ARGS>(args)...));
134 template<
typename TAR>
137 template<
typename RAW>
141 using BareType = RAW;
142 using ResultType = TAR;
144 using WrapFunc = std::function<ResultType(BareType)>;
147 defineFinalWrapper (WrapFunc&& fun)
149 this->wrapper_ = fun;
152 template<
class FUN,
typename... ARGS>
154 wrap (FUN create, ARGS&&... args)
156 return wrapper_(std::forward<BareType> (create(std::forward<ARGS>(args)...)));
174 template<
typename SIG,
typename ID>
177 typedef std::function<SIG> FactoryFunc;
181 select (ID
const&
id)
186 return producerTable_[id];
190 defineProduction (ID
const&
id, FactoryFunc fun)
192 producerTable_[id] = fun;
198 bool empty ()
const {
return producerTable_.empty(); }
199 bool contains (ID
id)
const {
return util::contains (producerTable_,
id); }
202 std::map<ID, FactoryFunc> producerTable_;
211 template<
typename TY
212 ,
template<
class>
class Wrapper
216 using WrapFunctor = Wrapper<TY>;
217 using BareProduct =
typename WrapFunctor::BareType;
220 typedef BareProduct SIG_Fab(
void);
222 enum{ ARGUMENT_CNT = 0 };
228 template<
typename RET
230 ,
template<
class>
class Wrapper
234 using WrapFunctor = Wrapper<RET>;
235 using BareProduct =
typename WrapFunctor::BareType;
238 typedef BareProduct SIG_Fab(ARGS...);
240 enum{ ARGUMENT_CNT =
sizeof...(ARGS)};
258 template<
typename SIG
260 ,
template<
class>
class Wrapper =
PassAsIs 263 :
public FabConfig<SIG,Wrapper>::WrapFunctor
266 using SIG_Fab =
typename _Conf::SIG_Fab;
273 using Creator =
typename _Fab::FactoryFunc;
276 selectProducer (ID
const&
id)
278 return funcTable_.select(
id);
283 using Product =
typename _Conf::WrappedProduct;
294 template<
typename... ARGS>
296 operator() (ID
const&
id, ARGS&& ...args)
298 static_assert (
sizeof...(ARGS) == _Conf::ARGUMENT_CNT,
299 "MultiFac instance invoked with the wrong number " 300 "of fabrication arguments. See template parameter SIG");
302 Creator& creator = selectProducer (
id);
303 return this->wrap (creator, std::forward<ARGS>(args)...);
307 template<
typename... ARGS>
311 return this->operator() (
id, std::forward<ARGS>(args)...);
318 template<
typename FUNC>
322 funcTable_.defineProduction (
id, fun);
338 createSingleton_accessFunction()
340 return std::bind (&SingleFact::operator()
341 , static_cast<SingleFact*>(
this));
354 bool empty ()
const {
return funcTable_.empty(); }
355 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