From 7dca7c237eb9ae40765e581317df6df4b4fc1ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Fri, 11 May 2018 20:34:39 +0200 Subject: [PATCH] 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 from a string literal, you'd need a ugly `std::string("yourstring")`. --- Source/Core/Common/Config/Config.h | 8 ++++---- Source/Core/Common/Config/Layer.h | 2 +- Source/Core/Common/Logging/LogManager.cpp | 7 +++++-- Source/Core/Core/ConfigLoaders/MovieConfigLoader.cpp | 2 +- Source/Core/DolphinQt2/HotkeyScheduler.cpp | 8 ++++---- Source/Core/DolphinWX/Frame.cpp | 10 +++++----- Source/Core/DolphinWX/VideoConfigDiag.cpp | 4 ++-- Source/Core/VideoBackends/OGL/PostProcessing.cpp | 2 +- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Source/Core/Common/Config/Config.h b/Source/Core/Common/Config/Config.h index 14a2dcb20c..1418a86606 100644 --- a/Source/Core/Common/Config/Config.h +++ b/Source/Core/Common/Config/Config.h @@ -70,26 +70,26 @@ LayerType GetActiveLayerForConfig(const ConfigInfo& info) } template -void Set(LayerType layer, const ConfigInfo& info, const T& value) +void Set(LayerType layer, const ConfigInfo& info, const std::common_type_t& value) { GetLayer(layer)->Set(info, value); InvokeConfigChangedCallbacks(); } template -void SetBase(const ConfigInfo& info, const T& value) +void SetBase(const ConfigInfo& info, const std::common_type_t& value) { Set(LayerType::Base, info, value); } template -void SetCurrent(const ConfigInfo& info, const T& value) +void SetCurrent(const ConfigInfo& info, const std::common_type_t& value) { Set(LayerType::CurrentRun, info, value); } template -void SetBaseOrCurrent(const ConfigInfo& info, const T& value) +void SetBaseOrCurrent(const ConfigInfo& info, const std::common_type_t& value) { if (GetActiveLayerForConfig(info) == LayerType::Base) Set(LayerType::Base, info, value); diff --git a/Source/Core/Common/Config/Layer.h b/Source/Core/Common/Config/Layer.h index c8373c5bce..e2af6a24ae 100644 --- a/Source/Core/Common/Config/Layer.h +++ b/Source/Core/Common/Config/Layer.h @@ -116,7 +116,7 @@ public: } template - void Set(const ConfigInfo& config_info, const T& value) + void Set(const ConfigInfo& config_info, const std::common_type_t& value) { Set(config_info.location, value); } diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp index cd66d23944..b9a56f8df5 100644 --- a/Source/Core/Common/Logging/LogManager.cpp +++ b/Source/Core/Common/Logging/LogManager.cpp @@ -169,8 +169,11 @@ void LogManager::SaveSettings() Config::SetBaseOrCurrent(LOGGER_VERBOSITY, static_cast(GetLogLevel())); for (const auto& container : m_log) - Config::SetBaseOrCurrent({{Config::System::Logger, "Logs", container.m_short_name}, false}, - container.m_enable); + { + const Config::ConfigInfo info{{Config::System::Logger, "Logs", container.m_short_name}, + false}; + Config::SetBaseOrCurrent(info, container.m_enable); + } Config::Save(); } diff --git a/Source/Core/Core/ConfigLoaders/MovieConfigLoader.cpp b/Source/Core/Core/ConfigLoaders/MovieConfigLoader.cpp index c0975fa57e..86ce99b8da 100644 --- a/Source/Core/Core/ConfigLoaders/MovieConfigLoader.cpp +++ b/Source/Core/Core/ConfigLoaders/MovieConfigLoader.cpp @@ -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(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); diff --git a/Source/Core/DolphinQt2/HotkeyScheduler.cpp b/Source/Core/DolphinQt2/HotkeyScheduler.cpp index e94e1489e1..690a896012 100644 --- a/Source/Core/DolphinQt2/HotkeyScheduler.cpp +++ b/Source/Core/DolphinQt2/HotkeyScheduler.cpp @@ -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(StereoMode::SBS) : @@ -365,12 +365,12 @@ void HotkeyScheduler::Run() if (Config::Get(Config::GFX_STEREO_MODE) != static_cast(StereoMode::Anaglyph)) { Config::SetCurrent(Config::GFX_STEREO_MODE, static_cast(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(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(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(StereoMode::Nvidia3DVision)); } diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index 57b9aadb3a..212c32430d 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -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(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(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(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(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(StereoMode::Nvidia3DVision)); } diff --git a/Source/Core/DolphinWX/VideoConfigDiag.cpp b/Source/Core/DolphinWX/VideoConfigDiag.cpp index 8947ab0aa8..c29ce83e1b 100644 --- a/Source/Core/DolphinWX/VideoConfigDiag.cpp +++ b/Source/Core/DolphinWX/VideoConfigDiag.cpp @@ -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? diff --git a/Source/Core/VideoBackends/OGL/PostProcessing.cpp b/Source/Core/VideoBackends/OGL/PostProcessing.cpp index 57cdd158c4..9de1a85326 100644 --- a/Source/Core/VideoBackends/OGL/PostProcessing.cpp +++ b/Source/Core/VideoBackends/OGL/PostProcessing.cpp @@ -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); }