10#include "observable.hpp"
33 virtual void reset() noexcept = 0;
40 std::shared_ptr<
std::function<
void()>> _modified_callback_ptr;
48 [[nodiscard]] virtual
datum encode() const noexcept = 0;
50 virtual
void decode(
datum const &data) = 0;
59 _value.subscribe(this->_modified_callback_ptr);
68 [[nodiscard]]
datum encode() const noexcept
override
74 return datum{std::monostate{}};
78 void decode(datum
const &data)
override
142 void save() const noexcept;
150 void save(
URL location) noexcept;
156 void load() noexcept;
164 void load(
URL location) noexcept;
168 [[nodiscard]]
void reset() noexcept;
177 void add(
std::string_view path,
observable<T> const &item, T init = T{})
noexcept
179 auto item_ = std::make_unique<detail::preference_item<T>>(*
this, path, item,
std::move(init));
196 mutable bool _modified =
false;
200 timer::callback_ptr_type _check_modified_callback_ptr;
206 void _load() noexcept;
207 void _save() const noexcept;
211 void check_modified() noexcept;
215 void write(jsonpath const &path, datum const value) noexcept;
219 datum read(jsonpath const &path) noexcept;
223 void remove(jsonpath const &path) noexcept;
225 friend class detail::preference_item_base;
A dynamic data type.
Definition datum.hpp:213
Definition jsonpath.hpp:379
A value which can be observed for modifications.
Definition observable.hpp:464
Encode and decode a type to and from a UTF-8 string.
Definition pickle.hpp:22
T decode(datum rhs) const
Decode a UTF-8 string into a value of a given type.
datum encode(T const &rhs) const noexcept
Encode the value of a type into a UTF-8 string.
Definition preferences.hpp:21
virtual void reset() noexcept=0
Reset the value.
void load() noexcept
Load a value from the preferences.
Definition preferences.hpp:54
void reset() noexcept override
Reset the value.
Definition preferences.hpp:62
user preferences.
Definition preferences.hpp:107
void load() noexcept
Load the preferences.
std::mutex mutex
Mutex used to synchronize changes to the preferences.
Definition preferences.hpp:114
preferences() noexcept
Construct a preferences instance.