|
ROSE
0.11.96.11
|
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 <Cached.h>
Public Types | |
| typedef T | Value |
| Type of stored value. | |
Public Member Functions | |
| bool | isCached () const |
| Cached state. More... | |
| void | clear () const |
| Remove cached value. More... | |
| const Sawyer::Optional< Value > & | getOptional () const |
| Return cached value or nothing. More... | |
| const Value & | get () const |
| Return the cached value. More... | |
| Value & | get () |
| Return the cached value. More... | |
| void | set (const Value &x) const |
| Assign a new value. More... | |
| const Cached & | operator= (const Value &x) const |
| Assign a new value. More... | |
|
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 79 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 82 of file Cached.h.
References Sawyer::Optional< T >::get().

|
inline |
|
inline |
|
inline |
1.8.17