Lazily generates and caches a value with optional custom destructor.
More...
#include <spk_cached_data.hpp>
|
|
using | value_type = TType |
| | Stored value type.
|
|
using | Generator = std::function<TType()> |
| | Callable used to lazily produce the cached value.
|
|
using | Destructor = std::function<void(TType &)> |
| | Optional cleanup function invoked when the cache is cleared.
|
|
| | CachedData (Generator p_generator, Destructor p_destructor=nullptr) |
| | Builds a cache with a generator and optional destructor.
|
|
| ~CachedData () |
| | Destroys any cached value using the destructor callback if set.
|
|
| CachedData (const CachedData &)=delete |
|
CachedData & | operator= (const CachedData &)=delete |
|
| CachedData (CachedData &&p_other)=delete |
|
CachedData & | operator= (CachedData &&p_other)=delete |
| TType & | get () |
| | Retrieves the cached value, generating it on first access.
|
| const TType & | get () const |
| | Retrieves the cached value, generating it on first access.
|
| TType & | operator* () |
| | Dereferences to the cached value, generating if needed.
|
| const TType & | operator* () const |
| | Dereferences to the cached value, generating if needed.
|
| TType * | operator-> () |
| | Member access to the cached value, generating if needed.
|
| const TType * | operator-> () const |
| | Member access to the cached value, generating if needed.
|
| | operator TType & () |
| | Implicitly converts to a mutable reference.
|
| | operator const TType & () const |
| | Implicitly converts to a const reference.
|
|
void | release () const |
| | Releases the cached value by invoking destructor if provided.
|
| void | configure (Generator p_generator, Destructor p_destructor=nullptr) |
| | Replaces the generator/destructor pair and clears any cached value.
|
| void | set (const TType &p_value) |
| | Stores a value directly, bypassing the generator.
|
| void | set (TType &&p_value) |
| | Stores a value directly, bypassing the generator (move overload).
|
| std::optional< TType > | take () |
| | Moves the cached value out of the cache without invoking the destructor.
|
| bool | isCached () const |
| | Checks if a value is currently cached.
|
| TType & | refresh () |
| | Drops the cached value and regenerates it.
|
template<typename TType>
class spk::CachedData< TType >
Lazily generates and caches a value with optional custom destructor.
- Template Parameters
-
| TType | cached value type (non-void). |
auto &value = blob.
get();
blob.release();
Lazily generates and caches a value with optional custom destructor.
Definition spk_cached_data.hpp:26
TType & get()
Retrieves the cached value, generating it on first access.
Definition spk_cached_data.hpp:116
◆ CachedData()
Builds a cache with a generator and optional destructor.
- Parameters
-
| p_generator | Function to produce the value on demand. |
| p_destructor | Optional cleanup function for the value. |
◆ configure()
Replaces the generator/destructor pair and clears any cached value.
- Parameters
-
| p_generator | New generator used to rebuild the value on demand. |
| p_destructor | Optional destructor for the cached value. |
◆ get() [1/2]
Retrieves the cached value, generating it on first access.
- Returns
- Mutable reference to the cached value.
◆ get() [2/2]
Retrieves the cached value, generating it on first access.
- Returns
- Constant reference to the cached value.
◆ isCached()
Checks if a value is currently cached.
- Returns
- true when data exists.
◆ operator const TType &()
Implicitly converts to a const reference.
- Returns
- Const reference to the value.
◆ operator TType &()
Implicitly converts to a mutable reference.
- Returns
- Reference to the value.
◆ operator*() [1/2]
Dereferences to the cached value, generating if needed.
- Returns
- Mutable reference to the value.
◆ operator*() [2/2]
Dereferences to the cached value, generating if needed.
- Returns
- Const reference to the value.
◆ operator->() [1/2]
Member access to the cached value, generating if needed.
- Returns
- Pointer to the value.
◆ operator->() [2/2]
Member access to the cached value, generating if needed.
- Returns
- Const pointer to the value.
◆ refresh()
Drops the cached value and regenerates it.
- Returns
- Reference to the new value.
◆ set() [1/2]
Stores a value directly, bypassing the generator.
- Parameters
-
◆ set() [2/2]
Stores a value directly, bypassing the generator (move overload).
- Parameters
-
◆ take()
Moves the cached value out of the cache without invoking the destructor.
- Returns
- Optional containing the moved value if it was cached.
The documentation for this class was generated from the following file: