Honeycomb  0.1
Component-Model Framework
Public Member Functions | Related Functions | List of all members
honey::lazy< T, Eval, Pred > Class Template Reference

Wraps a value so that it is calculated only when needed. A lock synchronizes access. More...

#include <Lazy.h>

Public Member Functions

 lazy (const Eval &eval=nullptr, const Pred &pred=nullptr)
 
void setDirty (bool dirty)
 
bool isDirty () const
 
void setPred (const Pred &pred)
 
void setEval (const Eval &eval)
 
const T & raw () const
 Direct access to the wrapped value (ie. does not evaluate) More...
 
T & raw ()
 
const T & operator* () const
 Evaluate the lazy value. More...
 
T & operator* ()
 
const T * operator-> () const
 
T * operator-> ()
 
 operator const T & () const
 Evaluate the lazy value. More...
 
 operator T & ()
 
template<class... Args>
T & get (Args &&...args)
 Evaluate the lazy value. Only evaluates if dirty. The args are passed to the predicate and eval function. More...
 
template<class... Args>
const T & get (Args &&...args) const
 

Related Functions

(Note that these are not member functions.)

template<class Eval >
auto lazyCreate (Eval &&eval) -> lazy< decltype(eval())>
 Create a lazy value from a function that returns a value. Ex. auto lazy = lazyCreate([] { return T(); }); More...
 

Detailed Description

template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
class honey::lazy< T, Eval, Pred >

Wraps a value so that it is calculated only when needed. A lock synchronizes access.

Constructor & Destructor Documentation

template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
honey::lazy< T, Eval, Pred >::lazy ( const Eval &  eval = nullptr,
const Pred &  pred = nullptr 
)
inline
Parameters
evalFunction that will be called to evaluate the lazy value. A reference to the wrapped value is provided as the first arg. eval is called after the lock is acquired.
predOptional predicate function to check if dirty. The lazy value is dirty if isDirty() or pred return true. pred is called once before (for early return) and once after the lock is acquired. Because pred is called on every access, it should use atomics and avoid locks.

Member Function Documentation

template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
template<class... Args>
T& honey::lazy< T, Eval, Pred >::get ( Args &&...  args)
inline

Evaluate the lazy value. Only evaluates if dirty. The args are passed to the predicate and eval function.

template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
template<class... Args>
const T& honey::lazy< T, Eval, Pred >::get ( Args &&...  args) const
inline
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
bool honey::lazy< T, Eval, Pred >::isDirty ( ) const
inline
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
honey::lazy< T, Eval, Pred >::operator const T & ( ) const
inline

Evaluate the lazy value.

template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
honey::lazy< T, Eval, Pred >::operator T & ( )
inline
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
const T& honey::lazy< T, Eval, Pred >::operator* ( ) const
inline

Evaluate the lazy value.

template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
T& honey::lazy< T, Eval, Pred >::operator* ( )
inline
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
const T* honey::lazy< T, Eval, Pred >::operator-> ( ) const
inline
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
T* honey::lazy< T, Eval, Pred >::operator-> ( )
inline
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
const T& honey::lazy< T, Eval, Pred >::raw ( ) const
inline

Direct access to the wrapped value (ie. does not evaluate)

template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
T& honey::lazy< T, Eval, Pred >::raw ( )
inline
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
void honey::lazy< T, Eval, Pred >::setDirty ( bool  dirty)
inline
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
void honey::lazy< T, Eval, Pred >::setEval ( const Eval &  eval)
inline
template<class T, class Eval = function<void(T&)>, class Pred = function<bool()>>
void honey::lazy< T, Eval, Pred >::setPred ( const Pred &  pred)
inline

Friends And Related Function Documentation

template<class Eval >
auto lazyCreate ( Eval &&  eval) -> lazy<decltype(eval())>
related

Create a lazy value from a function that returns a value. Ex. auto lazy = lazyCreate([] { return T(); });


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