From c8f970e2b04709280ef144ff135dac15945d21b2 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 29 Oct 2017 19:17:58 +0000 Subject: Config: Remove recursive layer --- Source/Core/Common/Config/Layer.cpp | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) (limited to 'Source/Core/Common/Config/Layer.cpp') diff --git a/Source/Core/Common/Config/Layer.cpp b/Source/Core/Common/Config/Layer.cpp index b613c4366b..a3912281f5 100644 --- a/Source/Core/Common/Config/Layer.cpp +++ b/Source/Core/Common/Config/Layer.cpp @@ -67,15 +67,7 @@ Section* Layer::GetOrCreateSection(System system, const std::string& section_nam Section* section = GetSection(system, section_name); if (!section) { - 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)); - } + m_sections[system].emplace_back(std::make_unique
(m_layer, system, section_name)); section = m_sections[system].back().get(); } return section; @@ -124,26 +116,4 @@ void Layer::ClearDirty() [](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; -} } -- cgit v1.2.3 From 4c24629b9551cab8af653a2bbcbe6d1639b3edb2 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 29 Oct 2017 19:11:15 +0000 Subject: Config: Flatten structures Originally, Layer contained a std::map of Sections, which containted a std::map containing the (key, value) pairs. Here we flattern this structure so that only one std::map is required, reducing the number of indirections required and vastly simplifying the code. --- Source/Core/Common/Config/Layer.cpp | 99 ++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 45 deletions(-) (limited to 'Source/Core/Common/Config/Layer.cpp') diff --git a/Source/Core/Common/Config/Layer.cpp b/Source/Core/Common/Config/Layer.cpp index a3912281f5..d4f9e7c633 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,56 +75,44 @@ Layer::~Layer() Save(); } -bool Layer::Exists(System system, const std::string& section_name, const std::string& key) -{ - Section* section = GetSection(system, section_name); - if (!section) - return false; - return section->Exists(key); -} - -bool Layer::DeleteKey(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->Delete(key); + const auto iter = m_map.find(location); + return iter != m_map.end() && iter->second.has_value(); } -Section* Layer::GetSection(System system, const std::string& section_name) +bool Layer::DeleteKey(const ConfigLocation& location) { - for (auto& section : m_sections[system]) - if (!strcasecmp(section->m_name.c_str(), section_name.c_str())) - return section.get(); - return nullptr; + m_is_dirty = true; + bool had_value = m_map[location].has_value(); + m_map[location].reset(); + return had_value; } -Section* Layer::GetOrCreateSection(System system, const std::string& section_name) +void Layer::DeleteAllKeys() { - Section* section = GetSection(system, section_name); - if (!section) + m_is_dirty = true; + for (auto& pair : m_map) { - m_sections[system].emplace_back(std::make_unique
(m_layer, system, section_name)); - section = m_sections[system].back().get(); + pair.second.reset(); } - return section; } 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(); } @@ -98,22 +123,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(); }); - }); + return m_map; } } -- cgit v1.2.3 From 37419b9a579fbcb1633caa9295a39da405e93904 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Mon, 30 Oct 2017 18:10:05 +0000 Subject: Config/Layer: Allow all keys of a section to be iterated over --- Source/Core/Common/Config/Layer.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Source/Core/Common/Config/Layer.cpp') diff --git a/Source/Core/Common/Config/Layer.cpp b/Source/Core/Common/Config/Layer.cpp index d4f9e7c633..5a5c4b5f59 100644 --- a/Source/Core/Common/Config/Layer.cpp +++ b/Source/Core/Common/Config/Layer.cpp @@ -98,6 +98,18 @@ void Layer::DeleteAllKeys() } } +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) -- cgit v1.2.3