![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Core/GlobalSettings.h>
Class for storing and retrieving persistent global settings. More...
Class for storing and retrieving persistent global settings.
This class allows you to load and store single values, as well as entire Configurable objects in a persistent manner across application sessions.
This class must be initialized with init() before any usage. Typically this would be done on program startup. In order for the changes to settings to be persisted, sync() must be called. This is typically done on program exit, but can also be called at any time.
There are several interfaces provided for loading and storing settings:
/
character (cf. path spec of Properties).The setting are stored in the following locations by default depending on the platform:
$HOME/.config/<org>/<app>.json
$HOME/Library/Preferences/<org>/<app>.json
APPDATA%/<org>/<app>.json
Where org and app must be specified by calling init() once in the application.
Static Public Member Functions | |
static void | init (const std::string &org, const std::string &app) |
Initialize the Settings with the default file location. | |
static void | init (const Filesystem::Path &configFilePath) |
Initialize the Settings with a custom file location. | |
template<typename T> | |
static bool | load (T &configurable) |
Loads the parameters for Configurable type T from global settings into configurable. | |
static bool | load (const std::string &name, Configurable &configurable) |
Load the parameters for name from the global settings into configurable. | |
template<typename T> | |
static std::optional< Properties > | load () |
Load the parameters for Configurable type T from the global settings. | |
static std::optional< Properties > | load (const std::string &name) |
Load the parameters for name from the global settings. | |
template<typename T> | |
static std::optional< T > | loadValue (const std::string &name) |
Load the value for name from the global settings. | |
template<typename T> | |
static void | store (const T &configurable) |
Stores the parameters for Configurable type T in the global settings from configurable. | |
static void | store (const std::string &name, const Configurable &configurable) |
Store the parameters for name in the global settings from configurable. | |
template<typename T> | |
static void | store (const Properties &properties) |
Store the parameters for Configurable type T in the global settings from properties. | |
static void | store (const std::string &name, const Properties &properties) |
Store the parameters for name in the global settings from properties. | |
template<typename T> | |
static void | storeValue (const std::string &name, const T &value) |
Store the value for name in the global settings. | |
template<typename T> | |
static void | storeValue (const std::string &name, const T &value, const T &defaultValue) |
Store the value for name in the global settings with a default value. | |
template<typename T> | |
static bool | remove () |
Remove the settings for Configurable type T from the global settings. | |
static bool | remove (const std::string &name) |
Remove the settings for name from the global settings. | |
static bool | sync () noexcept |
Synchronize the settings with disk. | |
static bool | importFrom (const Filesystem::Path &path) |
Import settings from a file. | |
static bool | exportTo (const Filesystem::Path &path) |
Export settings to a file. | |
static const Properties & | properties () |
Return the entire global settings as a Properties instance. | |
static void | setToDefaults () |
Set setting parameters that have default values to their defaults. | |
static void | setTo (const Properties &properties) |
Set the entire global settings to the given properties. | |
static Filesystem::Path | filePath () |
Return the path to the settings file. | |
template<typename T> | |
static std::string | settingsName () |
Return the name used for the settings of the type T. | |
|
static |
|
static |
|
static |
Loads the parameters for Configurable type T from global settings into configurable.
Returns false if no settings for T were found.
|
static |
Load the parameters for name from the global settings into configurable.
Returns false if no settings for name were found.
|
static |
Remove the settings for Configurable type T from the global settings.
Returns true if the settings existed.
|
static |
Remove the settings for name from the global settings.
Returns true if the settings existed.
|
static |
Set the entire global settings to the given properties.
This will not remove any settings currently on disk after sync(), but will overwrite the values if different.