Config/Layer: Allow all keys of a section to be iterated over

This commit is contained in:
MerryMage 2017-10-30 18:10:05 +00:00
parent 4c24629b95
commit 37419b9a57
2 changed files with 39 additions and 0 deletions

View file

@ -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)

View file

@ -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();