Skip to content
Permalink
Browse files
Merge pull request #6154 from MerryMage/config-cleanup
Cleanup implementation of onion configuration
  • Loading branch information
leoetlino committed Nov 17, 2017
2 parents 1e33fd0 + 37419b9 commit 84ca9a4
Show file tree
Hide file tree
Showing 22 changed files with 360 additions and 723 deletions.
@@ -4,8 +4,8 @@ set(SRCS
ColorUtil.cpp
CommonFuncs.cpp
Config/Config.cpp
Config/ConfigInfo.cpp
Config/Layer.cpp
Config/Section.cpp
Crypto/AES.cpp
Crypto/bn.cpp
Crypto/ec.cpp
@@ -29,8 +29,8 @@ set(SRCS
PcapFile.cpp
PerformanceCounter.cpp
Profiler.cpp
SettingsHandler.cpp
SDCardUtil.cpp
SettingsHandler.cpp
StringUtil.cpp
SymbolDB.cpp
SysConf.cpp
@@ -55,9 +55,9 @@
<ClInclude Include="CommonPaths.h" />
<ClInclude Include="CommonTypes.h" />
<ClInclude Include="Config\Config.h" />
<ClInclude Include="Config\ConfigInfo.h" />
<ClInclude Include="Config\Enums.h" />
<ClInclude Include="Config\Layer.h" />
<ClInclude Include="Config\Section.h" />
<ClInclude Include="CPUDetect.h" />
<ClInclude Include="DebugInterface.h" />
<ClInclude Include="ENetUtil.h" />
@@ -170,8 +170,8 @@
<ClCompile Include="CommonFuncs.cpp" />
<ClCompile Include="CompatPatches.cpp" />
<ClCompile Include="Config\Config.cpp" />
<ClCompile Include="Config\ConfigInfo.cpp" />
<ClCompile Include="Config\Layer.cpp" />
<ClCompile Include="Config\Section.cpp" />
<ClCompile Include="ENetUtil.cpp" />
<ClCompile Include="File.cpp" />
<ClCompile Include="FileSearch.cpp" />
@@ -17,11 +17,6 @@ static std::list<ConfigChangedCallback> s_callbacks;

void InvokeConfigChangedCallbacks();

Section* GetOrCreateSection(System system, const std::string& section_name)
{
return s_layers[LayerType::Meta]->GetOrCreateSection(system, section_name);
}

Layers* GetLayers()
{
return &s_layers;
@@ -83,8 +78,6 @@ void Init()
{
// These layers contain temporary values
ClearCurrentRunLayer();
// This layer always has to exist
s_layers[LayerType::Meta] = std::make_unique<RecursiveLayer>();
}

void Shutdown()
@@ -129,34 +122,18 @@ const std::string& GetLayerName(LayerType layer)
{LayerType::Movie, "Movie"},
{LayerType::CommandLine, "Command Line"},
{LayerType::CurrentRun, "Current Run"},
{LayerType::Meta, "Top"},
};
return layer_to_name.at(layer);
}

bool ConfigLocation::operator==(const ConfigLocation& other) const
{
return std::tie(system, section, key) == std::tie(other.system, other.section, other.key);
}

bool ConfigLocation::operator!=(const ConfigLocation& other) const
{
return !(*this == other);
}

bool ConfigLocation::operator<(const ConfigLocation& other) const
{
return std::tie(system, section, key) < std::tie(other.system, other.section, other.key);
}

LayerType GetActiveLayerForConfig(const ConfigLocation& config)
{
for (auto layer : SEARCH_ORDER)
{
if (!LayerExists(layer))
continue;

if (GetLayer(layer)->Exists(config.system, config.section, config.key))
if (GetLayer(layer)->Exists(config))
return layer;
}

@@ -9,36 +9,15 @@
#include <memory>
#include <string>

#include "Common/Config/ConfigInfo.h"
#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 <typename T>
struct ConfigInfo
{
ConfigLocation location;
T default_value;
};

using Layers = std::map<LayerType, std::unique_ptr<Layer>>;
using ConfigChangedCallback = std::function<void()>;

// 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> layer);
@@ -66,13 +45,15 @@ LayerType GetActiveLayerForConfig(const ConfigLocation&);
template <typename T>
T Get(LayerType layer, const ConfigInfo<T>& info)
{
if (layer == LayerType::Meta)
return Get(info);
return GetLayer(layer)->Get(info);
}

template <typename T>
T Get(const ConfigInfo<T>& info)
{
return Get(LayerType::Meta, info);
return GetLayer(GetActiveLayerForConfig(info.location))->Get(info);
}

template <typename T>
@@ -0,0 +1,35 @@
// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <cstring>

#include "Common/CommonFuncs.h"
#include "Common/Config/ConfigInfo.h"

namespace Config
{
bool ConfigLocation::operator==(const ConfigLocation& other) const
{
return system == other.system && strcasecmp(section.c_str(), other.section.c_str()) == 0 &&
strcasecmp(key.c_str(), other.key.c_str()) == 0;
}

bool ConfigLocation::operator!=(const ConfigLocation& other) const
{
return !(*this == other);
}

bool ConfigLocation::operator<(const ConfigLocation& other) const
{
if (system != other.system)
return system < other.system;

const int section_compare = strcasecmp(section.c_str(), other.section.c_str());
if (section_compare != 0)
return section_compare < 0;

const int key_compare = strcasecmp(key.c_str(), other.key.c_str());
return key_compare < 0;
}
}
@@ -0,0 +1,30 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <string>

#include "Common/Config/Enums.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 <typename T>
struct ConfigInfo
{
ConfigLocation location;
T default_value;
};
}
@@ -34,7 +34,6 @@ enum class System
};

constexpr std::array<LayerType, 7> SEARCH_ORDER{{
// Skip the meta layer
LayerType::CurrentRun, LayerType::CommandLine, LayerType::Movie, LayerType::Netplay,
LayerType::LocalGame, LayerType::GlobalGame, LayerType::Base,
}};

0 comments on commit 84ca9a4

Please sign in to comment.