// Copyright 2016 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. #pragma once #include #include #include #include #include "Common/Config/Enums.h" #include "Common/Config/Layer.h" #include "Common/Config/Section.h" namespace Config { 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 struct ConfigInfo { ConfigLocation location; T default_value; }; using Layers = std::map>; using ConfigChangedCallback = std::function; // Common function used for getting configuration Section* GetOrCreateSection(System system, const std::string& section_name); // Layer management Layers* GetLayers(); void AddLayer(std::unique_ptr layer); void AddLayer(std::unique_ptr loader); Layer* GetLayer(LayerType layer); void RemoveLayer(LayerType layer); bool LayerExists(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); System GetSystemFromName(const std::string& system); const std::string& GetLayerName(LayerType layer); LayerType GetActiveLayerForConfig(const ConfigLocation&); template T Get(LayerType layer, const ConfigInfo& info) { return GetLayer(layer) ->GetOrCreateSection(info.location.system, info.location.section) ->template Get(info.location.key, info.default_value); } template T Get(const ConfigInfo& info) { return Get(LayerType::Meta, info); } template T GetBase(const ConfigInfo& info) { return Get(LayerType::Base, info); } template LayerType GetActiveLayerForConfig(const ConfigInfo& info) { return GetActiveLayerForConfig(info.location); } template void Set(LayerType layer, const ConfigInfo& info, const T& value) { GetLayer(layer) ->GetOrCreateSection(info.location.system, info.location.section) ->Set(info.location.key, value); } template void SetBase(const ConfigInfo& info, const T& value) { Set(LayerType::Base, info, value); } template void SetCurrent(const ConfigInfo& info, const T& value) { Set(LayerType::CurrentRun, info, value); } template void SetBaseOrCurrent(const ConfigInfo& info, const T& value) { if (GetActiveLayerForConfig(info) == LayerType::Base) Set(LayerType::Base, info, value); else Set(LayerType::CurrentRun, info, value); } }