Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #8787 from leoetlino/config-config
Remove redundant Config prefix from ConfigInfo/ConfigLocation
  • Loading branch information
leoetlino committed May 3, 2020
2 parents 8d4e831 + 19da101 commit 90ba73c
Show file tree
Hide file tree
Showing 34 changed files with 554 additions and 588 deletions.
2 changes: 1 addition & 1 deletion Source/Core/Common/Config/Config.cpp
Expand Up @@ -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);

Expand Down
18 changes: 9 additions & 9 deletions Source/Core/Common/Config/Config.h
Expand Up @@ -37,55 +37,55 @@ 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);
return GetLayer(layer)->Get(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);
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/Common/Config/ConfigInfo.cpp
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions Source/Core/Common/Config/ConfigInfo.h
Expand Up @@ -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
12 changes: 6 additions & 6 deletions Source/Core/Common/Config/Layer.cpp
Expand Up @@ -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;
Expand All @@ -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()
Expand Down
18 changes: 9 additions & 9 deletions Source/Core/Common/Config/Layer.h
Expand Up @@ -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
{
Expand Down Expand Up @@ -98,18 +98,18 @@ class Layer
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())
Expand All @@ -118,18 +118,18 @@ class Layer
}

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)
Expand Down
15 changes: 7 additions & 8 deletions Source/Core/Common/Logging/LogManager.cpp
Expand Up @@ -26,13 +26,13 @@ namespace Common::Log
{
constexpr size_t MAX_MSGLEN = 1024;

const Config::ConfigInfo<bool> LOGGER_WRITE_TO_FILE{
{Config::System::Logger, "Options", "WriteToFile"}, false};
const Config::ConfigInfo<bool> LOGGER_WRITE_TO_CONSOLE{
const Config::Info<bool> LOGGER_WRITE_TO_FILE{{Config::System::Logger, "Options", "WriteToFile"},
false};
const Config::Info<bool> LOGGER_WRITE_TO_CONSOLE{
{Config::System::Logger, "Options", "WriteToConsole"}, true};
const Config::ConfigInfo<bool> LOGGER_WRITE_TO_WINDOW{
const Config::Info<bool> LOGGER_WRITE_TO_WINDOW{
{Config::System::Logger, "Options", "WriteToWindow"}, true};
const Config::ConfigInfo<int> LOGGER_VERBOSITY{{Config::System::Logger, "Options", "Verbosity"}, 0};
const Config::Info<int> LOGGER_VERBOSITY{{Config::System::Logger, "Options", "Verbosity"}, 0};

class FileLogListener : public LogListener
{
Expand Down Expand Up @@ -163,7 +163,7 @@ LogManager::LogManager()

for (LogContainer& container : m_log)
container.m_enable = Config::Get(
Config::ConfigInfo<bool>{{Config::System::Logger, "Logs", container.m_short_name}, false});
Config::Info<bool>{{Config::System::Logger, "Logs", container.m_short_name}, false});

m_path_cutoff_point = DeterminePathCutOffPoint();
}
Expand All @@ -188,8 +188,7 @@ void LogManager::SaveSettings()

for (const auto& container : m_log)
{
const Config::ConfigInfo<bool> info{{Config::System::Logger, "Logs", container.m_short_name},
false};
const Config::Info<bool> info{{Config::System::Logger, "Logs", container.m_short_name}, false};
Config::SetBaseOrCurrent(info, container.m_enable);
}

Expand Down

0 comments on commit 90ba73c

Please sign in to comment.