104 #include <type_traits> 105 #include <functional> 128 using Creator = std::function<OBJ*()>;
129 using Deleter = std::function<void()>;
147 return creator_? creator_()
151 template<
typename FUN>
153 defineCreator (FUN&& ctor)
155 creator_ = std::forward<FUN> (ctor);
158 template<
typename FUN>
160 defineCreatorAndManage (FUN&& ctor)
162 creator_ = [
this,ctor]
165 atDestruction ([obj]{
delete obj; });
173 creator_ = []() -> OBJ*
175 throw error::Fatal(
"Service not available at this point of the Application Lifecycle" 180 template<
typename FUN>
182 atDestruction (FUN&& additionalAction)
186 Deleter oldDeleter{std::move (deleter_)};
187 deleter_ = [oldDeleter, additionalAction]
194 deleter_ = std::forward<FUN> (additionalAction);
200 creator_ = std::move (source.creator_);
201 deleter_ = std::move (source.deleter_);
202 source.creator_ = Creator();
203 source.deleter_ = Deleter();
210 OBJ* obj = buildInstance<OBJ>();
211 atDestruction ([obj]{
delete obj; });
216 template<
class X,
typename = decltype(X())>
217 static std::true_type __try_instantiate(
int);
219 static std::false_type __try_instantiate(...);
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.");
282 using Instance = std::atomic<SRV*>;
293 return sharedFactory;
309 SRV*
object = instance.load (std::memory_order_acquire);
312 factory().zombieCheck();
315 object = instance.load (std::memory_order_relaxed);
318 object = factory().buildTarget();
320 factory().atDestruction([]{ instance =
nullptr; });
322 instance.store (
object, std::memory_order_release);
334 operator bool()
const 336 return instance.load (std::memory_order_acquire);
344 factory().zombieCheck();
static Instance instance
shared per type
Trigger the basic NoBug initialisation by placing a static variable.
Any copy and copy construction prohibited.
Access point to singletons and other kinds of dependencies designated by type.
Implementation namespace for support and library code.
Derived specific exceptions within Lumiera's exception hierarchy.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
This framework allows to (re)configure the lib::Depend front-end for dependency-injection.
metafunction: can we instantiate the desired object here?
A special implementation of lib::Sync, where the storage of the object monitor is associated directly...
Automatic lifecycle tracker, to produce an alarm when accessing objects after deletion.
Lumiera error handling (C++ interface).
A synchronisation protection guard employing a lock scoped to the parameter type as a whole...
Helper to abstract creation and lifecycle of a dependency.
Detector to set off alarm when (re)using deceased objects.