From 37419b9a579fbcb1633caa9295a39da405e93904 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Mon, 30 Oct 2017 18:10:05 +0000 Subject: [PATCH] Config/Layer: Allow all keys of a section to be iterated over --- Source/Core/Common/Config/Layer.cpp | 12 ++++++++++++ Source/Core/Common/Config/Layer.h | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) 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) diff --git a/Source/Core/Common/Config/Layer.h b/Source/Core/Common/Config/Layer.h index eb2a6bafca..8e56ae308a 100644 --- a/Source/Core/Common/Config/Layer.h +++ b/Source/Core/Common/Config/Layer.h @@ -62,6 +62,30 @@ private: const LayerType m_layer; }; +class Section +{ +public: + using iterator = LayerMap::iterator; + Section(iterator begin_, iterator end_) : m_begin(begin_), m_end(end_) {} + iterator begin() const { return m_begin; } + iterator end() const { return m_end; } +private: + iterator m_begin; + iterator m_end; +}; + +class ConstSection +{ +public: + using iterator = LayerMap::const_iterator; + ConstSection(iterator begin_, iterator end_) : m_begin(begin_), m_end(end_) {} + iterator begin() const { return m_begin; } + iterator end() const { return m_end; } +private: + iterator m_begin; + iterator m_end; +}; + class Layer { public: @@ -106,6 +130,9 @@ public: current_value = new_value; } + Section GetSection(System system, const std::string& section); + ConstSection GetSection(System system, const std::string& section) const; + // Explicit load and save of layers void Load(); void Save();