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>
|
template <typename T>
|
||||||
T Get(LayerType layer, const ConfigInfo<T>& info)
|
T Get(LayerType layer, const ConfigInfo<T>& info)
|
||||||
{
|
{
|
||||||
return GetLayer(layer)
|
return GetLayer(layer)->Get(info);
|
||||||
->GetOrCreateSection(info.location.system, info.location.section)
|
|
||||||
->template Get<T>(info.location.key, info.default_value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -92,9 +90,7 @@ LayerType GetActiveLayerForConfig(const ConfigInfo<T>& info)
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Set(LayerType layer, const ConfigInfo<T>& info, const T& value)
|
void Set(LayerType layer, const ConfigInfo<T>& info, const T& value)
|
||||||
{
|
{
|
||||||
GetLayer(layer)
|
GetLayer(layer)->Set(info, value);
|
||||||
->GetOrCreateSection(info.location.system, info.location.section)
|
|
||||||
->Set(info.location.key, value);
|
|
||||||
InvokeConfigChangedCallbacks();
|
InvokeConfigChangedCallbacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,9 @@
|
||||||
|
|
||||||
namespace Config
|
namespace Config
|
||||||
{
|
{
|
||||||
|
template <typename T>
|
||||||
|
struct ConfigInfo;
|
||||||
|
|
||||||
using LayerMap = std::map<System, std::vector<std::unique_ptr<Section>>>;
|
using LayerMap = std::map<System, std::vector<std::unique_ptr<Section>>>;
|
||||||
|
|
||||||
class ConfigLayerLoader
|
class ConfigLayerLoader
|
||||||
|
@ -52,6 +55,20 @@ public:
|
||||||
virtual Section* GetSection(System system, const std::string& section_name);
|
virtual Section* GetSection(System system, const std::string& section_name);
|
||||||
virtual Section* GetOrCreateSection(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
|
// Explicit load and save of layers
|
||||||
void Load();
|
void Load();
|
||||||
void Save();
|
void Save();
|
||||||
|
|
Loading…
Reference in New Issue