libnick 2025.10.0
A cross-platform base for native Nickvision applications.
|
A base class for thread-safe json data files. More...
#include <jsonfilebase.h>
Public Member Functions | |
JsonFileBase (const std::filesystem::path &path) | |
Constructs a JsonFileBase, loading the file from disk. | |
virtual | ~JsonFileBase () noexcept=default |
Destructs a JsonFileBase. | |
const std::filesystem::path & | getPath () const noexcept |
Gets the path of the json file. | |
Events::Event< Events::EventArgs > & | saved () noexcept |
Gets the Saved event. | |
bool | save () noexcept |
Saves the config file to disk. | |
boost::json::value | toJson () const noexcept override |
Serializes the object to Json. | |
Public Member Functions inherited from Nickvision::Helpers::IJsonSerializable | |
virtual | ~IJsonSerializable ()=default |
Protected Member Functions | |
bool | contains (const std::string &key) const noexcept |
Gets whether or not the json object contains a key. | |
template<SupportedJsonValue T> | |
T | get (const std::string &key, const T &defaultValue) const noexcept |
Gets a value from the json object. | |
template<SupportedJsonValue T> | |
void | set (const std::string &key, const T &value) noexcept |
Sets a value in the json object. |
A base class for thread-safe json data files.
Nickvision::Helpers::JsonFileBase::JsonFileBase | ( | const std::filesystem::path & | path | ) |
Constructs a JsonFileBase, loading the file from disk.
path | The path to the json file |
std::invalid_argument | Thrown if the path is empty |
|
virtualdefaultnoexcept |
Destructs a JsonFileBase.
|
protectednoexcept |
Gets whether or not the json object contains a key.
|
inlineprotectednoexcept |
Gets a value from the json object.
T | The type of the value to get |
key | The key of the value to get |
defaultValue | The default value to return if the key is not found or if the value is not of the expected type |
|
noexcept |
Gets the path of the json file.
|
noexcept |
Saves the config file to disk.
|
noexcept |
Gets the Saved event.
|
inlineprotectednoexcept |
Sets a value in the json object.
T | The type of the value to set |
key | The key of the value to set |
value | The value to set |
|
overridevirtualnoexcept |
Serializes the object to Json.
Implements Nickvision::Helpers::IJsonSerializable.