2017-10-30 16:22:37 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2018-05-11 20:38:44 +00:00
|
|
|
#include <type_traits>
|
2017-10-30 16:22:37 +00:00
|
|
|
|
|
|
|
#include "Common/Config/Enums.h"
|
|
|
|
|
|
|
|
namespace Config
|
|
|
|
{
|
2018-05-11 20:38:44 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
// std::underlying_type may only be used with enum types, so make sure T is an enum type first.
|
|
|
|
template <typename T>
|
|
|
|
using UnderlyingType = typename std::enable_if_t<std::is_enum<T>{}, std::underlying_type<T>>::type;
|
|
|
|
} // namespace detail
|
|
|
|
|
2017-10-30 16:22:37 +00:00
|
|
|
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
|
|
|
|
{
|
2018-05-11 20:38:44 +00:00
|
|
|
ConfigInfo(const ConfigLocation& location_, const T& default_value_)
|
|
|
|
: location{location_}, default_value{default_value_}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make it easy to convert ConfigInfo<Enum> into ConfigInfo<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)
|
|
|
|
: location{other.location}, default_value{static_cast<detail::UnderlyingType<Enum>>(
|
|
|
|
other.default_value)}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-10-30 16:22:37 +00:00
|
|
|
ConfigLocation location;
|
|
|
|
T default_value;
|
|
|
|
};
|
2019-05-05 23:48:12 +00:00
|
|
|
} // namespace Config
|