JSON module

Configuration

JSON configuration file See base [Configuration]({#ref classicy_1_1json_1_1Configuration #}) for all accessors

Configuration

#include <icy/json/configuration.h>

Inherits: Configuration

JSON configuration file

See base Configuration for all accessors

Public Attributes

ReturnNameDescription
json::Valueroot

root

json::Value root

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()

~Configuration

virtual

virtual ~Configuration()

Destroys the Configuration.


load

virtual

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

Sets the file path and loads the configuration.

Parameters

  • path Absolute or relative path to the JSON file.

  • create Reserved for future use (currently unused).

Exceptions

  • std::runtime_error if the path is empty.

load

virtual

virtual void load(bool create)

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

Parameters

  • create Reserved for future use (currently unused).

Exceptions

  • std::runtime_error if the path has not been set.

save

virtual

virtual void save()

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

Exceptions

  • std::runtime_error if the path is empty or the file cannot be written.

remove

virtual

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

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

Parameters

  • key Key to remove.

Returns

true if the key existed and was removed.


removeAll

virtual

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

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

Parameters

  • baseKey Substring to match against key names.

replace

virtual

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

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

Parameters

  • from Substring to find.

  • to Replacement string.


keys

virtual

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

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

Parameters

  • keys Output vector to append matching key names to.

  • baseKey Filter substring; empty string matches all keys.


print

virtual

virtual void print(std::ostream & ost)

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

Parameters

  • ost Output stream.

path

virtual

virtual std::string path()

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


loaded

virtual

virtual bool loaded()

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

Protected Attributes

ReturnNameDescription
bool_loaded
std::string_path
std::mutex_mutex

_loaded

bool _loaded

_path

std::string _path

_mutex

std::mutex _mutex

Protected Methods

ReturnNameDescription
boolgetRaw virtual constRetrieves the string value for key from the JSON root.
voidsetRaw virtualStores value under key in the JSON root and emits PropertyChanged.

getRaw

virtual const

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

Retrieves the string value for key from the JSON root.

Parameters

  • key Top-level JSON key.

  • value Set to the string value if the key exists.

Returns

true if the key was found, false otherwise.


setRaw

virtual

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

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

Parameters

  • key Top-level JSON key.

  • value String value to store.