53 Pref(
Collection& collection,
const char* key, T default_value = T());
59 bool set(
const T& value);
64 enum class PrefState { kUnknown, kUnset, kSet,
kError };
71 mutable PrefState state_;
94 return store.
clear(key);
110 const uint8_t& val) {
111 return store.
writeU8(key, val);
117 return store.
writeI8(key, val);
122 const uint16_t& val) {
128 const int16_t& val) {
134 const uint32_t& val) {
140 const int32_t& val) {
146 const uint64_t& val) {
152 const int64_t& val) {
169inline WriteResult StoreWrite<roo::string_view>(
Store& store,
const char* key,
170 const roo::string_view& val) {
176 const std::string& val) {
186inline ReadResult StoreRead<bool>(
Store& store,
const char* key,
bool& val) {
193 return store.
readU8(key, val);
199 return store.
readI8(key, val);
205 return store.
readU16(key, val);
211 return store.
readI16(key, val);
217 return store.
readU32(key, val);
223 return store.
readI32(key, val);
229 return store.
readU64(key, val);
235 return store.
readI64(key, val);
239inline ReadResult StoreRead<float>(
Store& store,
const char* key,
float& val) {
259 : collection_(collection),
261 default_value_(std::move(default_value)),
262 state_(PrefState::kUnknown),
263 value_(default_value) {}
268 return (state_ == PrefState::kSet);
280 if (state_ == PrefState::kSet && value_ == value) {
285 state_ = PrefState::kError;
288 switch (internal::StoreWrite(t.
store(), key_, value)) {
291 state_ = PrefState::kSet;
295 state_ = PrefState::kError;
304 if (state_ == PrefState::kUnset) {
309 state_ = PrefState::kError;
312 switch (internal::StoreClear(t.
store(), key_)) {
314 state_ = PrefState::kUnset;
315 value_ = default_value_;
319 state_ = PrefState::kError;
327 if (state_ == PrefState::kUnknown || state_ == PrefState::kError) {
330 state_ = PrefState::kUnset;
331 value_ = default_value_;
334 switch (internal::StoreRead(t.store(), key_, value_)) {
336 state_ = PrefState::kSet;
340 state_ = PrefState::kUnset;
341 value_ = default_value_;
345 state_ = PrefState::kError;
Collection corresponds to a preferences namespace. Use it to group related preferences.
Persistent preference of a specific type. The preference will store its value in the preferences coll...
Pref(Collection &collection, const char *key, T default_value=T())
Low-level wrapper around the underlying preferences storage.
WriteResult writeU8(const char *key, uint8_t val)
WriteResult writeBool(const char *key, bool val)
WriteResult writeI8(const char *key, int8_t val)
ReadResult readDouble(const char *key, double &val)
WriteResult writeFloat(const char *key, float val)
ReadResult readI32(const char *key, int32_t &val)
WriteResult writeI32(const char *key, int32_t val)
ReadResult readU8(const char *key, uint8_t &val)
WriteResult writeI16(const char *key, int16_t val)
ReadResult readI8(const char *key, int8_t &val)
WriteResult writeU32(const char *key, uint32_t val)
WriteResult writeString(const char *key, roo::string_view val)
ReadResult readI16(const char *key, int16_t &val)
ReadResult readBool(const char *key, bool &val)
ReadResult readU64(const char *key, uint64_t &val)
WriteResult writeDouble(const char *key, double val)
ReadResult readU32(const char *key, uint32_t &val)
ReadResult readI64(const char *key, int64_t &val)
ClearResult clear(const char *key)
WriteResult writeObject(const char *key, const T &val)
ReadResult readFloat(const char *key, float &val)
ReadResult readObject(const char *key, T &val)
WriteResult writeU64(const char *key, uint64_t val)
ReadResult readU16(const char *key, uint16_t &val)
ReadResult readString(const char *key, std::string &val)
WriteResult writeI64(const char *key, int64_t val)
WriteResult writeU16(const char *key, uint16_t val)
Ref-counted RAII for managing access to Preference namespaces. Allows orchestrating access to the Sto...
Similar to Pref<T>, but does not immediately store written data in persistent storage....
ReadResult
Result of reading a value from storage.
ClearResult
Result of clearing a value from storage.
WriteResult
Result of writing a value to storage.