2017-02-16 15:58:40 +00:00
|
|
|
// Copyright 2016 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
2017-11-26 17:24:01 +00:00
|
|
|
#include <optional>
|
2017-02-16 15:58:40 +00:00
|
|
|
#include <string>
|
|
|
|
|
2017-10-30 16:22:37 +00:00
|
|
|
#include "Common/Config/ConfigInfo.h"
|
2017-02-16 15:58:40 +00:00
|
|
|
#include "Common/Config/Enums.h"
|
|
|
|
#include "Common/Config/Layer.h"
|
|
|
|
|
|
|
|
namespace Config
|
|
|
|
{
|
|
|
|
using Layers = std::map<LayerType, std::unique_ptr<Layer>>;
|
|
|
|
using ConfigChangedCallback = std::function<void()>;
|
|
|
|
|
|
|
|
// Layer management
|
|
|
|
Layers* GetLayers();
|
|
|
|
void AddLayer(std::unique_ptr<Layer> layer);
|
|
|
|
void AddLayer(std::unique_ptr<ConfigLayerLoader> 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();
|
2017-05-13 22:34:49 +00:00
|
|
|
void ClearCurrentRunLayer();
|
2017-02-16 15:58:40 +00:00
|
|
|
|
|
|
|
const std::string& GetSystemName(System system);
|
2017-11-26 17:24:01 +00:00
|
|
|
std::optional<System> GetSystemFromName(const std::string& system);
|
2017-02-16 15:58:40 +00:00
|
|
|
const std::string& GetLayerName(LayerType layer);
|
2017-07-09 23:17:36 +00:00
|
|
|
LayerType GetActiveLayerForConfig(const ConfigLocation&);
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T Get(LayerType layer, const ConfigInfo<T>& info)
|
|
|
|
{
|
2017-10-29 19:17:58 +00:00
|
|
|
if (layer == LayerType::Meta)
|
|
|
|
return Get(info);
|
2017-08-02 17:20:52 +00:00
|
|
|
return GetLayer(layer)->Get(info);
|
2017-07-09 23:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T Get(const ConfigInfo<T>& info)
|
|
|
|
{
|
2017-10-29 19:17:58 +00:00
|
|
|
return GetLayer(GetActiveLayerForConfig(info.location))->Get(info);
|
2017-07-09 23:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T GetBase(const ConfigInfo<T>& info)
|
|
|
|
{
|
|
|
|
return Get(LayerType::Base, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
LayerType GetActiveLayerForConfig(const ConfigInfo<T>& info)
|
|
|
|
{
|
|
|
|
return GetActiveLayerForConfig(info.location);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2018-05-11 18:34:39 +00:00
|
|
|
void Set(LayerType layer, const ConfigInfo<T>& info, const std::common_type_t<T>& value)
|
2017-07-09 23:17:36 +00:00
|
|
|
{
|
2017-08-02 17:20:52 +00:00
|
|
|
GetLayer(layer)->Set(info, value);
|
2017-08-01 17:07:53 +00:00
|
|
|
InvokeConfigChangedCallbacks();
|
2017-07-09 23:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2018-05-11 18:34:39 +00:00
|
|
|
void SetBase(const ConfigInfo<T>& info, const std::common_type_t<T>& value)
|
2017-07-09 23:17:36 +00:00
|
|
|
{
|
|
|
|
Set<T>(LayerType::Base, info, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2018-05-11 18:34:39 +00:00
|
|
|
void SetCurrent(const ConfigInfo<T>& info, const std::common_type_t<T>& value)
|
2017-07-09 23:17:36 +00:00
|
|
|
{
|
|
|
|
Set<T>(LayerType::CurrentRun, info, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2018-05-11 18:34:39 +00:00
|
|
|
void SetBaseOrCurrent(const ConfigInfo<T>& info, const std::common_type_t<T>& value)
|
2017-07-09 23:17:36 +00:00
|
|
|
{
|
|
|
|
if (GetActiveLayerForConfig(info) == LayerType::Base)
|
|
|
|
Set<T>(LayerType::Base, info, value);
|
|
|
|
else
|
|
|
|
Set<T>(LayerType::CurrentRun, info, value);
|
|
|
|
}
|
2017-02-16 15:58:40 +00:00
|
|
|
}
|