diff --git a/Source/Core/Common/Config.h b/Source/Core/Common/Config.h index f08de4ec8b..cc880df5e2 100644 --- a/Source/Core/Common/Config.h +++ b/Source/Core/Common/Config.h @@ -91,6 +91,14 @@ public: bool Get(const std::string& key, float* value, float defaultValue = 0.0f) const; bool Get(const std::string& key, double* value, double defaultValue = 0.0) const; + template + T Get(const std::string& key, const T& default_value) const + { + T value; + Get(key, value, default_value); + return value; + } + // Section chunk void SetLines(const std::vector& lines); // XXX: Add to recursive layer @@ -187,6 +195,22 @@ void AddConfigChangedCallback(ConfigChangedCallback func); void Load(); void Save(); +// Often used functions for getting or setting configuration on the base layer for the main system +template +T Get(const std::string& section_name, const std::string& key, const T& default_value) +{ + auto base_layer = GetLayer(Config::LayerType::Base); + return base_layer->GetOrCreateSection(Config::System::Main, section_name) + ->Get(key, default_value); +} + +template +void Set(const std::string& section_name, const std::string& key, const T& value) +{ + auto base_layer = GetLayer(Config::LayerType::Base); + base_layer->GetOrCreateSection(Config::System::Main, section_name)->Set(key, value); +} + void Init(); void Shutdown();