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 ConfigChangedCallback = std::function<void()>;
|
|
|
|
|
|
|
|
// Layer management
|
|
|
|
void AddLayer(std::unique_ptr<ConfigLayerLoader> loader);
|
2019-07-30 14:40:52 +00:00
|
|
|
std::shared_ptr<Layer> GetLayer(LayerType layer);
|
2017-02-16 15:58:40 +00:00
|
|
|
void RemoveLayer(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);
|
2020-05-02 12:39:40 +00:00
|
|
|
LayerType GetActiveLayerForConfig(const Location&);
|
2017-07-09 23:17:36 +00:00
|
|
|
|
2020-11-25 15:26:13 +00:00
|
|
|
std::optional<std::string> GetAsString(const Location&);
|
|
|
|
|
2017-07-09 23:17:36 +00:00
|
|
|
template <typename T>
|
2020-05-02 12:39:40 +00:00
|
|
|
T Get(LayerType layer, const Info<T>& info)
|
2017-07-09 23:17:36 +00:00
|
|
|
{
|
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>
|
2020-05-02 12:39:40 +00:00
|
|
|
T Get(const Info<T>& info)
|
2017-07-09 23:17:36 +00:00
|
|
|
{
|
2020-11-25 15:26:13 +00:00
|
|
|
const std::optional<std::string> str = GetAsString(info.location);
|
|
|
|
if (!str)
|
|
|
|
return info.default_value;
|
|
|
|
|
|
|
|
return detail::TryParse<T>(*str).value_or(info.default_value);
|
2017-07-09 23:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2020-05-02 12:39:40 +00:00
|
|
|
T GetBase(const Info<T>& info)
|
2017-07-09 23:17:36 +00:00
|
|
|
{
|
|
|
|
return Get(LayerType::Base, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2020-05-02 12:39:40 +00:00
|
|
|
LayerType GetActiveLayerForConfig(const Info<T>& info)
|
2017-07-09 23:17:36 +00:00
|
|
|
{
|
|
|
|
return GetActiveLayerForConfig(info.location);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2020-05-02 12:39:40 +00:00
|
|
|
void Set(LayerType layer, const Info<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>
|
2020-05-02 12:39:40 +00:00
|
|
|
void SetBase(const Info<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>
|
2020-05-02 12:39:40 +00:00
|
|
|
void SetCurrent(const Info<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>
|
2020-05-02 12:39:40 +00:00
|
|
|
void SetBaseOrCurrent(const Info<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);
|
|
|
|
}
|
2019-03-03 16:58:37 +00:00
|
|
|
|
|
|
|
// 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
|