diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt
index 91eca8f2ae..f4e0a4ff84 100644
--- a/Source/Core/Common/CMakeLists.txt
+++ b/Source/Core/Common/CMakeLists.txt
@@ -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
diff --git a/Source/Core/Common/Common.vcxproj b/Source/Core/Common/Common.vcxproj
index 853cff6d0f..7d8ba3b2b0 100644
--- a/Source/Core/Common/Common.vcxproj
+++ b/Source/Core/Common/Common.vcxproj
@@ -55,9 +55,9 @@
+
-
@@ -170,8 +170,8 @@
+
-
diff --git a/Source/Core/Common/Config/Config.cpp b/Source/Core/Common/Config/Config.cpp
index 339155dbe3..a3504f80d2 100644
--- a/Source/Core/Common/Config/Config.cpp
+++ b/Source/Core/Common/Config/Config.cpp
@@ -17,11 +17,6 @@ static std::list 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();
}
void Shutdown()
@@ -129,26 +122,10 @@ 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)
@@ -156,7 +133,7 @@ LayerType GetActiveLayerForConfig(const ConfigLocation& config)
if (!LayerExists(layer))
continue;
- if (GetLayer(layer)->Exists(config.system, config.section, config.key))
+ if (GetLayer(layer)->Exists(config))
return layer;
}
diff --git a/Source/Core/Common/Config/Config.h b/Source/Core/Common/Config/Config.h
index 905960ed4a..3536f5677c 100644
--- a/Source/Core/Common/Config/Config.h
+++ b/Source/Core/Common/Config/Config.h
@@ -9,36 +9,15 @@
#include
#include
+#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
-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);
@@ -66,13 +45,15 @@ LayerType GetActiveLayerForConfig(const ConfigLocation&);
template
T Get(LayerType layer, const ConfigInfo& info)
{
+ if (layer == LayerType::Meta)
+ return Get(info);
return GetLayer(layer)->Get(info);
}
template
T Get(const ConfigInfo& info)
{
- return Get(LayerType::Meta, info);
+ return GetLayer(GetActiveLayerForConfig(info.location))->Get(info);
}
template
diff --git a/Source/Core/Common/Config/ConfigInfo.cpp b/Source/Core/Common/Config/ConfigInfo.cpp
new file mode 100644
index 0000000000..47d2e25c84
--- /dev/null
+++ b/Source/Core/Common/Config/ConfigInfo.cpp
@@ -0,0 +1,35 @@
+// Copyright 2016 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#include
+
+#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;
+}
+}
diff --git a/Source/Core/Common/Config/ConfigInfo.h b/Source/Core/Common/Config/ConfigInfo.h
new file mode 100644
index 0000000000..fc36ecee03
--- /dev/null
+++ b/Source/Core/Common/Config/ConfigInfo.h
@@ -0,0 +1,30 @@
+// Copyright 2017 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include
+
+#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
+struct ConfigInfo
+{
+ ConfigLocation location;
+ T default_value;
+};
+}
diff --git a/Source/Core/Common/Config/Enums.h b/Source/Core/Common/Config/Enums.h
index 9ffd9688c2..a5b62f812d 100644
--- a/Source/Core/Common/Config/Enums.h
+++ b/Source/Core/Common/Config/Enums.h
@@ -34,7 +34,6 @@ enum class System
};
constexpr std::array SEARCH_ORDER{{
- // Skip the meta layer
LayerType::CurrentRun, LayerType::CommandLine, LayerType::Movie, LayerType::Netplay,
LayerType::LocalGame, LayerType::GlobalGame, LayerType::Base,
}};
diff --git a/Source/Core/Common/Config/Layer.cpp b/Source/Core/Common/Config/Layer.cpp
index b613c4366b..5a5c4b5f59 100644
--- a/Source/Core/Common/Config/Layer.cpp
+++ b/Source/Core/Common/Config/Layer.cpp
@@ -8,10 +8,47 @@
#include "Common/Config/Config.h"
#include "Common/Config/Layer.h"
-#include "Common/Config/Section.h"
namespace Config
{
+namespace detail
+{
+std::string ValueToString(u16 value)
+{
+ return StringFromFormat("0x%04x", value);
+}
+
+std::string ValueToString(u32 value)
+{
+ return StringFromFormat("0x%08x", value);
+}
+
+std::string ValueToString(float value)
+{
+ return StringFromFormat("%#.9g", value);
+}
+
+std::string ValueToString(double value)
+{
+ return StringFromFormat("%#.17g", value);
+}
+
+std::string ValueToString(int value)
+{
+ return std::to_string(value);
+}
+
+std::string ValueToString(bool value)
+{
+ return StringFromBool(value);
+}
+
+std::string ValueToString(const std::string& value)
+{
+ return value;
+}
+}
+
ConfigLayerLoader::ConfigLayerLoader(LayerType layer) : m_layer(layer)
{
}
@@ -38,64 +75,56 @@ Layer::~Layer()
Save();
}
-bool Layer::Exists(System system, const std::string& section_name, const std::string& key)
+bool Layer::Exists(const ConfigLocation& location) const
{
- Section* section = GetSection(system, section_name);
- if (!section)
- return false;
- return section->Exists(key);
+ const auto iter = m_map.find(location);
+ return iter != m_map.end() && iter->second.has_value();
}
-bool Layer::DeleteKey(System system, const std::string& section_name, const std::string& key)
+bool Layer::DeleteKey(const ConfigLocation& location)
{
- Section* section = GetSection(system, section_name);
- if (!section)
- return false;
- return section->Delete(key);
+ m_is_dirty = true;
+ bool had_value = m_map[location].has_value();
+ m_map[location].reset();
+ return had_value;
}
-Section* Layer::GetSection(System system, const std::string& section_name)
+void Layer::DeleteAllKeys()
{
- for (auto& section : m_sections[system])
- if (!strcasecmp(section->m_name.c_str(), section_name.c_str()))
- return section.get();
- return nullptr;
-}
-
-Section* Layer::GetOrCreateSection(System system, const std::string& section_name)
-{
- Section* section = GetSection(system, section_name);
- if (!section)
+ m_is_dirty = true;
+ for (auto& pair : m_map)
{
- if (m_layer == LayerType::Meta)
- {
- m_sections[system].emplace_back(
- std::make_unique(m_layer, system, section_name));
- }
- else
- {
- m_sections[system].emplace_back(std::make_unique(m_layer, system, section_name));
- }
- section = m_sections[system].back().get();
+ pair.second.reset();
}
- return section;
+}
+
+Section Layer::GetSection(System system, const std::string& section)
+{
+ return Section{m_map.lower_bound(ConfigLocation{system, section, ""}),
+ m_map.lower_bound(ConfigLocation{system, section + '\001', ""})};
+}
+
+ConstSection Layer::GetSection(System system, const std::string& section) const
+{
+ return ConstSection{m_map.lower_bound(ConfigLocation{system, section, ""}),
+ m_map.lower_bound(ConfigLocation{system, section + '\001', ""})};
}
void Layer::Load()
{
if (m_loader)
m_loader->Load(this);
- ClearDirty();
+ m_is_dirty = false;
InvokeConfigChangedCallbacks();
}
void Layer::Save()
{
- if (!m_loader || !IsDirty())
+ if (!m_loader || !m_is_dirty)
return;
m_loader->Save(this);
- ClearDirty();
+ m_is_dirty = false;
InvokeConfigChangedCallbacks();
}
@@ -106,44 +135,6 @@ LayerType Layer::GetLayer() const
const LayerMap& Layer::GetLayerMap() const
{
- return m_sections;
-}
-
-bool Layer::IsDirty() const
-{
- return std::any_of(m_sections.begin(), m_sections.end(), [](const auto& system) {
- return std::any_of(system.second.begin(), system.second.end(),
- [](const auto& section) { return section->IsDirty(); });
- });
-}
-
-void Layer::ClearDirty()
-{
- std::for_each(m_sections.begin(), m_sections.end(), [](auto& system) {
- std::for_each(system.second.begin(), system.second.end(),
- [](auto& section) { section->ClearDirty(); });
- });
-}
-
-RecursiveLayer::RecursiveLayer() : Layer(LayerType::Meta)
-{
-}
-
-Section* RecursiveLayer::GetSection(System system, const std::string& section_name)
-{
- // Always queries backwards recursively, so it doesn't matter if it exists or not on this layer
- return GetOrCreateSection(system, section_name);
-}
-
-Section* RecursiveLayer::GetOrCreateSection(System system, const std::string& section_name)
-{
- Section* section = Layer::GetSection(system, section_name);
- if (!section)
- {
- m_sections[system].emplace_back(
- std::make_unique(m_layer, system, section_name));
- section = m_sections[system].back().get();
- }
- return section;
+ return m_map;
}
}
diff --git a/Source/Core/Common/Config/Layer.h b/Source/Core/Common/Config/Layer.h
index edbb706081..8e56ae308a 100644
--- a/Source/Core/Common/Config/Layer.h
+++ b/Source/Core/Common/Config/Layer.h
@@ -6,18 +6,47 @@
#include