Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
LazyInit< PAR > Class Template Reference

#include "lib/lazy-init.hpp"

Description

template<class PAR = EmptyBase>
class lib::LazyInit< PAR >

Mix-in for lazy/delayed initialisation of an embedded functor.

This allows to keep the overall object (initially) copyable, while later preventing copy once the functor was »engaged«. Initially, only a »trap« is installed into the functor, invoking an initialisation closure on first use.

Definition at line 206 of file lazy-init.hpp.

Classes

struct  MarkDisabled
 

Public Member Functions

template<class SIG , class INI , typename... ARGS>
 LazyInit (std::function< SIG > &targetFunctor, INI &&initialiser, ARGS &&...parentCtorArgs)
 prepare an initialiser to be activated on first use
 
 LazyInit (LazyInit const &ref)
 
 LazyInit (LazyInit &&rref)
 
LazyInitoperator= (LazyInit const &ref)
 
LazyInitoperator= (LazyInit &&rref)
 
bool isInit () const
 
template<class SIG >
void installEmptyInitialiser ()
 
template<class SIG , class INI >
void installInitialiser (std::function< SIG > &targetFunctor, INI &&initialiser)
 

Protected Member Functions

template<typename... ARGS>
 LazyInit (MarkDisabled, ARGS &&...parentCtorArgs)
 

Private Types

template<class SIG >
using DelegateType = std::function< std::function< SIG > &(RawAddr)>
 
using PlaceholderType = DelegateType< void(void)>
 
using HeapStorage = InPlaceBuffer< PlaceholderType >
 
using PendingInit = std::shared_ptr< HeapStorage >
 

Private Member Functions

PendingInit const & __trapLocked (PendingInit const &init)
 
PendingInit && __trapLocked (PendingInit &&init)
 
template<class SIG >
DelegateType< SIG > emptyInitialiser ()
 
template<class SIG , class INI >
PendingInit prepareInitialiser (std::function< SIG > &targetFunctor, INI &&initialiser)
 
template<class SIG , class INI >
DelegateType< SIG > buildInitialiserDelegate (std::function< SIG > &targetFunctor, INI &&initialiser)
 

Static Private Member Functions

template<class SIG >
static DelegateType< SIG > * getPointerToDelegate (HeapStorage &buffer)
 
template<class SIG >
static std::function< SIG > maybeInvoke (PendingInit const &pendingInit, RawAddr location)
 

Private Attributes

PendingInit pendingInit_
 manage heap storage for a pending initialisation closure
 

Constructor & Destructor Documentation

◆ LazyInit() [1/4]

template<class PAR = EmptyBase>
template<typename... ARGS>
LazyInit ( MarkDisabled  ,
ARGS &&...  parentCtorArgs 
)
inlineprotected

allows derived classes to leave the initialiser deliberately disabled

Definition at line 247 of file lazy-init.hpp.

◆ LazyInit() [2/4]

template<class PAR = EmptyBase>
template<class SIG , class INI , typename... ARGS>
LazyInit ( std::function< SIG > &  targetFunctor,
INI &&  initialiser,
ARGS &&...  parentCtorArgs 
)
inline

prepare an initialiser to be activated on first use

Definition at line 256 of file lazy-init.hpp.

References LazyInit< PAR >::installInitialiser().

+ Here is the call graph for this function:

◆ LazyInit() [3/4]

template<class PAR = EmptyBase>
LazyInit ( LazyInit< PAR > const &  ref)
inline

Definition at line 264 of file lazy-init.hpp.

◆ LazyInit() [4/4]

template<class PAR = EmptyBase>
LazyInit ( LazyInit< PAR > &&  rref)
inline

Definition at line 269 of file lazy-init.hpp.


Class Documentation

◆ lib::LazyInit::MarkDisabled

struct lib::LazyInit::MarkDisabled
+ Collaboration diagram for LazyInit< PAR >::MarkDisabled:

Member Typedef Documentation

◆ DelegateType

template<class PAR = EmptyBase>
template<class SIG >
using DelegateType = std::function<std::function<SIG>&(RawAddr)>
private

Definition at line 210 of file lazy-init.hpp.

◆ PlaceholderType

template<class PAR = EmptyBase>
using PlaceholderType = DelegateType<void(void)>
private

Definition at line 212 of file lazy-init.hpp.

◆ HeapStorage

template<class PAR = EmptyBase>
using HeapStorage = InPlaceBuffer<PlaceholderType>
private

Definition at line 213 of file lazy-init.hpp.

◆ PendingInit

