mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Merge Core/Config/Config.h into Common/Config/Config.h
Allows code in Common to take advantage of the layered config logic.
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
|
||||
#include "Common/Assert.h"
|
||||
#include "Common/Config/Config.h"
|
||||
@ -144,4 +145,34 @@ const std::string& GetLayerName(LayerType layer)
|
||||
};
|
||||
return layer_to_name.at(layer);
|
||||
}
|
||||
|
||||
bool ConfigLocation::operator==(const ConfigLocation& other) const
|
||||
{
|
||||
return std::tie(system, section, key) == std::tie(other.system, other.section, other.key);
|
||||
}
|
||||
|
||||
bool ConfigLocation::operator!=(const ConfigLocation& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
bool ConfigLocation::operator<(const ConfigLocation& other) const
|
||||
{
|
||||
return std::tie(system, section, key) < std::tie(other.system, other.section, other.key);
|
||||
}
|
||||
|
||||
LayerType GetActiveLayerForConfig(const ConfigLocation& config)
|
||||
{
|
||||
for (auto layer : SEARCH_ORDER)
|
||||
{
|
||||
if (!LayerExists(layer))
|
||||
continue;
|
||||
|
||||
if (GetLayer(layer)->Exists(config.system, config.section, config.key))
|
||||
return layer;
|
||||
}
|
||||
|
||||
// If config is not present in any layer, base layer is considered active.
|
||||
return LayerType::Base;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,24 @@
|
||||
|
||||
namespace Config
|
||||
{
|
||||
struct ConfigLocation
|
||||
{
|
||||
System system;
|
||||
std::string section;
|
||||
std::string key;
|
||||
|
||||
bool operator==(const ConfigLocation& other) const;
|
||||
bool operator!=(const ConfigLocation& other) const;
|
||||
bool operator<(const ConfigLocation& other) const;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct ConfigInfo
|
||||
{
|
||||
ConfigLocation location;
|
||||
T default_value;
|
||||
};
|
||||
|
||||
using Layers = std::map<LayerType, std::unique_ptr<Layer>>;
|
||||
using ConfigChangedCallback = std::function<void()>;
|
||||
|
||||
@ -45,4 +63,60 @@ void ClearCurrentRunLayer();
|
||||
const std::string& GetSystemName(System system);
|
||||
System GetSystemFromName(const std::string& system);
|
||||
const std::string& GetLayerName(LayerType layer);
|
||||
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);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T Get(const ConfigInfo<T>& info)
|
||||
{
|
||||
return Get(LayerType::Meta, info);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T GetBase(const ConfigInfo<T>& info)
|
||||
{
|
||||
return Get(LayerType::Base, info);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
LayerType GetActiveLayerForConfig(const ConfigInfo<T>& info)
|
||||
{
|
||||
return GetActiveLayerForConfig(info.location);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SetBase(const ConfigInfo<T>& info, const T& value)
|
||||
{
|
||||
Set<T>(LayerType::Base, info, value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SetCurrent(const ConfigInfo<T>& info, const T& value)
|
||||
{
|
||||
Set<T>(LayerType::CurrentRun, info, value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SetBaseOrCurrent(const ConfigInfo<T>& info, const T& value)
|
||||
{
|
||||
if (GetActiveLayerForConfig(info) == LayerType::Base)
|
||||
Set<T>(LayerType::Base, info, value);
|
||||
else
|
||||
Set<T>(LayerType::CurrentRun, info, value);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user