LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
LC::Util::LazyInitializer< Source, Object > Class Template Reference

Provides lazy initialization on first access to an object. More...

#include "lazyinitializer.h"

Public Member Functions

template<typename Init >
 LazyInitializer (const Source &source, const Init &initializer, const std::function< void(Source &)> &clear=[](Source &src) { src=Source {};})
 Constructs an unevaluated lazy initializer. More...
 
 LazyInitializer (const Object &object)
 Constructs an evaluated initializer from the object. More...
 
LazyInitializeroperator= (const Object &object)
 Assigns an object to this lazy (making it evaluated) initializer and clears the source. More...
 
 operator Object ()
 Conversion operator to Object, forcing object construction. More...
 
Object & operator-> ()
 Indirection operator, forcing object construction. More...
 
void Force ()
 

Detailed Description

template<typename Source, typename Object>
class LC::Util::LazyInitializer< Source, Object >

Provides lazy initialization on first access to an object.

If the lazy initializer is unevaluated, the initialization functor passed to the constructor will be called first time the object inside this initializer is accessed.

Template Parameters
SourceThe source object used for initialization of the object.
ObjectThe type of the object which should be initialized.

Definition at line 41 of file lazyinitializer.h.

Constructor & Destructor Documentation

◆ LazyInitializer() [1/2]

template<typename Source , typename Object >
template<typename Init >
LC::Util::LazyInitializer< Source, Object >::LazyInitializer ( const Source &  source,
const Init &  initializer,
const std::function< void(Source &)> &  clear = [] (Source& src) { src = Source {}; } 
)
inline

Constructs an unevaluated lazy initializer.

Parameters
[in]sourceThe source object from which the Object should be initialized.
[in]initializerThe initialization function that returns an Object when called with Source.
[in]clearThe function for clearing the source after initialization to free up resources. Default function just assigns a default-constructed Source.
Template Parameters
InitThe type of the initializer.

Definition at line 68 of file lazyinitializer.h.

◆ LazyInitializer() [2/2]

template<typename Source , typename Object >
LC::Util::LazyInitializer< Source, Object >::LazyInitializer ( const Object &  object)
inline

Constructs an evaluated initializer from the object.

Parameters
[in]objectThe object used to initialize the stored one.

Definition at line 81 of file lazyinitializer.h.

Member Function Documentation

◆ Force()

template<typename Source , typename Object >
void LC::Util::LazyInitializer< Source, Object >::Force ( )
inline

Definition at line 115 of file lazyinitializer.h.

◆ operator Object()

template<typename Source , typename Object >
LC::Util::LazyInitializer< Source, Object >::operator Object ( )
inline

Conversion operator to Object, forcing object construction.

Definition at line 101 of file lazyinitializer.h.

◆ operator->()

template<typename Source , typename Object >
Object& LC::Util::LazyInitializer< Source, Object >::operator-> ( )
inline

Indirection operator, forcing object construction.

Definition at line 109 of file lazyinitializer.h.

◆ operator=()

template<typename Source , typename Object >
LazyInitializer& LC::Util::LazyInitializer< Source, Object >::operator= ( const Object &  object)
inline

Assigns an object to this lazy (making it evaluated) initializer and clears the source.

Parameters
[in]objectThe object to set this lazy initializer to.

Definition at line 91 of file lazyinitializer.h.


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