JSON module

Configuration

JSON configuration file See base Configuration for all accessors

#include <icy/json/configuration.h>

class Configuration

Defined in src/json/include/icy/json/configuration.h:28

JSON configuration file

See base Configuration for all accessors

List of all members

NameKindOwner
rootvariableDeclared here
ConfigurationfunctionDeclared here
~ConfigurationfunctionDeclared here
loadfunctionDeclared here
loadfunctionDeclared here
savefunctionDeclared here
removefunctionDeclared here
removeAllfunctionDeclared here
replacefunctionDeclared here
keysfunctionDeclared here
printfunctionDeclared here
pathfunctionDeclared here
loadedfunctionDeclared here
_loadedvariableDeclared here
_pathvariableDeclared here
_mutexvariableDeclared here
getRawfunctionDeclared here
setRawfunctionDeclared here
PropertyChangedvariableInherited from Configuration
ConfigurationfunctionInherited from Configuration
~ConfigurationfunctionInherited from Configuration
existsfunctionInherited from Configuration
getStringfunctionInherited from Configuration
getStringfunctionInherited from Configuration
getRawStringfunctionInherited from Configuration
getRawStringfunctionInherited from Configuration
getIntfunctionInherited from Configuration
getIntfunctionInherited from Configuration
getLargeIntfunctionInherited from Configuration
getLargeIntfunctionInherited from Configuration
getDoublefunctionInherited from Configuration
getDoublefunctionInherited from Configuration
getBoolfunctionInherited from Configuration
getBoolfunctionInherited from Configuration
setStringfunctionInherited from Configuration
setIntfunctionInherited from Configuration
setLargeIntfunctionInherited from Configuration
setDoublefunctionInherited from Configuration
setBoolfunctionInherited from Configuration
getRawfunctionInherited from Configuration
setRawfunctionInherited from Configuration
ConfigurationfunctionInherited from Configuration
operator=functionInherited from Configuration
ConfigurationfunctionInherited from Configuration
operator=functionInherited from Configuration
_mutexvariableInherited from Configuration

Inherited from Configuration

KindNameDescription
variablePropertyChangedThe Key and Value of the changed configuration property.
functionConfigurationCreates the Configuration.
function~Configuration virtualDestroys the Configuration.
functionexists constReturns true if the property with the given key exists.
functiongetString constReturns the string value of the property with the given name. Throws a NotFoundException if the key does not exist.
functiongetString constIf a property with the given key exists, returns the property's string value, otherwise returns the given default value.
functiongetRawString constReturns the raw string value of the property with the given name. Throws a NotFoundException if the key does not exist. References to other properties are not expanded.
functiongetRawString constIf a property with the given key exists, returns the property's raw string value, otherwise returns the given default value. References to other properties are not expanded.
functiongetInt constReturns the int value of the property with the given name. Throws a NotFoundException if the key does not exist. Throws a SyntaxException if the property can not be converted to an int. Numbers starting with 0x are treated as hexadecimal.
functiongetInt constIf a property with the given key exists, returns the property's int value, otherwise returns the given default value. Throws a SyntaxException if the property can not be converted to an int. Numbers starting with 0x are treated as hexadecimal.
functiongetLargeInt constReturns the int value of the property with the given name. Throws a NotFoundException if the key does not exist. Throws a SyntaxException if the property can not be converted to an int. Numbers starting with 0x are treated as hexadecimal.
functiongetLargeInt constIf a property with the given key exists, returns the property's int value, otherwise returns the given default value. Throws a SyntaxException if the property can not be converted to an int. Numbers starting with 0x are treated as hexadecimal.
functiongetDouble constReturns the double value of the property with the given name. Throws a NotFoundException if the key does not exist. Throws a SyntaxException if the property can not be converted to a double.
functiongetDouble constIf a property with the given key exists, returns the property's double value, otherwise returns the given default value. Throws a SyntaxException if the property can not be converted to an double.
functiongetBool constReturns the double value of the property with the given name. Throws a NotFoundException if the key does not exist. Throws a SyntaxException if the property can not be converted to a double.
functiongetBool constIf a property with the given key exists, returns the property's bool value, otherwise returns the given default value. Throws a SyntaxException if the property can not be converted to a boolean. The following string values can be converted into a boolean:
functionsetStringSets the property with the given key to the given value. An already existing value for the key is overwritten.
functionsetIntSets the property with the given key to the given value. An already existing value for the key is overwritten.
functionsetLargeIntSets the property with the given key to the given value. An already existing value for the key is overwritten.
functionsetDoubleSets the property with the given key to the given value. An already existing value for the key is overwritten.
functionsetBoolSets the property with the given key to the given value. An already existing value for the key is overwritten.
functiongetRaw virtual constIf the property with the given key exists, stores the property's value in value and returns true. Otherwise, returns false.
functionsetRaw virtualSets the property with the given key to the given value. An already existing value for the key is overwritten.
functionConfigurationDeleted constructor.
functionoperator=Deleted assignment operator.
functionConfigurationDeleted constructor.
functionoperator=Deleted assignment operator.
variable_mutex

Public Attributes

ReturnNameDescription
json::Valueroot

root

json::Value root

Type: json::Value

Defined in src/json/include/icy/json/configuration.h:80

