mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Turn Config::Info into a class with getters
This commit is contained in:
@ -52,11 +52,11 @@ T Get(LayerType layer, const Info<T>& info)
|
||||
template <typename T>
|
||||
T Get(const Info<T>& info)
|
||||
{
|
||||
const std::optional<std::string> str = GetAsString(info.location);
|
||||
const std::optional<std::string> str = GetAsString(info.GetLocation());
|
||||
if (!str)
|
||||
return info.default_value;
|
||||
return info.GetDefaultValue();
|
||||
|
||||
return detail::TryParse<T>(*str).value_or(info.default_value);
|
||||
return detail::TryParse<T>(*str).value_or(info.GetDefaultValue());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -68,7 +68,7 @@ T GetBase(const Info<T>& info)
|
||||
template <typename T>
|
||||
LayerType GetActiveLayerForConfig(const Info<T>& info)
|
||||
{
|
||||
return GetActiveLayerForConfig(info.location);
|
||||
return GetActiveLayerForConfig(info.GetLocation());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -30,10 +30,11 @@ struct Location
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Info
|
||||
class Info
|
||||
{
|
||||
Info(const Location& location_, const T& default_value_)
|
||||
: location{location_}, default_value{default_value_}
|
||||
public:
|
||||
constexpr Info(const Location& location, const T& default_value)
|
||||
: m_location{location}, m_default_value{default_value}
|
||||
{
|
||||
}
|
||||
|
||||
@ -41,13 +42,17 @@ struct Info
|
||||
// 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>
|
||||
Info(const Info<Enum>& other)
|
||||
: location{other.location}, default_value{static_cast<detail::UnderlyingType<Enum>>(
|
||||
other.default_value)}
|
||||
constexpr Info(const Info<Enum>& other)
|
||||
: m_location{other.GetLocation()}, m_default_value{static_cast<detail::UnderlyingType<Enum>>(
|
||||
other.GetDefaultValue())}
|
||||
{
|
||||
}
|
||||
|
||||
Location location;
|
||||
T default_value;
|
||||
constexpr const Location& GetLocation() const { return m_location; }
|
||||
constexpr const T& GetDefaultValue() const { return m_default_value; }
|
||||
|
||||
private:
|
||||
Location m_location;
|
||||
T m_default_value;
|
||||
};
|
||||
} // namespace Config
|
||||
|
@ -45,7 +45,7 @@ inline std::optional<std::string> TryParse(const std::string& str_value)
|
||||
} // namespace detail
|
||||
|
||||
template <typename T>
|
||||
struct Info;
|
||||
class Info;
|
||||
|
||||
class Layer;
|
||||
using LayerMap = std::map<Location, std::optional<std::string>>;
|
||||
@ -105,7 +105,7 @@ public:
|
||||
template <typename T>
|
||||
T Get(const Info<T>& config_info) const
|
||||
{
|
||||
return Get<T>(config_info.location).value_or(config_info.default_value);
|
||||
return Get<T>(config_info.GetLocation()).value_or(config_info.GetDefaultValue());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -120,7 +120,7 @@ public:
|
||||
template <typename T>
|
||||
void Set(const Info<T>& config_info, const std::common_type_t<T>& value)
|
||||
{
|
||||
Set(config_info.location, value);
|
||||
Set(config_info.GetLocation(), value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
Reference in New Issue
Block a user