ROSE 0.11.145.147
|
Implements cache data members.
A cache data member either stores a value or stores no value. When its value is present, it can be obtained, and when absent it has no value (not even a default constructed value). The value of a cache data member can be modified even when its object is const. For instance, an object that caches an expensive-to-compute value could be declared thusly:
When a Foo object is constructed the bar_
member will contain nothing (not even a default-constructed object). Here's a sample implementation that returns the value, performing the expensive calculation and caching the result if necessary. The method is declared to take a const this
pointer since it is conceptually a data member accessor:
#include <Sawyer/Cached.h>
Public Types | |
typedef T | Value |
Type of stored value. | |
Public Member Functions | |
Cached () | |
Initialize to an empty value. | |
bool | isCached () const |
Cached state. | |
void | clear () const |
Remove cached value. | |
const Sawyer::Optional< Value > & | getOptional () const |
Return cached value or nothing. | |
const Value & | get () const |
Return the cached value. | |
Value & | get () |
Return the cached value. | |
const Value & | operator* () const |
Return the cached value. | |
Value & | operator* () |
Return the cached value. | |
const Value * | operator-> () const |
Return pointer to cached value. | |
Value * | operator-> () |
Return pointer to cached value. | |
void | set (const Value &x) const |
Assign a new value. | |
const Cached & | operator= (const Value &x) const |
Assign a new value. | |
typedef T Sawyer::Cached< T >::Value |
|
inline |
|
inline |
|
inline |
|
inline |
Return the cached value.
If a value is cached then it is returned. This should not be called unless a cached value is present (see isCached). An alternative is to use getOptional.
Definition at line 92 of file Cached.h.
References Sawyer::Optional< T >::get().
|
inline |
Return the cached value.
If a value is cached then it is returned. This should not be called unless a cached value is present (see isCached). An alternative is to use getOptional.
Definition at line 95 of file Cached.h.
References Sawyer::Optional< T >::get().
|
inline |
Return the cached value.
If a value is cached then it is returned. This should not be called unless a cached value is present (see isCached). An alternative is to use getOptional.
Definition at line 98 of file Cached.h.
References Sawyer::Optional< T >::get().
|
inline |
Return the cached value.
If a value is cached then it is returned. This should not be called unless a cached value is present (see isCached). An alternative is to use getOptional.
Definition at line 101 of file Cached.h.
References Sawyer::Optional< T >::get().
|
inline |
Return pointer to cached value.
If a value is cached then its address is returned. This should not be called unless a cached value is present (see isCached).
Definition at line 112 of file Cached.h.
References Sawyer::Optional< T >::get().
|
inline |
Return pointer to cached value.
If a value is cached then its address is returned. This should not be called unless a cached value is present (see isCached).
Definition at line 115 of file Cached.h.
References Sawyer::Optional< T >::get().
|
inline |
|
inline |
|
inline |