|
roo_prefs
API Documentation for roo_prefs
|
Persistent preference of a specific type. The preference will store its value in the preferences collection provided in the constructor, under the specified key (which needs to remain constant). The value is read lazily (on first access.) You can provide default value to be used if the collection does not contain the specified key. The value is cached in memory - subsequent reads will return the cached value. Writes always write to the persistent storage (and also, update the cache.) Read and write are performed within implicitly created transactions. If you have multiple properties that you want to read/write at the same time, you can read them under an explicit transaction: More...
#include <pref.h>
Public Member Functions | |
| Pref (Collection &collection, const char *key, T default_value=T()) | |
| bool | isSet () const |
| const T & | get () const |
| bool | set (const T &value) |
| bool | clear () |
Persistent preference of a specific type. The preference will store its value in the preferences collection provided in the constructor, under the specified key (which needs to remain constant). The value is read lazily (on first access.) You can provide default value to be used if the collection does not contain the specified key. The value is cached in memory - subsequent reads will return the cached value. Writes always write to the persistent storage (and also, update the cache.) Read and write are performed within implicitly created transactions. If you have multiple properties that you want to read/write at the same time, you can read them under an explicit transaction:
roo_prefs::Collection col("foo"); roo_prefs::Int16 pref1(col, "pref1"); roo_prefs::String pref2(col, "pref2"); int16_t a; std::string b; { Transaction t(col); a = pref1.get(); b = pref2.get(); }
For simple types, use aliases defined later in the file (Uint8, String, etc.)
You can persist arbitrary types (e.g. struct types). Types other than simple types and std::string are persisted as BLOBs, containing the binary representation of the object.
NOTE:
| roo_prefs::Pref< T >::Pref | ( | Collection & | collection, |
| const char * | key, | ||
| T | default_value = T() |
||
| ) |
| bool roo_prefs::Pref< T >::clear | ( | ) |
Definition at line 302 of file pref.h.
References roo_prefs::Transaction::active(), roo_prefs::kOk, and roo_prefs::Transaction::store().
| const T & roo_prefs::Pref< T >::get | ( | ) | const |
| bool roo_prefs::Pref< T >::isSet | ( | ) | const |
| bool roo_prefs::Pref< T >::set | ( | const T & | value | ) |
Definition at line 278 of file pref.h.
References roo_prefs::Transaction::active(), roo_prefs::kOk, and roo_prefs::Transaction::store().