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

#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
 
preferencesoperator= (preferences const &)=delete
 
preferencesoperator= (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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ preferences() [1/2]

v1::preferences::preferences ( )
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.

◆ preferences() [2/2]

v1::preferences::preferences ( std::filesystem::path location)
inlinenoexcept

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,
observer< T > const & item,
T init = T{} )
inlinenoexcept

Register an observer to a preferences file.

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

◆ load() [1/2]

void v1::preferences::load ( )
inlinenoexcept

Load the preferences.

This will load the preferences from the current selected file.

◆ load() [2/2]

void v1::preferences::load ( std::filesystem::path location)
inlinenoexcept

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 ( )
inlinenoexcept

Reset data members to their default value.

◆ save() [1/2]

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

Save the preferences.

This will load the preferences from the current selected file.

◆ save() [2/2]

void v1::preferences::save ( std::filesystem::path location)
inlinenoexcept

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: