diff options
| author | Léo Lam <leo@leolam.fr> | 2020-05-03 14:07:41 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-03 14:07:41 +0200 |
| commit | 90ba73c6c2cdc6d92bff75f4e66d48b044ebdfac (patch) | |
| tree | 65e612f4bb02ee0d7cea8f5856afd0a52fd66626 /Source/Core/Common | |
| parent | 8d4e8314a3dcd8680ae81d91fb7e076b4496b43b (diff) | |
| parent | 19da1011648beb324122f36e6da4cd14cc4c7217 (diff) | |
Merge pull request #8787 from leoetlino/config-config
Remove redundant Config prefix from ConfigInfo/ConfigLocation
Diffstat (limited to 'Source/Core/Common')
| -rw-r--r-- | Source/Core/Common/Config/Config.cpp | 2 | ||||
| -rw-r--r-- | Source/Core/Common/Config/Config.h | 18 | ||||
| -rw-r--r-- | Source/Core/Common/Config/ConfigInfo.cpp | 6 | ||||
| -rw-r--r-- | Source/Core/Common/Config/ConfigInfo.h | 18 | ||||
| -rw-r--r-- | Source/Core/Common/Config/Layer.cpp | 12 | ||||
| -rw-r--r-- | Source/Core/Common/Config/Layer.h | 18 | ||||
| -rw-r--r-- | Source/Core/Common/Logging/LogManager.cpp | 15 |
7 files changed, 44 insertions, 45 deletions
diff --git a/Source/Core/Common/Config/Config.cpp b/Source/Core/Common/Config/Config.cpp index 2587dc5aac..2211d0d5fb 100644 --- a/Source/Core/Common/Config/Config.cpp +++ b/Source/Core/Common/Config/Config.cpp @@ -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); diff --git a/Source/Core/Common/Config/Config.h b/Source/Core/Common/Config/Config.h index 2d69e0809e..fa315857bf 100644 --- a/Source/Core/Common/Config/Config.h +++ b/Source/Core/Common/Config/Config.h @@ -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); diff --git a/Source/Core/Common/Config/ConfigInfo.cpp b/Source/Core/Common/Config/ConfigInfo.cpp index 1d4084c3c6..76c5933e27 100644 --- a/Source/Core/Common/Config/ConfigInfo.cpp +++ b/Source/Core/Common/Config/ConfigInfo.cpp @@ -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; diff --git a/Source/Core/Common/Config/ConfigInfo.h b/Source/Core/Common/Config/ConfigInfo.h index ecea74a04b..20051c1003 100644 --- a/Source/Core/Common/Config/ConfigInfo.h +++ b/Source/Core/Common/Config/ConfigInfo.h @@ -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 diff --git a/Source/Core/Common/Config/Layer.cpp b/Source/Core/Common/Config/Layer.cpp index 573c79c04e..311e99ded2 100644 --- a/Source/Core/Common/Config/Layer.cpp +++ b/Source/Core/Common/Config/Layer.cpp @@ -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() diff --git a/Source/Core/Common/Config/Layer.h b/Source/Core/Common/Config/Layer.h index 87c6b91f90..c309810719 100644 --- a/Source/Core/Common/Config/Layer.h +++ b/Source/Core/Common/Config/Layer.h @@ -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) diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp index 729e5cb3a8..a847b2402f 100644 --- a/Source/Core/Common/Logging/LogManager.cpp +++ b/Source/Core/Common/Logging/LogManager.cpp @@ -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 { @@ -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(); } @@ -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); } |
