Config: Add Get/Set on Layer
For convenience, when getting/setting from ConfigInfos.
This commit is contained in:
parent
e86f5ac04b
commit
c900e77ac5
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue