Krotos Modules 3
Loading...
Searching...
No Matches
krotos::SettingsFile Class Referencefinal

A class to manage the settings.json file, derived privately from JsonFile. More...

#include <SettingsFile.h>

Inheritance diagram for krotos::SettingsFile:
krotos::JsonFile

Public Member Functions

 SettingsFile (const File &settingsFile)
 Constructor that initializes the SettingsFile with a given File object.
 
var getSetting (const Identifier &key)
 Retrieves the value associated with a given key.
 
void setSetting (const Identifier &key, const var &value)
 Sets the value associated with a given key in the settings.
 
String getSettingsVersion () const
 Retrieves the settings version from the JSON data. This function retrieves the settings version from the JSON data stored in the SettingsFile object.
 
void setSettingsVersion (const String &version)
 Sets the settings version in the JSON data. This function sets the settings version in the JSON data of the SettingsFile object.
 
bool existsAsFile ()
 Checks if the associated JSON file exists as a file.
 
void setDefaultIfVoid (const Identifier &key, const var &defaultValue)
 Sets the default value (if required) associated with a given key in the settings.
 

Additional Inherited Members

- Private Member Functions inherited from krotos::JsonFile
 JsonFile (File jsonFile, const Identifier &defaultProperty, const String &defaultFormat)
 Simple helper class for handling json files. It will attempt to create a json file with the given default property and format, or if the given json file already exists, it will attempt to parse it and check it has the default property.
 
var getDefaultProperty () const
 Get the variant for the default property.
 
const String & getDefaultFormat () const
 Gets the underlying default formatted json, this is used as a fallback when an invalid input is passed to the JSON file.
 
void initialise ()
 Parse the file if it exists, or create it if it doesn't. Data is parsed to m_data;.
 
void save ()
 Call save internal.
 
void createJsonFromDefaultFormat ()
 Generate the JSON file using the default format - used in cases where JSON fails to load.
 
- Private Attributes inherited from krotos::JsonFile
var m_data
 The parsed json data.
 
File m_jsonFile
 The json file.
 

Detailed Description

A class to manage the settings.json file, derived privately from JsonFile.

This class provides methods to get and set settings using a JSON file.

Constructor & Destructor Documentation

◆ SettingsFile()

krotos::SettingsFile::SettingsFile ( const File & settingsFile)

Constructor that initializes the SettingsFile with a given File object.

Parameters
settingsFileA reference to a File object representing the settings file.

Member Function Documentation

◆ existsAsFile()

bool krotos::SettingsFile::existsAsFile ( )
inline

Checks if the associated JSON file exists as a file.

Returns
A boolean value that is true if the JSON file exists as a file, false otherwise.

◆ getSetting()

var krotos::SettingsFile::getSetting ( const Identifier & key)

Retrieves the value associated with a given key.

Parameters
keyAn Identifier representing the key to look for in the settings.
Returns
A var containing the value associated with the given key.

◆ getSettingsVersion()

String krotos::SettingsFile::getSettingsVersion ( ) const

Retrieves the settings version from the JSON data. This function retrieves the settings version from the JSON data stored in the SettingsFile object.

Returns
A String containing the settings version.

◆ setDefaultIfVoid()

void krotos::SettingsFile::setDefaultIfVoid ( const Identifier & key,
const var & defaultValue )

Sets the default value (if required) associated with a given key in the settings.

Parameters
keyAn Identifier representing the key to associate with the value.
defaultValueA var containing the desired default value.

◆ setSetting()

void krotos::SettingsFile::setSetting ( const Identifier & key,
const var & value )

Sets the value associated with a given key in the settings.

Parameters
keyAn Identifier representing the key to associate with the value.
valueA var containing the value to set for the given key.

◆ setSettingsVersion()

void krotos::SettingsFile::setSettingsVersion ( const String & version)

Sets the settings version in the JSON data. This function sets the settings version in the JSON data of the SettingsFile object.

Parameters
versionA String representing the new settings version to set.

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