Configuration
Configuration
#include <icy/json/configuration.h>Inherits:
Configuration
JSON configuration file
See base Configuration for all accessors
Public Attributes
| Return | Name | Description |
|---|---|---|
json::Value | root |
root
json::Value rootPublic Methods
| Return | Name | Description |
|---|---|---|
Configuration | ||
~Configuration virtual | Destroys the Configuration. | |
void | load virtual | Sets the file path and loads the configuration. |
void | load virtual | Reloads the configuration from the previously set path. Silently ignores parse errors (e.g. empty file). |
void | save virtual | Writes the current JSON root to the file at the stored path. |
bool | remove virtual | Removes the top-level key key from the JSON root. |
void | removeAll virtual | Removes all top-level keys whose names contain baseKey as a substring. |
void | replace virtual | Performs a global string substitution on the serialized JSON, replacing all occurrences of from with to, then re-parses. |
void | keys virtual | Populates keys with all top-level key names containing baseKey as a substring. |
void | print virtual | Writes the pretty-printed JSON to ost with 4-space indentation. |
std::string | path virtual | Returns the file path that was passed to load(). |
bool | loaded virtual | Returns 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
pathAbsolute or relative path to the JSON file.createReserved for future use (currently unused).
Exceptions
std::runtime_errorif 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
createReserved for future use (currently unused).
Exceptions
std::runtime_errorif 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_errorif 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
keyKey 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
baseKeySubstring 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
fromSubstring to find.toReplacement 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
keysOutput vector to append matching key names to.baseKeyFilter substring; empty string matches all keys.
virtual
virtual void print(std::ostream & ost)Writes the pretty-printed JSON to ost with 4-space indentation.
Parameters
ostOutput 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
_loaded
bool _loaded_path
std::string _path_mutex
std::mutex _mutexProtected Methods
| Return | Name | Description |
|---|---|---|
bool | getRaw virtual const | Retrieves the string value for key from the JSON root. |
void | setRaw virtual | Stores value under key in the JSON root and emits PropertyChanged. |
getRaw
virtual const
virtual bool getRaw(const std::string & key, std::string & value) constRetrieves the string value for key from the JSON root.
Parameters
keyTop-level JSON key.valueSet 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
keyTop-level JSON key.valueString value to store.
