19 m_config =
"{\"config\":{}}"_json;
25 m_config =
"{\"config\":{}}"_json;
38 auto path = std::filesystem::path(file);
41 if (!std::filesystem::exists(path))
43 std::ofstream ofs {
m_path, std::ofstream::out | std::ofstream::trunc};
58 std::ifstream input {
m_path, std::ifstream::in};
79 std::ofstream ofs {
m_path, std::ofstream::out | std::ofstream::trunc};
102 return m_config[
"config"].contains(key);
108 bool Config::has(
const std::string& key,
const std::string& section,
const std::string& delim)
113 if (sections.empty())
116 const auto& root =
m_config[
"config"];
117 if (root.contains(section))
119 return root[section].contains(key);
125 nlohmann::json* leaf = &
m_config[
"config"];
126 for (
const auto& sec : sections)
128 if (leaf->contains(sec))
130 leaf = &leaf->at(sec);
134 if (leaf->contains(key))
148 return m_config.at(
"config").empty();
#define GALAXY_LOG(level, msg,...)
nlohmann::json m_config
Config file as JSON.
const nlohmann::json & raw() const noexcept
Get raw json object.
~Config() noexcept
Destructor.
bool empty() const
Is the config file blank.
void save()
Save the config file. Must be opened first.
bool has(const std::string &key) noexcept
Check if the config file actually has a value.
void load(std::string_view file)
Checks if config exists and flags if a config needs to be created.
Config() noexcept
Constructor.
bool m_loaded
Config loaded flag.
std::string m_path
Filepath.
std::vector< std::string > split(std::string_view input, std::string_view delim) noexcept
Split a string based on a delimiter.