diff --git a/src/xenia/base/cvar.cc b/src/xenia/base/cvar.cc index d7c82c970..3300a0b7c 100644 --- a/src/xenia/base/cvar.cc +++ b/src/xenia/base/cvar.cc @@ -37,13 +37,13 @@ void ParseLaunchArguments(int argc, char** argv) { } for (auto& it : *CmdVars) { auto cmdVar = static_cast(it.second); - if (result.count(cmdVar->GetName())) { + if (result.count(cmdVar->name())) { cmdVar->LoadFromLaunchOptions(&result); } } for (auto& it : *ConfigVars) { auto configVar = static_cast(it.second); - if (result.count(configVar->GetName())) { + if (result.count(configVar->name())) { configVar->LoadFromLaunchOptions(&result); } } diff --git a/src/xenia/base/cvar.h b/src/xenia/base/cvar.h index 447128c36..a4c8c5d9b 100644 --- a/src/xenia/base/cvar.h +++ b/src/xenia/base/cvar.h @@ -10,8 +10,8 @@ namespace cvar { class ICommandVar { public: virtual ~ICommandVar() = default; - virtual std::string GetName() = 0; - virtual std::string GetDescription() = 0; + virtual const std::string& name() const = 0; + virtual const std::string& description() const = 0; virtual void UpdateValue() = 0; virtual void AddToLaunchOptions(cxxopts::Options* options) = 0; virtual void LoadFromLaunchOptions(cxxopts::ParseResult* result) = 0; @@ -19,9 +19,9 @@ class ICommandVar { class IConfigVar : virtual public ICommandVar { public: - virtual std::string GetCategory() = 0; - virtual bool GetIsTransient() = 0; - virtual std::string GetConfigValue() = 0; + virtual const std::string& category() const = 0; + virtual bool is_transient() const = 0; + virtual std::string config_value() const = 0; virtual void LoadConfigValue(std::shared_ptr result) = 0; virtual void LoadGameConfigValue(std::shared_ptr result) = 0; }; @@ -29,18 +29,18 @@ class IConfigVar : virtual public ICommandVar { template class CommandVar : virtual public ICommandVar { public: - CommandVar(const char* name, T* defaultValue, const char* description); - std::string GetName() override; - std::string GetDescription() override; + CommandVar(const char* name, T* default_value, const char* description); + const std::string& name() const override; + const std::string& description() const override; void AddToLaunchOptions(cxxopts::Options* options) override; void LoadFromLaunchOptions(cxxopts::ParseResult* result) override; - T* GetCurrentValue() { return currentValue_; } + T* current_value() { return current_value_; } protected: std::string name_; - T defaultValue_; - T* currentValue_; - std::unique_ptr commandLineValue_; + T default_value_; + T* current_value_; + std::unique_ptr commandline_value_; std::string description_; T Convert(std::string val); static std::string ToString(T val); @@ -53,11 +53,11 @@ class CommandVar : virtual public ICommandVar { template class ConfigVar : public CommandVar, virtual public IConfigVar { public: - ConfigVar(const char* name, T* defaultValue, const char* description, + ConfigVar(const char* name, T* default_value, const char* description, const char* category, bool is_transient); - std::string GetConfigValue() override; - std::string GetCategory() override; - bool GetIsTransient() override; + std::string config_value() const override; + const std::string& category() const override; + bool is_transient() const override; void AddToLaunchOptions(cxxopts::Options* options) override; void LoadConfigValue(std::shared_ptr result) override; void LoadGameConfigValue(std::shared_ptr result) override; @@ -67,32 +67,31 @@ class ConfigVar : public CommandVar, virtual public IConfigVar { private: std::string category_; bool is_transient_; - std::unique_ptr configValue_ = nullptr; - std::unique_ptr gameConfigValue_ = nullptr; + std::unique_ptr config_value_ = nullptr; + std::unique_ptr game_config_value_ = nullptr; void UpdateValue() override; }; #pragma warning(pop) template -std::string CommandVar::GetName() { +const std::string& CommandVar::name() const { return name_; } template -std::string CommandVar::GetDescription() { +const std::string& CommandVar::description() const { return description_; } template void CommandVar::AddToLaunchOptions(cxxopts::Options* options) { - options->add_options()(this->name_, this->description_, cxxopts::value()); + options->add_options()(name_, description_, cxxopts::value()); } template void ConfigVar::AddToLaunchOptions(cxxopts::Options* options) { - options->add_options(category_)(this->name_, this->description_, - cxxopts::value()); + options->add_options(category_)(name_, description_, cxxopts::value()); } template void CommandVar::LoadFromLaunchOptions(cxxopts::ParseResult* result) { - T value = (*result)[this->name_].template as(); + T value = (*result)[name_].template as(); SetCommandLineValue(value); } template @@ -104,32 +103,32 @@ void ConfigVar::LoadGameConfigValue(std::shared_ptr result) { SetGameConfigValue(*cpptoml::get_impl(result)); } template -CommandVar::CommandVar(const char* name, T* defaultValue, +CommandVar::CommandVar(const char* name, T* default_value, const char* description) : name_(name), - defaultValue_(*defaultValue), + default_value_(*default_value), description_(description), - currentValue_(defaultValue) {} + current_value_(default_value) {} template -ConfigVar::ConfigVar(const char* name, T* defaultValue, +ConfigVar::ConfigVar(const char* name, T* default_value, const char* description, const char* category, bool is_transient) - : CommandVar(name, defaultValue, description), + : CommandVar(name, default_value, description), category_(category), is_transient_(is_transient) {} template void CommandVar::UpdateValue() { - if (this->commandLineValue_) return this->SetValue(*this->commandLineValue_); - return this->SetValue(defaultValue_); + if (commandline_value_) return SetValue(*commandline_value_); + return SetValue(default_value_); } template void ConfigVar::UpdateValue() { - if (this->commandLineValue_) return this->SetValue(*this->commandLineValue_); - if (this->gameConfigValue_) return this->SetValue(*this->gameConfigValue_); - if (this->configValue_) return this->SetValue(*this->configValue_); - return this->SetValue(this->defaultValue_); + if (commandline_value_) return SetValue(*commandline_value_); + if (game_config_value_) return SetValue(*game_config_value_); + if (config_value_) return SetValue(*config_value_); + return SetValue(default_value_); } template T CommandVar::Convert(std::string val) { @@ -156,35 +155,35 @@ std::string CommandVar::ToString(T val) { template void CommandVar::SetValue(T val) { - *currentValue_ = val; + *current_value_ = val; } template -std::string ConfigVar::GetCategory() { +const std::string& ConfigVar::category() const { return category_; } template -bool ConfigVar::GetIsTransient() { +bool ConfigVar::is_transient() const { return is_transient_; } template -std::string ConfigVar::GetConfigValue() { - if (this->configValue_) return this->ToString(*this->configValue_); - return this->ToString(this->defaultValue_); +std::string ConfigVar::config_value() const { + if (config_value_) return ToString(*config_value_); + return ToString(default_value_); } template void CommandVar::SetCommandLineValue(const T val) { - this->commandLineValue_ = std::make_unique(val); - this->UpdateValue(); + commandline_value_ = std::make_unique(val); + UpdateValue(); } template void ConfigVar::SetConfigValue(T val) { - this->configValue_ = std::make_unique(val); - this->UpdateValue(); + config_value_ = std::make_unique(val); + UpdateValue(); } template void ConfigVar::SetGameConfigValue(T val) { - this->gameConfigValue_ = std::make_unique(val); - this->UpdateValue(); + game_config_value_ = std::make_unique(val); + UpdateValue(); } extern std::map* CmdVars; @@ -192,11 +191,11 @@ extern std::map* ConfigVars; inline void AddConfigVar(IConfigVar* cv) { if (!ConfigVars) ConfigVars = new std::map(); - ConfigVars->insert(std::pair(cv->GetName(), cv)); + ConfigVars->insert(std::pair(cv->name(), cv)); } inline void AddCommandVar(ICommandVar* cv) { if (!CmdVars) CmdVars = new std::map(); - CmdVars->insert(std::pair(cv->GetName(), cv)); + CmdVars->insert(std::pair(cv->name(), cv)); } void ParseLaunchArguments(int argc, char** argv); diff --git a/src/xenia/config.cc b/src/xenia/config.cc index e0de33ec7..08b914221 100644 --- a/src/xenia/config.cc +++ b/src/xenia/config.cc @@ -12,9 +12,9 @@ std::wstring config_folder; std::wstring config_path; bool sortCvar(cvar::IConfigVar* a, cvar::IConfigVar* b) { - if (a->GetCategory() < b->GetCategory()) return true; - if (a->GetCategory() > b->GetCategory()) return false; - if (a->GetName() < b->GetName()) return true; + if (a->category() < b->category()) return true; + if (a->category() > b->category()) return false; + if (a->name() < b->name()) return true; return false; } @@ -32,7 +32,7 @@ void ReadConfig(const std::wstring& file_path) { const auto config = ParseConfig(xe::to_string(file_path)); for (auto& it : *cvar::ConfigVars) { auto configVar = static_cast(it.second); - auto configKey = configVar->GetCategory() + "." + configVar->GetName(); + auto configKey = configVar->category() + "." + configVar->name(); if (config->contains_qualified(configKey)) { configVar->LoadConfigValue(config->get_qualified(configKey)); } @@ -44,7 +44,7 @@ void ReadGameConfig(std::wstring file_path) { const auto config = ParseConfig(xe::to_string(file_path)); for (auto& it : *cvar::ConfigVars) { auto configVar = static_cast(it.second); - auto configKey = configVar->GetCategory() + "." + configVar->GetName(); + auto configKey = configVar->category() + "." + configVar->name(); if (config->contains_qualified(configKey)) { configVar->LoadGameConfigValue(config->get_qualified(configKey)); } @@ -61,21 +61,20 @@ void SaveConfig() { std::ostringstream output; std::string lastCategory; for (auto configVar : vars) { - if (configVar->GetIsTransient()) { + if (configVar->is_transient()) { continue; } - if (lastCategory != configVar->GetCategory()) { + if (lastCategory != configVar->category()) { if (!lastCategory.empty()) { output << std::endl; } - lastCategory = configVar->GetCategory(); + lastCategory = configVar->category(); output << xe::format_string("[%s]\n", lastCategory.c_str()); } output << std::left << std::setw(40) << std::setfill(' ') - << xe::format_string("%s = %s", configVar->GetName().c_str(), - configVar->GetConfigValue().c_str()); - output << xe::format_string("\t# %s\n", - configVar->GetDescription().c_str()); + << xe::format_string("%s = %s", configVar->name().c_str(), + configVar->config_value().c_str()); + output << xe::format_string("\t# %s\n", configVar->description().c_str()); } if (xe::filesystem::PathExists(config_path)) {