From c900e77ac556c348b0c1c4f114a0cd5e4fc54844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Thu, 3 Aug 2017 01:20:52 +0800 Subject: [PATCH] Config: Add Get/Set on Layer For convenience, when getting/setting from ConfigInfos. --- Source/Core/Common/Config/Config.h | 8 ++------ Source/Core/Common/Config/Layer.h | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Source/Core/Common/Config/Config.h b/Source/Core/Common/Config/Config.h index 95dc2b6c64..905960ed4a 100644 --- a/Source/Core/Common/Config/Config.h +++ b/Source/Core/Common/Config/Config.h @@ -66,9 +66,7 @@ LayerType GetActiveLayerForConfig(const ConfigLocation&); template T Get(LayerType layer, const ConfigInfo& info) { - return GetLayer(layer) - ->GetOrCreateSection(info.location.system, info.location.section) - ->template Get(info.location.key, info.default_value); + return GetLayer(layer)->Get(info); } template @@ -92,9 +90,7 @@ LayerType GetActiveLayerForConfig(const ConfigInfo& info) template void Set(LayerType layer, const ConfigInfo& info, const T& value) { - GetLayer(layer) - ->GetOrCreateSection(info.location.system, info.location.section) - ->Set(info.location.key, value); + GetLayer(layer)->Set(info, value); InvokeConfigChangedCallbacks(); } diff --git a/Source/Core/Common/Config/Layer.h b/Source/Core/Common/Config/Layer.h index 2606990ec6..14eb4e6c65 100644 --- a/Source/Core/Common/Config/Layer.h +++ b/Source/Core/Common/Config/Layer.h @@ -14,6 +14,9 @@ namespace Config { +template +struct ConfigInfo; + using LayerMap = std::map>>; class ConfigLayerLoader @@ -52,6 +55,20 @@ public: virtual Section* GetSection(System system, const std::string& section_name); virtual Section* GetOrCreateSection(System system, const std::string& section_name); + template + T Get(const ConfigInfo& config_info) + { + return GetOrCreateSection(config_info.location.system, config_info.location.section) + ->template Get(config_info.location.key, config_info.default_value); + } + + template + void Set(const ConfigInfo& config_info, const T& value) + { + GetOrCreateSection(config_info.location.system, config_info.location.section) + ->Set(config_info.location.key, value); + } + // Explicit load and save of layers void Load(); void Save();