|
HikoGUI
A low latency retained GUI
|
#include <hikogui/settings/preferences.hpp>
Public Member Functions | |
| preferences () noexcept | |
| Construct a preferences instance. | |
| preferences (std::filesystem::path location) noexcept | |
| Construct a preferences instance. | |
| preferences (std::string_view location) | |
| preferences (std::string const &location) | |
| preferences (char const *location) | |
| preferences (preferences const &)=delete | |
| preferences (preferences &&)=delete | |
| preferences & | operator= (preferences const &)=delete |
| preferences & | operator= (preferences &&)=delete |
| void | save () const noexcept |
| Save the preferences. | |
| void | save (std::filesystem::path location) noexcept |
| Save the preferences. | |
| void | load () noexcept |
| Load the preferences. | |
| void | load (std::filesystem::path location) noexcept |
| Load the preferences. | |
| void | reset () noexcept |
| Reset data members to their default value. | |
| template<typename T > | |
| void | add (std::string_view path, observer< T > const &item, T init=T{}) noexcept |
| Register an observer to a preferences file. | |
Data Fields | |
| std::mutex | mutex |
| Mutex used to synchronize changes to the preferences. | |
Friends | |
| class | detail::preference_item_base |
| template<typename T > | |
| class | detail::preference_item |
user preferences.
A preferences objects maintains a link between observer in the application and a preferences file.
When loading preferences the observer are set to the value in the preferences file. When an observer changes a value the preferences file is updated to reflect this change. For performance reasons multiple modifications are combined into a single save.
An application may open multiple preferences files, for example an application preferences file and a project-specific preferences file. The name of the project-specific preferences file can then be selected by the user.
The preferences file is updated by using the operating system specific call to overwrite an existing file atomically.
|
inlinenoexcept |
Construct a preferences instance.
No current preferences file will be selected.
It is recommended to call preferences::load(std::filesystem::path) after the constructor.
|
inlinenoexcept |
Construct a preferences instance.
The current preferences file is changed to the location give.
| location | The location of the preferences file to load from. |
|
inlinenoexcept |
Register an observer to a preferences file.
| path | The json-path inside the preference file. |
| item | The observer to monitor. |
| init | The value of the observer when it is not present in the preferences file. |
|
inlinenoexcept |
Load the preferences.
This will load the preferences from the current selected file.
|
inlinenoexcept |
Load the preferences.
This will change the current preferences file to the location given.
| location | The file to save the preferences to. |
|
inlinenoexcept |
Reset data members to their default value.
|
inlinenoexcept |
Save the preferences.
This will load the preferences from the current selected file.
|
inlinenoexcept |
Save the preferences.
This will change the current preferences file to the location given.
| location | The file to save the preferences to. |
|
mutable |
Mutex used to synchronize changes to the preferences.
This mutex may be used externally to atomically combine multiple observer modification into a single change of the preferences file.