104#include <type_traits>
151 template<
typename FUN>
155 creator_ = std::forward<FUN> (ctor);
158 template<
typename FUN>
175 throw error::Fatal(
"Service not available at this point of the Application Lifecycle"
180 template<
typename FUN>
187 deleter_ = [oldDeleter, additionalAction]
194 deleter_ = std::forward<FUN> (additionalAction);
200 creator_ = std::move (source.creator_);
201 deleter_ = std::move (source.deleter_);
210 OBJ* obj = buildInstance<OBJ>();
216 template<
class X,
typename = decltype(X())>
227 : decltype(__try_instantiate<X>(0))
244 throw error::Fatal(
"Attempt to create a singleton instance of an abstract class. "
245 "Application architecture or lifecycle is seriously broken.");
252 throw error::Fatal(
"Desired singleton class is not default constructible. "
253 "Application architecture or lifecycle is seriously broken.");
293 return sharedFactory;
309 SRV*
object =
instance.load (std::memory_order_acquire);
315 object =
instance.load (std::memory_order_relaxed);
318 object =
factory().buildTarget();
322 instance.store (
object, std::memory_order_release);
334 operator bool()
const
336 return instance.load (std::memory_order_acquire);
A synchronisation protection guard employing a lock scoped to the parameter type as a whole,...
This framework allows to (re)configure the lib::Depend front-end for dependency-injection.
Access point to singletons and other kinds of dependencies designated by type.
SRV & operator()()
Interface to be used by clients for retrieving the service instance.
static Instance instance
shared per type
ClassLock< SRV, NonrecursiveLock_NoWait > Lock
std::atomic< SRV * > Instance
DependencyFactory< SRV > Factory
static Factory & factory()
Helper to abstract creation and lifecycle of a dependency.
void transferDefinition(DependencyFactory &&source)
static std::true_type __try_instantiate(int)
std::function< void()> Deleter
std::function< OBJ *()> Creator
static meta::disable_if< std::__or_< std::is_abstract< ABS >, canDefaultConstruct< ABS > >, ABS * > buildInstance()
void atDestruction(FUN &&additionalAction)
static std::false_type __try_instantiate(...)
DependencyFactory()=default
void defineCreator(FUN &&ctor)
void defineCreatorAndManage(FUN &&ctor)
static meta::enable_if< canDefaultConstruct< TAR >, TAR * > buildInstance()
static meta::enable_if< std::is_abstract< ABS >, ABS * > buildInstance()
Automatic lifecycle tracker, to produce an alarm when accessing objects after deletion.
Any copy and copy construction prohibited.
Lumiera error handling (C++ interface).
Implementation namespace for support and library code.
LumieraError< LERR_(FATAL), Logic > Fatal
Trigger the basic NoBug initialisation by placing a static variable.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
metafunction: can we instantiate the desired object here?
A special implementation of lib::Sync, where the storage of the object monitor is associated directly...
Detector to set off alarm when (re)using deceased objects.