Config: Add Get/Set on Layer

For convenience, when getting/setting from ConfigInfos.
This commit is contained in:
Léo Lam 2017-08-03 01:20:52 +08:00
parent e86f5ac04b
commit c900e77ac5
2 changed files with 19 additions and 6 deletions

View File

@ -66,9 +66,7 @@ LayerType GetActiveLayerForConfig(const ConfigLocation&);
template <typename T>
T Get(LayerType layer, const ConfigInfo<T>& info)
{
return GetLayer(layer)
->GetOrCreateSection(info.location.system, info.location.section)
->template Get<T>(info.location.key, info.default_value);
return GetLayer(layer)->Get(info);
}
template <typename T>
@ -92,9 +90,7 @@ LayerType GetActiveLayerForConfig(const ConfigInfo<T>& info)
template <typename T>
void Set(LayerType layer, const ConfigInfo<T>& info, const T& value)
{
GetLayer(layer)
->GetOrCreateSection(info.location.system, info.location.section)
->Set(info.location.key, value);
GetLayer(layer)->Set(info, value);
InvokeConfigChangedCallbacks();
}

View File

@ -14,6 +14,9 @@
namespace Config
{
template <typename T>
struct ConfigInfo;
using LayerMap = std::map<System, std::vector<std::unique_ptr<Section>>>;
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 <typename T>
T Get(const ConfigInfo<T>& config_info)
{
return GetOrCreateSection(config_info.location.system, config_info.location.section)
->template Get<T>(config_info.location.key, config_info.default_value);
}
template <typename T>
void Set(const ConfigInfo<T>& 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();