// Copyright 2016 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. #pragma once #include #include #include #include #include #include "Common/Config/ConfigInfo.h" #include "Common/Config/Enums.h" #include "Common/Config/Layer.h" namespace Config { using ConfigChangedCallback = std::function; // Layer management void AddLayer(std::unique_ptr loader); std::shared_ptr GetLayer(LayerType layer); void RemoveLayer(LayerType layer); void AddConfigChangedCallback(ConfigChangedCallback func); void InvokeConfigChangedCallbacks(); // Explicit load and save of layers void Load(); void Save(); void Init(); void Shutdown(); void ClearCurrentRunLayer(); const std::string& GetSystemName(System system); std::optional GetSystemFromName(const std::string& system); const std::string& GetLayerName(LayerType layer); LayerType GetActiveLayerForConfig(const Location&); template T Get(LayerType layer, const Info& info) { if (layer == LayerType::Meta) return Get(info); return GetLayer(layer)->Get(info); } template T Get(const Info& info) { return GetLayer(GetActiveLayerForConfig(info.location))->Get(info); } template T GetBase(const Info& info) { return Get(LayerType::Base, info); } template LayerType GetActiveLayerForConfig(const Info& info) { return GetActiveLayerForConfig(info.location); } template void Set(LayerType layer, const Info& info, const std::common_type_t& value) { GetLayer(layer)->Set(info, value); InvokeConfigChangedCallbacks(); } template void SetBase(const Info& info, const std::common_type_t& value) { Set(LayerType::Base, info, value); } template void SetCurrent(const Info& info, const std::common_type_t& value) { Set(LayerType::CurrentRun, info, value); } template void SetBaseOrCurrent(const Info& info, const std::common_type_t& value) { if (GetActiveLayerForConfig(info) == LayerType::Base) Set(LayerType::Base, info, value); else Set(LayerType::CurrentRun, info, value); } // Used to defer InvokeConfigChangedCallbacks until after the completion of many config changes. class ConfigChangeCallbackGuard { public: ConfigChangeCallbackGuard(); ~ConfigChangeCallbackGuard(); ConfigChangeCallbackGuard(const ConfigChangeCallbackGuard&) = delete; ConfigChangeCallbackGuard& operator=(const ConfigChangeCallbackGuard&) = delete; }; } // namespace Config