![]() |
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) |
Checks if config exists and flags if a config needs to be created. | |
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 is missing. | |
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 is missing. | |
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> | |
Value | get (const std::string &key) |
Retrieve a root config value. | |
template<meta::standard_type Value> | |
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 | |
bool | m_loaded |
Config loaded flag. | |
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 24 of file Config.hpp.
|
noexcept |
Constructor.
Definition at line 16 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 22 of file Config.cpp.
|
noexcept |
Destructor.
Definition at line 30 of file Config.cpp.
|
privatedelete |
Copy constructor.
|
privatedelete |
Move constructor.
void galaxy::core::Config::load | ( | std::string_view | file | ) |
Checks if config exists and flags if a config needs to be created.
Also sets up filepath and json.
file | Path to config to open / use (does not matter if does not exist). This is relative to the app. |
Definition at line 36 of file Config.cpp.
void galaxy::core::Config::save | ( | ) |
Save the config file. Must be opened first.
Definition at line 75 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 224 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 237 of file Config.hpp.
|
inlinenoexcept |
Sets a new setting, only if key or value is missing.
Value | Standard JSON type to use. |
key | Name of the variable. |
value | The variable value to set. |
Definition at line 271 of file Config.hpp.
|
inline |
Sets a new setting, only if key or value is missing.
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 280 of file Config.hpp.
|
nodiscardnoexcept |
Check if the config file actually has a value.
key | Name of the value to check. |
Definition at line 98 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 108 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 289 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 311 of file Config.hpp.
|
nodiscard |
Is the config file blank.
Definition at line 144 of file Config.cpp.
|
noexcept |
Set as external json object.
json | New json config data to set. |
Definition at line 154 of file Config.cpp.
|
nodiscardnoexcept |
Get raw json object.
Definition at line 160 of file Config.cpp.
|
private |
Config loaded flag.
Definition at line 210 of file Config.hpp.
|
private |
Config file as JSON.
Definition at line 215 of file Config.hpp.
|
private |
Filepath.
Definition at line 220 of file Config.hpp.