template<class PAR = EmptyBase>
using PendingInit = std::shared_ptr<HeapStorage>
private

Definition at line 214 of file lazy-init.hpp.

Member Function Documentation

◆ __trapLocked() [1/2]

template<class PAR = EmptyBase>
PendingInit const & __trapLocked ( PendingInit const &  init)
inlineprivate

Definition at line 221 of file lazy-init.hpp.

Referenced by LazyInit< PAR >::operator=(), and LazyInit< PAR >::operator=().

+ Here is the caller graph for this function:

◆ __trapLocked() [2/2]

template<class PAR = EmptyBase>
PendingInit && __trapLocked ( PendingInit &&  init)
inlineprivate

Definition at line 231 of file lazy-init.hpp.

◆ operator=() [1/2]

template<class PAR = EmptyBase>
LazyInit & operator= ( LazyInit< PAR > const &  ref)
inline

Definition at line 275 of file lazy-init.hpp.

References LazyInit< PAR >::__trapLocked(), util::isSameObject(), and LazyInit< PAR >::pendingInit_.

+ Here is the call graph for this function:

◆ operator=() [2/2]

template<class PAR = EmptyBase>
LazyInit & operator= ( LazyInit< PAR > &&  rref)
inline

Definition at line 286 of file lazy-init.hpp.

References LazyInit< PAR >::__trapLocked(), util::isSameObject(), and LazyInit< PAR >::pendingInit_.

+ Here is the call graph for this function:

◆ isInit()

template<class PAR = EmptyBase>
bool isInit ( ) const
inline

Definition at line 298 of file lazy-init.hpp.

References LazyInit< PAR >::pendingInit_.

Referenced by LazyInit< PAR >::prepareInitialiser(), and LazyInit_test::verify_complexUsageWithCopy().

+ Here is the caller graph for this function:

◆ installEmptyInitialiser()

template<class PAR = EmptyBase>
template<class SIG >
void installEmptyInitialiser ( )
inline

Definition at line 305 of file lazy-init.hpp.

References LazyInit< PAR >::pendingInit_.

◆ installInitialiser()

template<class PAR = EmptyBase>
template<class SIG , class INI >
void installInitialiser ( std::function< SIG > &  targetFunctor,
INI &&  initialiser 
)
inline

Definition at line 312 of file lazy-init.hpp.

References LazyInit< PAR >::pendingInit_, and LazyInit< PAR >::prepareInitialiser().

Referenced by LazyInit_test::LazyDemo::LazyDemo(), LazyInit_test::LazyDemo::LazyDemo(), LazyInit< PAR >::LazyInit(), and LazyInit_test::LazyDemo::attach().

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

◆ emptyInitialiser()

template<class PAR = EmptyBase>
template<class SIG >
DelegateType< SIG > emptyInitialiser ( )
inlineprivate

Definition at line 321 of file lazy-init.hpp.

◆ prepareInitialiser()

template<class PAR = EmptyBase>
template<class SIG , class INI >
PendingInit prepareInitialiser ( std::function< SIG > &  targetFunctor,
INI &&  initialiser 
)
inlineprivate

Definition at line 333 of file lazy-init.hpp.

References LazyInit< PAR >::buildInitialiserDelegate(), TrojanFun< SIG >::generateTrap(), and LazyInit< PAR >::isInit().

Referenced by LazyInit< PAR >::installInitialiser().

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

◆ getPointerToDelegate()

template<class PAR = EmptyBase>
template<class SIG >
static DelegateType< SIG > * getPointerToDelegate ( HeapStorage buffer)
inlinestaticprivate

Definition at line 352 of file lazy-init.hpp.

◆ maybeInvoke()

template<class PAR = EmptyBase>
template<class SIG >
static std::function< SIG > maybeInvoke ( PendingInit const &  pendingInit,
RawAddr  location 
)
inlinestaticprivate

Definition at line 359 of file lazy-init.hpp.

◆ buildInitialiserDelegate()

template<class PAR = EmptyBase>
template<class SIG , class INI >
DelegateType< SIG > buildInitialiserDelegate ( std::function< SIG > &  targetFunctor,
INI &&  initialiser 
)
inlineprivate

Definition at line 369 of file lazy-init.hpp.

References LazyInit< PAR >::pendingInit_.

Referenced by LazyInit< PAR >::prepareInitialiser().

+ Here is the caller graph for this function:

Member Data Documentation

◆ pendingInit_

template<class PAR = EmptyBase>
PendingInit pendingInit_
private
+ Inheritance diagram for LazyInit< PAR >:
+ Collaboration diagram for LazyInit< PAR >:

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