Public Methods

ReturnNameDescription
Configuration
~Configuration virtualDestroys the Configuration.
voidload virtualSets the file path and loads the configuration.
voidload virtualReloads the configuration from the previously set path. Silently ignores parse errors (e.g. empty file).
voidsave virtualWrites the current JSON root to the file at the stored path.
boolremove virtualRemoves the top-level key key from the JSON root.
voidremoveAll virtualRemoves all top-level keys whose names contain baseKey as a substring.
voidreplace virtualPerforms a global string substitution on the serialized JSON, replacing all occurrences of from with to, then re-parses.
voidkeys virtualPopulates keys with all top-level key names containing baseKey as a substring.
voidprint virtualWrites the pretty-printed JSON to ost with 4-space indentation.
std::stringpath virtualReturns the file path that was passed to load().
boolloaded virtualReturns true if load() has been called at least once.

Configuration

Configuration()

Defined in src/json/include/icy/json/configuration.h:31


~Configuration

virtual

virtual ~Configuration()

Defined in src/json/include/icy/json/configuration.h:32

Destroys the Configuration.

Reimplements


load

virtual

virtual void load(const std::string & path, bool create = false)

Defined in src/json/include/icy/json/configuration.h:38

Sets the file path and loads the configuration.

Parameters

ParameterTypeDescription
pathconst std::string &Absolute or relative path to the JSON file.
createboolReserved for future use (currently unused).

Exceptions

ExceptionDescription
std::runtime_errorif the path is empty.

load

virtual

virtual void load(bool create = false)

Defined in src/json/include/icy/json/configuration.h:44

Reloads the configuration from the previously set path. Silently ignores parse errors (e.g. empty file).

Parameters

ParameterTypeDescription
createboolReserved for future use (currently unused).

Exceptions

ExceptionDescription
std::runtime_errorif the path has not been set.

save

virtual

virtual void save()

Defined in src/json/include/icy/json/configuration.h:48

Writes the current JSON root to the file at the stored path.

Exceptions

ExceptionDescription
std::runtime_errorif the path is empty or the file cannot be written.

remove

virtual

virtual bool remove(const std::string & key)

Defined in src/json/include/icy/json/configuration.h:53

Removes the top-level key key from the JSON root.

Returns

true if the key existed and was removed.

Parameters

ParameterTypeDescription
keyconst std::string &Key to remove.

removeAll

virtual

virtual void removeAll(const std::string & baseKey)

Defined in src/json/include/icy/json/configuration.h:57

Removes all top-level keys whose names contain baseKey as a substring.

Parameters

ParameterTypeDescription
baseKeyconst std::string &Substring to match against key names.

replace

virtual

virtual void replace(const std::string & from, const std::string & to)

Defined in src/json/include/icy/json/configuration.h:63

Performs a global string substitution on the serialized JSON, replacing all occurrences of from with to, then re-parses.

Parameters

ParameterTypeDescription
fromconst std::string &Substring to find.
toconst std::string &Replacement string.

keys

virtual

virtual void keys(std::vector< std::string > & keys, const std::string & baseKey = "")

Defined in src/json/include/icy/json/configuration.h:68

Populates keys with all top-level key names containing baseKey as a substring.

Parameters

ParameterTypeDescription
keysstd::vector< std::string > &Output vector to append matching key names to.
baseKeyconst std::string &Filter substring; empty string matches all keys.

print

virtual

virtual void print(std::ostream & ost)

Defined in src/json/include/icy/json/configuration.h:72

Writes the pretty-printed JSON to ost with 4-space indentation.

Parameters

ParameterTypeDescription
oststd::ostream &Output stream.

path

virtual

virtual std::string path()

Defined in src/json/include/icy/json/configuration.h:75

Returns the file path that was passed to load().


loaded

virtual

virtual bool loaded()

Defined in src/json/include/icy/json/configuration.h:78

Returns true if load() has been called at least once.

Protected Attributes

ReturnNameDescription
bool_loaded
std::string_path
std::mutex_mutex

_loaded

bool _loaded

Defined in src/json/include/icy/json/configuration.h:94


_path

std::string _path

Defined in src/json/include/icy/json/configuration.h:95


_mutex

std::mutex _mutex

Defined in src/json/include/icy/json/configuration.h:96

Protected Methods

ReturnNameDescription
boolgetRaw virtual const overrideRetrieves the string value for key from the JSON root.
voidsetRaw virtual overrideStores value under key in the JSON root and emits PropertyChanged.

getRaw

virtual const override

virtual bool getRaw(const std::string & key, std::string & value) const override

Defined in src/json/include/icy/json/configuration.h:87

Retrieves the string value for key from the JSON root.

Returns

true if the key was found, false otherwise.

Reimplements

Parameters

ParameterTypeDescription
keyconst std::string &Top-level JSON key.
valuestd::string &Set to the string value if the key exists.

setRaw

virtual override

virtual void setRaw(const std::string & key, const std::string & value) override

Defined in src/json/include/icy/json/configuration.h:92

Stores value under key in the JSON root and emits PropertyChanged.

Reimplements

Parameters

ParameterTypeDescription
keyconst std::string &Top-level JSON key.
valueconst std::string &String value to store.