roo_prefs
API Documentation for roo_prefs
Loading...
Searching...
No Matches
roo_prefs::Pref< T > Class Template Reference

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 ()
 

Detailed Description

template<typename T>
class roo_prefs::Pref< T >

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:

  • Preferences library is generally intended for storing small values.
  • If the definition (and thus the internal representation) of your complex type changes, any persisted values of that type will become unreadable or corrupted. For these reasons, it is generally not a good practice to persist large objects using this template.

Definition at line 51 of file pref.h.

Constructor & Destructor Documentation

◆ Pref()

template<typename T >
roo_prefs::Pref< T >::Pref ( Collection collection,
const char *  key,
default_value = T() 
)

Definition at line 258 of file pref.h.

Member Function Documentation

◆ clear()

template<typename T >
bool roo_prefs::Pref< T >::clear ( )

◆ get()

template<typename T >
const T & roo_prefs::Pref< T >::get ( ) const

Definition at line 272 of file pref.h.

◆ isSet()

template<typename T >
bool roo_prefs::Pref< T >::isSet ( ) const

Definition at line 266 of file pref.h.

◆ set()

template<typename T >
bool roo_prefs::Pref< T >::set ( const T &  value)

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