113 #include <type_traits> 114 #include <functional> 137 using Creator = std::function<OBJ*()>;
138 using Deleter = std::function<void()>;
156 return creator_? creator_()
160 template<
typename FUN>
162 defineCreator (FUN&& ctor)
164 creator_ = std::forward<FUN> (ctor);
167 template<
typename FUN>
169 defineCreatorAndManage (FUN&& ctor)
171 creator_ = [
this,ctor]
174 atDestruction ([obj]{
delete obj; });
182 creator_ = []() -> OBJ*
184 throw error::Fatal(
"Service not available at this point of the Application Lifecycle" 189 template<
typename FUN>
191 atDestruction (FUN&& additionalAction)
195 Deleter oldDeleter{std::move (deleter_)};
196 deleter_ = [oldDeleter, additionalAction]
203 deleter_ = std::forward<FUN> (additionalAction);
209 creator_ = std::move (source.creator_);
210 deleter_ = std::move (source.deleter_);
211 source.creator_ = Creator();
212 source.deleter_ = Deleter();
219 OBJ* obj = buildInstance<OBJ>();
220 atDestruction ([obj]{
delete obj; });
225 template<
class X,
typename = decltype(X())>
226 static std::true_type __try_instantiate(
int);
228 static std::false_type __try_instantiate(...);
236 : decltype(__try_instantiate<X>(0))
253 throw error::Fatal(
"Attempt to create a singleton instance of an abstract class. " 254 "Application architecture or lifecycle is seriously broken.");
261 throw error::Fatal(
"Desired singleton class is not default constructible. " 262 "Application architecture or lifecycle is seriously broken.");
291 using Instance = std::atomic<SRV*>;
302 return sharedFactory;
318 SRV*
object = instance.load (std::memory_order_acquire);
321 factory().zombieCheck();
324 object = instance.load (std::memory_order_relaxed);
327 object = factory().buildTarget();
329 factory().atDestruction([]{ instance =
nullptr; });
331 instance.store (
object, std::memory_order_release);
343 operator bool()
const 345 return instance.load (std::memory_order_acquire);
353 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.