Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
DependencyFactory< OBJ > Class Template Reference

#include "lib/depend.hpp"

Description

template<class OBJ>
class lib::DependencyFactory< OBJ >

Helper to abstract creation and lifecycle of a dependency.

Holds a configurable constructor function and optionally an automatically invoked deleter function.

Note
DependencyFactory can be declared friend to indicate the expected way to invoke an otherwise private ctor. This is a classical idiom for singletons.
See also
lib::Depend
lib::DependInject

Definition at line 125 of file depend.hpp.

Classes

struct  canDefaultConstruct
 metafunction: can we instantiate the desired object here? More...
 

Public Attributes

ZombieCheck zombieCheck {util::typeStr<OBJ>()}
 

Public Member Functions

 DependencyFactory ()=default
 
 ~DependencyFactory ()
 
OBJ * buildTarget ()
 
template<typename FUN >
void defineCreator (FUN &&ctor)
 
template<typename FUN >
void defineCreatorAndManage (FUN &&ctor)
 
void disable ()
 
template<typename FUN >
void atDestruction (FUN &&additionalAction)
 
void transferDefinition (DependencyFactory &&source)
 

Private Types

using Creator = std::function< OBJ *()>
 
using Deleter = std::function< void()>
 

Private Member Functions

OBJ * buildAndManage ()
 
- Private Member Functions inherited from NonCopyable
 ~NonCopyable ()=default
 
 NonCopyable ()=default
 
 NonCopyable (NonCopyable const &)=delete
 
NonCopyableoperator= (NonCopyable const &)=delete
 

Static Private Member Functions

template<class X , typename = decltype(X())>
static std::true_type __try_instantiate (int)
 
template<class >
static std::false_type __try_instantiate (...)
 
template<class TAR >
static meta::enable_if< canDefaultConstruct< TAR >, TAR * > buildInstance ()
 
template<class ABS >
static meta::enable_if< std::is_abstract< ABS >, ABS * > buildInstance ()
 
template<class ABS >
static meta::disable_if< std::__or_< std::is_abstract< ABS >, canDefaultConstruct< ABS > >, ABS * > buildInstance ()
 

Private Attributes

Creator creator_
 
Deleter deleter_
 

Constructor & Destructor Documentation

◆ DependencyFactory()

template<class OBJ >
DependencyFactory ( )
default

◆ ~DependencyFactory()

template<class OBJ >
~DependencyFactory ( )
inline

Definition at line 138 of file depend.hpp.

References DependencyFactory< OBJ >::deleter_.

Member Typedef Documentation

◆ Creator

template<class OBJ >
using Creator = std::function<OBJ*()>
private

Definition at line 128 of file depend.hpp.

◆ Deleter

template<class OBJ >
using Deleter = std::function<void()>
private

Definition at line 129 of file depend.hpp.

Member Function Documentation

◆ buildTarget()

template<class OBJ >
OBJ * buildTarget ( )
inline

Definition at line 145 of file depend.hpp.

References DependencyFactory< OBJ >::buildAndManage(), and DependencyFactory< OBJ >::creator_.

+ Here is the call graph for this function:

◆ defineCreator()

template<class OBJ >
template<typename FUN >
void defineCreator ( FUN &&  ctor)
inline

Definition at line 153 of file depend.hpp.

References DependencyFactory< OBJ >::creator_.

◆ defineCreatorAndManage()

template<class OBJ >
template<typename FUN >
void defineCreatorAndManage ( FUN &&  ctor)
inline

Definition at line 160 of file depend.hpp.

References DependencyFactory< OBJ >::atDestruction(), and DependencyFactory< OBJ >::creator_.

+ Here is the call graph for this function:

◆ disable()

template<class OBJ >
void disable ( )
inline

Definition at line 171 of file depend.hpp.

References DependencyFactory< OBJ >::creator_, and LERR_.

◆ atDestruction()

template<class OBJ >
template<typename FUN >
void atDestruction ( FUN &&  additionalAction)
inline

Definition at line 182 of file depend.hpp.

References DependencyFactory< OBJ >::deleter_.

Referenced by DependencyFactory< OBJ >::buildAndManage(), and DependencyFactory< OBJ >::defineCreatorAndManage().

+ Here is the caller graph for this function:

◆ transferDefinition()

template<class OBJ >
void transferDefinition ( DependencyFactory< OBJ > &&  source)
inline

◆ buildAndManage()

template<class OBJ >
OBJ * buildAndManage ( )
inlineprivate

Definition at line 208 of file depend.hpp.

References DependencyFactory< OBJ >::atDestruction().

Referenced by DependencyFactory< OBJ >::buildTarget().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __try_instantiate() [1/2]

template<class OBJ >
template<class X , typename = decltype(X())>
static std::true_type __try_instantiate ( int  )
staticprivate

◆ __try_instantiate() [2/2]

template<class OBJ >
template<class >
static std::false_type __try_instantiate (   ...)
staticprivate

◆ buildInstance() [1/3]

template<class OBJ >
template<class TAR >
static meta::enable_if< canDefaultConstruct< TAR >, TAR * > buildInstance ( )
inlinestaticprivate

Definition at line 234 of file depend.hpp.

◆ buildInstance() [2/3]

template<class OBJ >
template<class ABS >
static meta::enable_if< std::is_abstract< ABS >, ABS * > buildInstance ( )
inlinestaticprivate

Definition at line 242 of file depend.hpp.

◆ buildInstance() [3/3]

template<class OBJ >
template<class ABS >
static meta::disable_if< std::__or_< std::is_abstract< ABS >, canDefaultConstruct< ABS > >, ABS * > buildInstance ( )
inlinestaticprivate

Definition at line 250 of file depend.hpp.

Member Data Documentation

◆ creator_

◆ deleter_

◆ zombieCheck

template<class OBJ >
ZombieCheck zombieCheck {util::typeStr<OBJ>()}

Definition at line 135 of file depend.hpp.

+ Inheritance diagram for DependencyFactory< OBJ >:
+ Collaboration diagram for DependencyFactory< OBJ >:

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