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"
4
#include "
roo_prefs/store/preferences_store.h
"
5
6
namespace
roo_prefs
{
7
8
class
Transaction
;
9
10
using
Store
=
PreferencesStore
;
11
12
/// Collection corresponds to a preferences namespace. Use it to group related
13
/// preferences.
14
class
Collection
{
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
roo_prefs::Collection
Collection corresponds to a preferences namespace. Use it to group related preferences.
Definition
collection.h:14
roo_prefs::Collection::Collection
Collection(const char *name)
Definition
collection.h:16
roo_prefs::Collection::inTransaction
bool inTransaction() const
Definition
collection.h:19
roo_prefs::PreferencesStore
Low-level wrapper around the underlying preferences storage.
Definition
preferences_store.h:13
roo_prefs::Transaction
Ref-counted RAII for managing access to Preference namespaces. Allows orchestrating access to the Sto...
Definition
transaction.h:9
roo_prefs
Similar to Pref<T>, but does not immediately store written data in persistent storage....
Definition
collection.h:6
roo_prefs::Store
PreferencesStore Store
Definition
collection.h:10
preferences_store.h
temp_repos
roo_prefs
src
roo_prefs
collection.h
Generated by
1.9.8