![]() |
galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
|
Allows you to read, write and manipulate JSON config files. More...
#include <Config.hpp>
Public Member Functions | |
Config () noexcept | |
Constructor. | |
Config (std::string_view file) noexcept | |
Argument constructor. | |
~Config () noexcept | |
Destructor. | |
void | load (std::string_view file) |
Loads config json from disk. | |
void | save () |
Save the config file. Must be opened first. | |
template<meta::standard_type Value> | |
void | set (const std::string &key, const Value &value) noexcept |
Set a new key-value pair for the config. | |
template<meta::standard_type Value> | |
void | set (const std::string &key, const Value &value, const std::string §ion, const std::string &delim=".") |
Sets a new key-value pair in a section. Can use a delimiter to seperate sections. | |
template<meta::standard_type Value> | |
void | restore (const std::string &key, const Value &value) noexcept |
Sets a new setting, only if key or value does not already exist. | |
template<meta::standard_type Value> | |
void | restore (const std::string &key, const Value &value, const std::string §ion, const std::string &delim=".") |
Sets a new setting, only if key or value does not already exist. | |
bool | has (const std::string &key) noexcept |
Check if the config file actually has a value. | |
bool | has (const std::string &key, const std::string §ion, const std::string &delim=".") |
Check if the config file actually has a value. | |
template<meta::standard_type Value> | |
std::optional< Value > | get (const std::string &key) |
Retrieve a root config value. | |
template<meta::standard_type Value> | |
std::optional< Value > | get (const std::string &key, const std::string §ion, const std::string &delim=".") |
Retrieve a config value in a section. | |
bool | empty () const |
Is the config file blank. | |
void | raw (const nlohmann::json &json) noexcept |
Set as external json object. | |
const nlohmann::json & | raw () const noexcept |
Get raw json object. | |
Private Member Functions | |
Config (const Config &)=delete | |
Copy constructor. | |
Config (Config &&)=delete | |
Move constructor. | |
Config & | operator= (const Config &)=delete |
Copy assignment operator. | |
Config & | operator= (Config &&)=delete |
Move assignment operator. | |
Private Attributes | |
nlohmann::json | m_config |
Config file as JSON. | |
std::string | m_path |
Filepath. | |
Allows you to read, write and manipulate JSON config files.
Definition at line 22 of file Config.hpp.
|
noexcept |
Constructor.
Definition at line 14 of file Config.cpp.
|
noexcept |
Argument constructor.
Calls load().
file | Path to config to open / use (does not matter if does not exist). This is relative to the app. |
Definition at line 19 of file Config.cpp.
|
noexcept |
Destructor.
Definition at line 25 of file Config.cpp.
|
privatedelete |
Copy constructor.
|
privatedelete |
Move constructor.
void galaxy::Config::load | ( | std::string_view | file | ) |
Loads config json from disk.
Will override any existing configuration.
file | Path to config to open / use (does not matter if does not exist). This is relative to the app. |
Definition at line 30 of file Config.cpp.
void galaxy::Config::save | ( | ) |
Save the config file. Must be opened first.
Definition at line 59 of file Config.cpp.
|
inlinenoexcept |
Set a new key-value pair for the config.
Will create if not exist, otherwise update.
Value | Standard JSON type to use. |
key | Name of the variable. |
value | The variable value to set. |
Definition at line 217 of file Config.hpp.
|
inline |
Sets a new key-value pair in a section. Can use a delimiter to seperate sections.
Will create if not exist, otherwise update.
Value | Standard JSON type to use. |
key | Name of the variable. |
value | The variable value to set. |
section | Section of the config file to use. Can use a delimiter to seperate sections. |
delim | Delimiter to seperate sections with. Optional. |
Definition at line 223 of file Config.hpp.
|
inlinenoexcept |
Sets a new setting, only if key or value does not already exist.
Value | Standard JSON type to use. |
key | Name of the variable. |
value | The variable value to set. |
Definition at line 250 of file Config.hpp.
|
inline |
Sets a new setting, only if key or value does not already exist.
Value | Standard JSON type to use. |
key | Name of the variable. |
value | The variable value to set. |
section | Section of the config file to use. Can use a delimiter to seperate sections. |
delim | Delimiter to seperate sections with. Optional. |
Definition at line 259 of file Config.hpp.
|
nodiscardnoexcept |
Check if the config file actually has a value.
key | Name of the value to check. |
Definition at line 68 of file Config.cpp.
|
nodiscard |
Check if the config file actually has a value.
key | Key to lookup value. |
section | Delimiter seperated sections. |
delim | Delimiter to use. Optional. |
Definition at line 73 of file Config.cpp.
|
inlinenodiscard |
Retrieve a root config value.
Value | Standard JSON type to use. |
key | Name of the value to retrieve. |
Definition at line 268 of file Config.hpp.
|
inlinenodiscard |
Retrieve a config value in a section.
Value | Standard JSON type to use. |
key | Key to lookup value. |
section | Delimiter seperated sections. |
delim | Delimiter to use. Optional. |
Definition at line 281 of file Config.hpp.
|
nodiscard |
Is the config file blank.
Definition at line 106 of file Config.cpp.
|
noexcept |
Set as external json object.
json | New json config data to set. |
Definition at line 111 of file Config.cpp.
|
nodiscardnoexcept |
Get raw json object.
Definition at line 116 of file Config.cpp.
|
private |
Config file as JSON.
Definition at line 208 of file Config.hpp.
|
private |
Filepath.
Definition at line 213 of file Config.hpp.