Documentation for OpenFLUID 2.2.0
openfluid::tools::SettingsBackend Class Reference

Detailed Description

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>

Public Member Functions

 SettingsBackend (const std::string &BackendFile="", bool AutoSave=true)
 
 ~SettingsBackend ()
 
std::string getBackendFilePath () const
 
void enableAutoSave (bool AutoSave)
 
bool isAutoSave () const
 
bool save () const
 
void writeToStream (std::ostream &OutS) const
 
openfluid::thirdparty::jsondata ()
 
const SettingValue getValue (const std::string &Pointer) const
 
void setValue (const std::string &ParentPointer, const std::string &Key, const SettingValue &Value, bool AutoCreate=true)
 
void remove (const std::string &Pointer)
 
bool exists (const std::string &Pointer) const
 

Constructor & Destructor Documentation

◆ 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]BackendFilePath to file where settings are stored. Default is empty (no persistent storage)
[in]AutoSaveIf true, automatically saves settings to file (i any) at each modification. Enabled by default

◆ ~SettingsBackend()

openfluid::tools::SettingsBackend::~SettingsBackend ( )

Member Function Documentation

◆ data()

openfluid::thirdparty::json& openfluid::tools::SettingsBackend::data ( )
inline

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]AutoSavetrue 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]Pointerthe 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]PointerThe 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]Pointerthe 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]ParentPointerthe parent pointer in which the key/value will be created or updated
[in]Keythe key for the value
[in]Valuethe value
[in]AutoCreateif 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]OutSThe stream in which the JSON is written

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