roo_prefs
API Documentation for roo_prefs
Loading...
Searching...
No Matches
collection.h
Go to the documentation of this file.
1#pragma once
2
3#include "roo_logging.h"
5
6namespace roo_prefs {
7
8class Transaction;
9
11
12/// Collection corresponds to a preferences namespace. Use it to group related
13/// preferences.
15 public:
16 Collection(const char* name)
17 : store_(), name_(name), refcount_(0), read_only_(true) {}
18
19 bool inTransaction() const { return refcount_ > 0; }
20
21 private:
22 friend class Transaction;
23
24 bool inc(bool read_only) {
25 if (refcount_ == 0) {
26 if (!store_.begin(name_, read_only)) {
27 if (read_only) {
28 LOG(WARNING) << "Failed to initialize preferences " << name_
29 << " for reading";
30 } else {
31 LOG(ERROR) << "Failed to initialize preferences " << name_
32 << " for writing";
33 }
34 return false;
35 }
36 read_only_ = read_only;
37 ++refcount_;
38 return true;
39 }
40 if (read_only_ && !read_only) return false;
41 ++refcount_;
42 return true;
43 }
44
45 void dec() {
46 if (--refcount_ == 0) {
47 store_.end();
48 }
49 }
50
51 Store store_;
52 const char* name_;
53 int refcount_;
54 bool read_only_;
55};
56
57} // namespace roo_prefs
Collection corresponds to a preferences namespace. Use it to group related preferences.
Definition collection.h:14
Collection(const char *name)
Definition collection.h:16
bool inTransaction() const
Definition collection.h:19
Low-level wrapper around the underlying preferences storage.
Ref-counted RAII for managing access to Preference namespaces. Allows orchestrating access to the Sto...
Definition transaction.h:9
Similar to Pref<T>, but does not immediately store written data in persistent storage....
Definition collection.h:6
PreferencesStore Store
Definition collection.h:10