Lumiera  0.pre.03
»edit your freedom«
Depend< SRV > Class Template Reference

#include "lib/depend.hpp"

Description

template<class SRV>
class lib::Depend< SRV >

Access point to singletons and other kinds of dependencies designated by type.

Actually this is a Factory object, which is typically placed into a static field of the Singleton (target) class or some otherwise suitable interface.

Template Parameters
SRVthe class of the Service or Singleton instance
Note
uses static fields internally, so all factory configuration is shared per type
Remarks
  • threadsafe lazy instantiation implemented by Double Checked Locking with std::atomic.
  • by default, without any explicit configuration, this template creates a singleton.
  • a per-type factory function can be configured with the help of lib::DependInject<SRV>
  • singletons will be destroyed when the embedded static InstanceHolder is destroyed.

Definition at line 280 of file depend.hpp.

Public Member Functions

 Depend ()
 
 operator bool () const
 allow to "peek" if a dependency is already available and exposed. More...
 
SRV & operator() ()
 Interface to be used by clients for retrieving the service instance. More...
 

Friends

class DependInject< SRV >
 

Private Types

using Factory = DependencyFactory< SRV >
 
using Instance = std::atomic< SRV * >
 
using Lock = ClassLock< SRV, NonrecursiveLock_NoWait >
 

Static Private Member Functions

static Factoryfactory ()
 

Static Private Attributes

static Instance instance
 shared per type
 

Constructor & Destructor Documentation

◆ Depend()

Depend ( )
inline
Remarks
this ctor ensures the factory is created prior to first use, and stays alive during the whole lifespan of any Depend<TY>

Definition at line 342 of file depend.hpp.

Member Function Documentation

◆ operator()()

SRV& operator() ( )
inline

Interface to be used by clients for retrieving the service instance.

Manages the instance creation, lifecycle and access in multithreaded context.

Returns
instance of class SRV. When used in default configuration, the returned service instance is a singleton.

Definition at line 307 of file depend.hpp.

◆ operator bool()

operator bool ( ) const
inlineexplicit

allow to "peek" if a dependency is already available and exposed.

Remarks
relevant when C code relies on a service with lifecycle.

Definition at line 334 of file depend.hpp.

+ Inheritance diagram for Depend< SRV >:
+ Collaboration diagram for Depend< SRV >:

The documentation for this class was generated from the following file: