Config: Fix template deduction for implicit conversions

This excludes the second argument from template deduction.

Otherwise, it is required to manually cast the second argument to
the ConfigInfo type (because implicit conversions won't work).

e.g. to set the value for a ConfigInfo<std::string> from a string
literal, you'd need a ugly `std::string("yourstring")`.
This commit is contained in:
Léo Lam 2018-05-11 20:34:39 +02:00
parent f0c5b76186
commit 7dca7c237e
8 changed files with 23 additions and 20 deletions

View File

@ -70,26 +70,26 @@ LayerType GetActiveLayerForConfig(const ConfigInfo<T>& info)
}
template <typename T>
void Set(LayerType layer, const ConfigInfo<T>& info, const T& value)
void Set(LayerType layer, const ConfigInfo<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 T& value)
void SetBase(const ConfigInfo<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 T& value)
void SetCurrent(const ConfigInfo<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 T& value)
void SetBaseOrCurrent(const ConfigInfo<T>& info, const std::common_type_t<T>& value)
{
if (GetActiveLayerForConfig(info) == LayerType::Base)
Set<T>(LayerType::Base, info, value);

View File

@ -116,7 +116,7 @@ public:
}
template <typename T>
void Set(const ConfigInfo<T>& config_info, const T& value)
void Set(const ConfigInfo<T>& config_info, const std::common_type_t<T>& value)
{
Set<T>(config_info.location, value);
}

View File

@ -169,8 +169,11 @@ void LogManager::SaveSettings()
Config::SetBaseOrCurrent(LOGGER_VERBOSITY, static_cast<int>(GetLogLevel()));
for (const auto& container : m_log)
Config::SetBaseOrCurrent({{Config::System::Logger, "Logs", container.m_short_name}, false},
container.m_enable);
{
const Config::ConfigInfo<bool> info{{Config::System::Logger, "Logs", container.m_short_name},
false};
Config::SetBaseOrCurrent(info, container.m_enable);
}
Config::Save();
}

View File

@ -29,7 +29,7 @@ static void LoadFromDTM(Config::Layer* config_layer, Movie::DTMHeader* dtm)
config_layer->Set(Config::MAIN_FAST_DISC_SPEED, dtm->bFastDiscSpeed);
config_layer->Set(Config::MAIN_CPU_CORE, static_cast<int>(dtm->CPUCore));
config_layer->Set(Config::MAIN_SYNC_GPU, dtm->bSyncGPU);
config_layer->Set(Config::MAIN_GFX_BACKEND, std::string(dtm->videoBackend.data()));
config_layer->Set(Config::MAIN_GFX_BACKEND, dtm->videoBackend.data());
config_layer->Set(Config::SYSCONF_PROGRESSIVE_SCAN, dtm->bProgressive);
config_layer->Set(Config::SYSCONF_PAL60, dtm->bPAL60);

View File

@ -348,7 +348,7 @@ void HotkeyScheduler::Run()
{
// Disable post-processing shader, as stereoscopy itself is currently a shader
if (Config::Get(Config::GFX_ENHANCE_POST_SHADER) == DUBOIS_ALGORITHM_SHADER)
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, std::string(""));
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, "");
Config::SetCurrent(Config::GFX_STEREO_MODE, IsHotkey(HK_TOGGLE_STEREO_SBS) ?
static_cast<int>(StereoMode::SBS) :
@ -365,12 +365,12 @@ void HotkeyScheduler::Run()
if (Config::Get(Config::GFX_STEREO_MODE) != static_cast<int>(StereoMode::Anaglyph))
{
Config::SetCurrent(Config::GFX_STEREO_MODE, static_cast<int>(StereoMode::Anaglyph));
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, std::string(DUBOIS_ALGORITHM_SHADER));
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, DUBOIS_ALGORITHM_SHADER);
}
else
{
Config::SetCurrent(Config::GFX_STEREO_MODE, static_cast<int>(StereoMode::Off));
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, std::string(""));
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, "");
}
}
@ -379,7 +379,7 @@ void HotkeyScheduler::Run()
if (Config::Get(Config::GFX_STEREO_MODE) != static_cast<int>(StereoMode::Nvidia3DVision))
{
if (Config::Get(Config::GFX_ENHANCE_POST_SHADER) == DUBOIS_ALGORITHM_SHADER)
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, std::string(""));
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, "");
Config::SetCurrent(Config::GFX_STEREO_MODE, static_cast<int>(StereoMode::Nvidia3DVision));
}

View File

@ -1524,7 +1524,7 @@ void CFrame::ParseHotkeys()
// turned off when selecting other stereoscopy modes.
if (g_Config.sPostProcessingShader == "dubois")
{
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, std::string(""));
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, "");
}
Config::SetCurrent(Config::GFX_STEREO_MODE, static_cast<int>(StereoMode::SBS));
}
@ -1539,7 +1539,7 @@ void CFrame::ParseHotkeys()
{
if (g_Config.sPostProcessingShader == "dubois")
{
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, std::string(""));
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, "");
}
Config::SetCurrent(Config::GFX_STEREO_MODE, static_cast<int>(StereoMode::TAB));
}
@ -1555,12 +1555,12 @@ void CFrame::ParseHotkeys()
// Setting the anaglyph mode also requires a specific
// post-processing shader to be activated.
Config::SetCurrent(Config::GFX_STEREO_MODE, static_cast<int>(StereoMode::Anaglyph));
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, std::string("dubois"));
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, "dubois");
}
else
{
Config::SetCurrent(Config::GFX_STEREO_MODE, static_cast<int>(StereoMode::Off));
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, std::string(""));
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, "");
}
}
if (IsHotkey(HK_TOGGLE_STEREO_3DVISION))
@ -1569,7 +1569,7 @@ void CFrame::ParseHotkeys()
{
if (g_Config.sPostProcessingShader == "dubois")
{
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, std::string(""));
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, "");
}
Config::SetCurrent(Config::GFX_STEREO_MODE, static_cast<int>(StereoMode::Nvidia3DVision));
}

View File

@ -1233,11 +1233,11 @@ void VideoConfigDiag::PopulatePostProcessingShaders()
if (vconfig.stereo_mode == StereoMode::Anaglyph)
{
Config::SetBaseOrCurrent(Config::GFX_ENHANCE_POST_SHADER, std::string("dubois"));
Config::SetBaseOrCurrent(Config::GFX_ENHANCE_POST_SHADER, "dubois");
choice_ppshader->SetStringSelection(StrToWxStr(vconfig.sPostProcessingShader));
}
else
Config::SetBaseOrCurrent(Config::GFX_ENHANCE_POST_SHADER, std::string(""));
Config::SetBaseOrCurrent(Config::GFX_ENHANCE_POST_SHADER, "");
}
// Should the configuration button be loaded by default?

View File

@ -141,7 +141,7 @@ void OpenGLPostProcessing::ApplyShader()
if (!ProgramShaderCache::CompileShader(m_shader, s_vertex_shader, code))
{
ERROR_LOG(VIDEO, "Failed to compile post-processing shader %s", m_config.GetShader().c_str());
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, std::string(""));
Config::SetCurrent(Config::GFX_ENHANCE_POST_SHADER, "");
code = m_config.LoadShader();
ProgramShaderCache::CompileShader(m_shader, s_vertex_shader, code);
}