HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Member Functions | Data Fields | Friends
v1::preferences Class Reference

#include <hikogui/preferences.hpp>

Public Member Functions

 preferences () noexcept
 Construct a preferences instance.
 
 preferences (URL location) noexcept
 Construct a preferences instance.
 
 preferences (preferences const &)=delete
 
 preferences (preferences &&)=delete
 
preferencesoperator= (preferences const &)=delete
 
preferencesoperator= (preferences &&)=delete
 
void save () const noexcept
 Save the preferences.
 
void save (URL location) noexcept
 Save the preferences.
 
void load () noexcept
 Load the preferences.
 
void load (URL location) noexcept
 Load the preferences.
 
void reset () noexcept
 Reset data members to their default value.
 
template<typename T >
void add (std::string_view path, observable< T > const &item, T init=T{}) noexcept
 Register an observable 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
 

Detailed Description

user preferences.

A preferences objects maintains a link between observables in the application and a preferences file.

When loading preferences the observables are set to the value in the preferences file. When an observable 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.

Constructor & Destructor Documentation

◆ preferences() [1/2]

v1::preferences::preferences ( )
noexcept

Construct a preferences instance.

No current preferences file will be selected.

It is recommended to call preferences::load(URL) after the constructor.

◆ preferences() [2/2]

v1::preferences::preferences ( URL location)
noexcept

Construct a preferences instance.

The current preferences file is changed to the location give.

Parameters
locationThe location of the preferences file to load from.

Member Function Documentation

◆ add()

template<typename T >
void v1::preferences::add ( std::string_view path,
observable< T > const & item,
T init = T{} )
inlinenoexcept

Register an observable to a preferences file.

Parameters
pathThe json-path inside the preference file.
itemThe observable to monitor.
initThe value of the observable when it is not present in the preferences file.

◆ load() [1/2]

void v1::preferences::load ( )
noexcept

Load the preferences.

This will load the preferences from the current selected file.

◆ load() [2/2]

void v1::preferences::load ( URL location)
noexcept

Load the preferences.

This will change the current preferences file to the location given.

Parameters
locationThe file to save the preferences to.

◆ reset()

void v1::preferences::reset ( )
noexcept

Reset data members to their default value.

◆ save() [1/2]

void v1::preferences::save ( ) const
noexcept

Save the preferences.

This will load the preferences from the current selected file.

◆ save() [2/2]

void v1::preferences::save ( URL location)
noexcept

Save the preferences.

This will change the current preferences file to the location given.

Parameters
locationThe file to save the preferences to.

Field Documentation

◆ mutex

std::mutex v1::preferences::mutex
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.


The documentation for this class was generated from the following file: