57 _value_cbt = _value.subscribe(
59 if (
auto tmp = this->encode(); not holds_alternative<std::monostate>(tmp)) {
60 this->_parent.write(_path, this->encode());
62 this->_parent.remove(_path);
65 callback_flags::local);
74 [[nodiscard]]
datum encode() const noexcept
override
76 if (*_value != _init) {
77 return hi::pickle<T>{}.encode(*_value);
79 return datum{std::monostate{}};
83 void decode(datum
const& data)
override
85 _value = hi::pickle<T>{}.decode(data);
91 typename decltype(_value)::callback_token _value_cbt;
139 preferences(
std::string const &location) : preferences(
std::filesystem::path{location}) {}
140 preferences(
char const *location) : preferences(
std::filesystem::path{location}) {}
143 preferences(preferences
const&) =
delete;
144 preferences(preferences&&) =
delete;
145 preferences& operator=(preferences
const&) =
delete;
146 preferences& operator=(preferences&&) =
delete;
160 void save(
std::filesystem::path location) noexcept;
166 void load() noexcept;
174 void load(
std::filesystem::path location) noexcept;
178 void reset() noexcept;
187 void add(
std::string_view path,
observer<T> const& item, T init = T{})
noexcept
189 auto item_ = std::make_unique<detail::preference_item<T>>(*
this, path, item,
std::move(init));
197 std::filesystem::path _location;
206 mutable bool _modified =
false;
208 loop::timer_callback_token _check_modified_cbt;
214 void _load() noexcept;
215 void _save() const noexcept;
219 void check_modified() noexcept;
223 void write(jsonpath const& path, datum const value) noexcept;
227 datum read(jsonpath const& path) noexcept;
231 void remove(jsonpath const& path) noexcept;
233 friend class detail::preference_item_base;
235 friend class detail::preference_item;