diff options
| author | untodesu <kirill@untode.su> | 2025-06-25 00:44:36 +0500 |
|---|---|---|
| committer | untodesu <kirill@untode.su> | 2025-06-25 00:44:36 +0500 |
| commit | 88c01588aa0830e219eaa62588839e4d1e2883ce (patch) | |
| tree | 602bb27dd3399aab4aae8c19630e3b7a8dac824b /core/config.cc | |
| parent | 99cf6cca8dbbc1e563c10cf0167432d3d8af9783 (diff) | |
| download | voxelius-88c01588aa0830e219eaa62588839e4d1e2883ce.tar.bz2 voxelius-88c01588aa0830e219eaa62588839e4d1e2883ce.zip | |
Clang-format the entire source code
Diffstat (limited to 'core/config.cc')
| -rw-r--r-- | core/config.cc | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/core/config.cc b/core/config.cc index 94a8c1b..52cd102 100644 --- a/core/config.cc +++ b/core/config.cc @@ -1,4 +1,5 @@ #include "core/pch.hh" + #include "core/config.hh" #include "core/cmdline.hh" @@ -11,13 +12,13 @@ ConfigBoolean::ConfigBoolean(bool default_value) m_string = ConfigBoolean::to_string(default_value); } -void ConfigBoolean::set(const char *value) +void ConfigBoolean::set(const char* value) { m_value = ConfigBoolean::from_string(value); m_string = ConfigBoolean::to_string(m_value); } -const char *ConfigBoolean::get(void) const +const char* ConfigBoolean::get(void) const { return m_string.c_str(); } @@ -33,31 +34,35 @@ void ConfigBoolean::set_value(bool value) m_string = ConfigBoolean::to_string(m_value); } -const char *ConfigBoolean::to_string(bool value) +const char* ConfigBoolean::to_string(bool value) { - if(value) + if(value) { return "true"; - return "false"; + } else { + return "false"; + } } -bool ConfigBoolean::from_string(const char *value) +bool ConfigBoolean::from_string(const char* value) { - if(std::strcmp(value, "false") && !std::strcmp(value, "true")) + if(std::strcmp(value, "false") && !std::strcmp(value, "true")) { return true; - return false; + } else { + return false; + } } -ConfigString::ConfigString(const char *default_value) +ConfigString::ConfigString(const char* default_value) { m_value = default_value; } -void ConfigString::set(const char *value) +void ConfigString::set(const char* value) { m_value = value; } -const char *ConfigString::get(void) const +const char* ConfigString::get(void) const { return m_value.c_str(); } @@ -71,7 +76,7 @@ void Config::load_cmdline(void) } } -bool Config::load_file(const char *path) +bool Config::load_file(const char* path) { if(auto file = PHYSFS_openRead(path)) { auto source = std::string(PHYSFS_fileLength(file), char(0x00)); @@ -85,9 +90,11 @@ bool Config::load_file(const char *path) while(std::getline(stream, line)) { auto comment = line.find_first_of('#'); - if(comment == std::string::npos) + if(comment == std::string::npos) { kv_string = strtools::trim_whitespace(line); - else kv_string = strtools::trim_whitespace(line.substr(0, comment)); + } else { + kv_string = strtools::trim_whitespace(line.substr(0, comment)); + } if(strtools::is_whitespace(kv_string)) { // Ignore empty or commented out lines @@ -120,7 +127,7 @@ bool Config::load_file(const char *path) return false; } -bool Config::save_file(const char *path) const +bool Config::save_file(const char* path) const { std::ostringstream stream; @@ -129,7 +136,7 @@ bool Config::save_file(const char *path) const stream << "# Voxelius " << PROJECT_VERSION_STRING << " configuration file" << std::endl; stream << "# Generated at: " << std::put_time(std::gmtime(&curtime), "%Y-%m-%d %H:%M:%S %z") << std::endl << std::endl; - for(const auto &it : m_values) { + for(const auto& it : m_values) { stream << it.first << "="; stream << it.second->get(); stream << std::endl; @@ -145,7 +152,7 @@ bool Config::save_file(const char *path) const return false; } -bool Config::set_value(const char *name, const char *value) +bool Config::set_value(const char* name, const char* value) { auto kv_pair = m_values.find(name); @@ -157,23 +164,28 @@ bool Config::set_value(const char *name, const char *value) return false; } -const char *Config::get_value(const char *name) const +const char* Config::get_value(const char* name) const { auto kv_pair = m_values.find(name); - if(kv_pair != m_values.cend()) + if(kv_pair != m_values.cend()) { return kv_pair->second->get(); - return nullptr; + } else { + return nullptr; + } } -void Config::add_value(const char *name, IConfigValue &vref) +void Config::add_value(const char* name, IConfigValue& vref) { m_values.insert_or_assign(name, &vref); } -const IConfigValue *Config::find(const char *name) const +const IConfigValue* Config::find(const char* name) const { auto kv_pair = m_values.find(name); - if(kv_pair != m_values.cend()) + + if(kv_pair != m_values.cend()) { return kv_pair->second; - return nullptr; + } else { + return nullptr; + } } |
