Remove redundant Config prefix from ConfigInfo/ConfigLocation

Both structs are already in the Config namespace.
This commit is contained in:
Léo Lam
2020-05-02 14:39:40 +02:00
parent 66c91b9dfb
commit 19da101164
34 changed files with 543 additions and 577 deletions

View File

@ -159,7 +159,7 @@ const std::string& GetLayerName(LayerType layer)
return layer_to_name.at(layer);
}
LayerType GetActiveLayerForConfig(const ConfigLocation& config)
LayerType GetActiveLayerForConfig(const Location& config)
{
ReadLock lock(s_layers_rw_lock);

View File

@ -37,10 +37,10 @@ void ClearCurrentRunLayer();
const std::string& GetSystemName(System system);
std::optional<System> GetSystemFromName(const std::string& system);
const std::string& GetLayerName(LayerType layer);
LayerType GetActiveLayerForConfig(const ConfigLocation&);
LayerType GetActiveLayerForConfig(const Location&);
template <typename T>
T Get(LayerType layer, const ConfigInfo<T>& info)
T Get(LayerType layer, const Info<T>& info)
{
if (layer == LayerType::Meta)
return Get(info);
@ -48,44 +48,44 @@ T Get(LayerType layer, const ConfigInfo<T>& info)
}
template <typename T>
T Get(const ConfigInfo<T>& info)
T Get(const Info<T>& info)
{
return GetLayer(GetActiveLayerForConfig(info.location))->Get(info);
}
template <typename T>
T GetBase(const ConfigInfo<T>& info)
T GetBase(const Info<T>& info)
{
return Get(LayerType::Base, info);
}
template <typename T>
LayerType GetActiveLayerForConfig(const ConfigInfo<T>& info)
LayerType GetActiveLayerForConfig(const Info<T>& info)
{
return GetActiveLayerForConfig(info.location);
}
template <typename T>
void Set(LayerType layer, const ConfigInfo<T>& info, const std::common_type_t<T>& value)
void Set(LayerType layer, const Info<T>& info, const std::common_type_t<T>& value)
{
GetLayer(layer)->Set(info, value);
InvokeConfigChangedCallbacks();
}
template <typename T>
void SetBase(const ConfigInfo<T>& info, const std::common_type_t<T>& value)
void SetBase(const Info<T>& info, const std::common_type_t<T>& value)
{
Set<T>(LayerType::Base, info, value);
}
template <typename T>
void SetCurrent(const ConfigInfo<T>& info, const std::common_type_t<T>& value)
void SetCurrent(const Info<T>& info, const std::common_type_t<T>& value)
{
Set<T>(LayerType::CurrentRun, info, value);
}
template <typename T>
void SetBaseOrCurrent(const ConfigInfo<T>& info, const std::common_type_t<T>& value)
void SetBaseOrCurrent(const Info<T>& info, const std::common_type_t<T>& value)
{
if (GetActiveLayerForConfig(info) == LayerType::Base)
Set<T>(LayerType::Base, info, value);

View File

@ -9,18 +9,18 @@
namespace Config
{
bool ConfigLocation::operator==(const ConfigLocation& other) const
bool Location::operator==(const Location& other) const
{
return system == other.system && strcasecmp(section.c_str(), other.section.c_str()) == 0 &&
strcasecmp(key.c_str(), other.key.c_str()) == 0;
}
bool ConfigLocation::operator!=(const ConfigLocation& other) const
bool Location::operator!=(const Location& other) const
{
return !(*this == other);
}
bool ConfigLocation::operator<(const ConfigLocation& other) const
bool Location::operator<(const Location& other) const
{
if (system != other.system)
return system < other.system;

View File

@ -18,36 +18,36 @@ template <typename T>
using UnderlyingType = typename std::enable_if_t<std::is_enum<T>{}, std::underlying_type<T>>::type;
} // namespace detail
struct ConfigLocation
struct Location
{
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;
bool operator==(const Location& other) const;
bool operator!=(const Location& other) const;
bool operator<(const Location& other) const;
};
template <typename T>
struct ConfigInfo
struct Info
{
ConfigInfo(const ConfigLocation& location_, const T& default_value_)
Info(const Location& location_, const T& default_value_)
: location{location_}, default_value{default_value_}
{
}
// Make it easy to convert ConfigInfo<Enum> into ConfigInfo<UnderlyingType<Enum>>
// Make it easy to convert Info<Enum> into Info<UnderlyingType<Enum>>
// so that enum settings can still easily work with code that doesn't care about the enum values.
template <typename Enum,
std::enable_if_t<std::is_same<T, detail::UnderlyingType<Enum>>::value>* = nullptr>
ConfigInfo(const ConfigInfo<Enum>& other)
Info(const Info<Enum>& other)
: location{other.location}, default_value{static_cast<detail::UnderlyingType<Enum>>(
other.default_value)}
{
}
ConfigLocation location;
Location location;
T default_value;
};
} // namespace Config

View File

@ -37,13 +37,13 @@ Layer::~Layer()
Save();
}
bool Layer::Exists(const ConfigLocation& location) const
bool Layer::Exists(const Location& location) const
{
const auto iter = m_map.find(location);
return iter != m_map.end() && iter->second.has_value();
}
bool Layer::DeleteKey(const ConfigLocation& location)
bool Layer::DeleteKey(const Location& location)
{
m_is_dirty = true;
bool had_value = false;
@ -68,14 +68,14 @@ void Layer::DeleteAllKeys()
Section Layer::GetSection(System system, const std::string& section)
{
return Section{m_map.lower_bound(ConfigLocation{system, section, ""}),
m_map.lower_bound(ConfigLocation{system, section + '\001', ""})};
return Section{m_map.lower_bound(Location{system, section, ""}),
m_map.lower_bound(Location{system, section + '\001', ""})};
}
ConstSection Layer::GetSection(System system, const std::string& section) const
{
return ConstSection{m_map.lower_bound(ConfigLocation{system, section, ""}),
m_map.lower_bound(ConfigLocation{system, section + '\001', ""})};
return ConstSection{m_map.lower_bound(Location{system, section, ""}),
m_map.lower_bound(Location{system, section + '\001', ""})};
}
void Layer::Load()

View File

@ -45,10 +45,10 @@ inline std::optional<std::string> TryParse(const std::string& str_value)
} // namespace detail
template <typename T>
struct ConfigInfo;
struct Info;
class Layer;
using LayerMap = std::map<ConfigLocation, std::optional<std::string>>;
using LayerMap = std::map<Location, std::optional<std::string>>;
class ConfigLayerLoader
{
@ -98,18 +98,18 @@ public:
virtual ~Layer();
// Convenience functions
bool Exists(const ConfigLocation& location) const;
bool DeleteKey(const ConfigLocation& location);
bool Exists(const Location& location) const;
bool DeleteKey(const Location& location);
void DeleteAllKeys();
template <typename T>
T Get(const ConfigInfo<T>& config_info) const
T Get(const Info<T>& config_info) const
{
return Get<T>(config_info.location).value_or(config_info.default_value);
}
template <typename T>
std::optional<T> Get(const ConfigLocation& location) const
std::optional<T> Get(const Location& location) const
{
const auto iter = m_map.find(location);
if (iter == m_map.end() || !iter->second.has_value())
@ -118,18 +118,18 @@ public:
}
template <typename T>
void Set(const ConfigInfo<T>& config_info, const std::common_type_t<T>& value)
void Set(const Info<T>& config_info, const std::common_type_t<T>& value)
{
Set(config_info.location, value);
}
template <typename T>
void Set(const ConfigLocation& location, const T& value)
void Set(const Location& location, const T& value)
{
Set(location, ValueToString(value));
}
void Set(const ConfigLocation& location, std::string new_value)
void Set(const Location& location, std::string new_value)
{
const auto iter = m_map.find(location);
if (iter != m_map.end() && iter->second == new_value)