Manages settings using a JSON-based backend. The JSON structure is stored under a key representing the "role" of the settings
e.g. with a "myapp-config" role
{
"myapp-config": {
"automatic": true,
"properties": {
"size": 5,
"color": "blue"
},
"last_use": "2021-07-16 14:11:37"
}
}
Access to values is made using JSON pointers (see rfc6901 https://datatracker.ietf.org/doc/html/rfc6901)
#include <tools/SettingsBackend.hpp>
◆ SettingsBackend()
openfluid::tools::SettingsBackend::SettingsBackend |
( |
const std::string & |
BackendFile = "" , |
|
|
bool |
AutoSave = true |
|
) |
| |
Constructor of for a settings backend. If no BackendFile is given, the settings are not persistent and will be lost when the object is destroyed.
- Parameters
-
[in] | BackendFile | Path to file where settings are stored. Default is empty (no persistent storage) |
[in] | AutoSave | If true, automatically saves settings to file (i any) at each modification. Enabled by default |
◆ ~SettingsBackend()
openfluid::tools::SettingsBackend::~SettingsBackend |
( |
| ) |
|
◆ data()
Returns a reference to the raw JSON data structure
- Returns
- a reference to the JSON document
◆ enableAutoSave()
void openfluid::tools::SettingsBackend::enableAutoSave |
( |
bool |
AutoSave | ) |
|
|
inline |
Enables or disables the automatic saving to backend file
- Parameters
-
[in] | AutoSave | true to enable, false to disable |
◆ exists()
bool openfluid::tools::SettingsBackend::exists |
( |
const std::string & |
Pointer | ) |
const |
Checks if a value exists at the location given by the pointer
- Parameters
-
[in] | Pointer | the pointer to the value to check |
◆ getBackendFilePath()
std::string openfluid::tools::SettingsBackend::getBackendFilePath |
( |
| ) |
const |
|
inline |
Returns the path of the backend file for persistance
- Returns
- The path to the backend file
◆ getValue()
const SettingValue openfluid::tools::SettingsBackend::getValue |
( |
const std::string & |
Pointer | ) |
const |
Gets a value located at the given pointer. If the pointed location does not exist, a null value is returned
- Parameters
-
[in] | Pointer | The pointer to the requested value |
- Returns
- the value located at the pointer
◆ isAutoSave()
bool openfluid::tools::SettingsBackend::isAutoSave |
( |
| ) |
const |
|
inline |
Returns the status of the automatic saving (enabled/disabled)
- Returns
- true if enabled, false if disabled
◆ remove()
void openfluid::tools::SettingsBackend::remove |
( |
const std::string & |
Pointer | ) |
|
Removes the value located by the given pointer
- Parameters
-
[in] | Pointer | the pointer to the value to remove |
◆ save()
bool openfluid::tools::SettingsBackend::save |
( |
| ) |
const |
Triggers the saving of the settings to the backend file
- Returns
- true if the operation has been completed
◆ setValue()
void openfluid::tools::SettingsBackend::setValue |
( |
const std::string & |
ParentPointer, |
|
|
const std::string & |
Key, |
|
|
const SettingValue & |
Value, |
|
|
bool |
AutoCreate = true |
|
) |
| |
Creates or updates a value named by its key as a child of the parent pointer
- Parameters
-
[in] | ParentPointer | the parent pointer in which the key/value will be created or updated |
[in] | Key | the key for the value |
[in] | Value | the value |
[in] | AutoCreate | if true, the path of the parent pointer is automatically created if it does not exist. Default is true |
◆ writeToStream()
void openfluid::tools::SettingsBackend::writeToStream |
( |
std::ostream & |
OutS | ) |
const |
Writes the JSON structure of the settings to a stream
- Parameters
-
[out] | OutS | The stream in which the JSON is written |
The documentation for this class was generated from the following file: