SettingsInterface: Create type aliases for string lists

pull/3794/head
Stenzek 3 weeks ago
parent 5100c51644
commit 3bc1e8cdf2
No known key found for this signature in database

@ -66,9 +66,9 @@ void LayeredSettingsInterface::RemoveEmptySections()
Panic("Attempt to call RemoveEmptySections() on layered settings interface");
}
std::vector<std::string> LayeredSettingsInterface::GetStringList(const char* section, const char* key) const
LayeredSettingsInterface::StringList LayeredSettingsInterface::GetStringList(const char* section, const char* key) const
{
std::vector<std::string> ret;
StringList ret;
for (u32 layer = FIRST_LAYER; layer <= LAST_LAYER; layer++)
{
@ -83,8 +83,7 @@ std::vector<std::string> LayeredSettingsInterface::GetStringList(const char* sec
return ret;
}
void LayeredSettingsInterface::SetStringList(const char* section, const char* key,
const std::vector<std::string>& items)
void LayeredSettingsInterface::SetStringList(const char* section, const char* key, const StringList& items)
{
Panic("Attempt to call SetStringList() on layered settings interface");
}
@ -99,16 +98,16 @@ bool LayeredSettingsInterface::AddToStringList(const char* section, const char*
Panic("Attempt to call AddToStringList() on layered settings interface");
}
std::vector<std::pair<std::string, std::string>> LayeredSettingsInterface::GetKeyValueList(const char* section) const
LayeredSettingsInterface::KeyValueList LayeredSettingsInterface::GetKeyValueList(const char* section) const
{
std::unordered_set<std::string_view> seen;
std::vector<std::pair<std::string, std::string>> ret;
KeyValueList ret;
for (u32 layer = FIRST_LAYER; layer <= LAST_LAYER; layer++)
{
if (SettingsInterface* sif = m_layers[layer])
{
const size_t newly_added_begin = ret.size();
std::vector<std::pair<std::string, std::string>> entries = sif->GetKeyValueList(section);
KeyValueList entries = sif->GetKeyValueList(section);
for (std::pair<std::string, std::string>& entry : entries)
{
if (seen.find(entry.first) != seen.end())

@ -32,13 +32,13 @@ public:
void RemoveSection(const char* section) override;
void RemoveEmptySections() override;
std::vector<std::string> GetStringList(const char* section, const char* key) const override;
StringList GetStringList(const char* section, const char* key) const override;
void SetStringList(const char* section, const char* key, const std::vector<std::string>& items) override;
bool RemoveFromStringList(const char* section, const char* key, const char* item) override;
bool AddToStringList(const char* section, const char* key, const char* item) override;
std::vector<std::pair<std::string, std::string>> GetKeyValueList(const char* section) const override;
void SetKeyValueList(const char* section, const std::vector<std::pair<std::string, std::string>>& items) override;
KeyValueList GetKeyValueList(const char* section) const override;
void SetKeyValueList(const char* section, const KeyValueList& items) override;
private:
static constexpr Layer FIRST_LAYER = LAYER_GAME;

@ -16,6 +16,9 @@ class Error;
class SettingsInterface
{
public:
using KeyValueList = std::vector<std::pair<std::string, std::string>>;
using StringList = std::vector<std::string>;
virtual ~SettingsInterface();
virtual bool IsEmpty() = 0;
@ -23,13 +26,13 @@ public:
virtual bool LookupValue(const char* section, const char* key, std::string_view* value) const = 0;
virtual void StoreValue(const char* section, const char* key, std::string_view value) = 0;
virtual std::vector<std::string> GetStringList(const char* section, const char* key) const = 0;
virtual void SetStringList(const char* section, const char* key, const std::vector<std::string>& items) = 0;
virtual StringList GetStringList(const char* section, const char* key) const = 0;
virtual void SetStringList(const char* section, const char* key, const StringList& items) = 0;
virtual bool RemoveFromStringList(const char* section, const char* key, const char* item) = 0;
virtual bool AddToStringList(const char* section, const char* key, const char* item) = 0;
virtual std::vector<std::pair<std::string, std::string>> GetKeyValueList(const char* section) const = 0;
virtual void SetKeyValueList(const char* section, const std::vector<std::pair<std::string, std::string>>& items) = 0;
virtual KeyValueList GetKeyValueList(const char* section) const = 0;
virtual void SetKeyValueList(const char* section, const KeyValueList& items) = 0;
virtual bool ContainsValue(const char* section, const char* key) const = 0;
virtual void DeleteValue(const char* section, const char* key) = 0;

@ -87,8 +87,8 @@ INISettingsInterface::Section& INISettingsInterface::GetOrCreateSection(std::str
return *m_sections.insert(it, std::move(sec));
}
INISettingsInterface::KeyValueList::const_iterator INISettingsInterface::FindKey(const Section& section,
std::string_view key) const
INISettingsInterface::SectionKeyValueList::const_iterator INISettingsInterface::FindKey(const Section& section,
std::string_view key) const
{
auto it = std::lower_bound(
section.entries.begin(), section.entries.end(), key,
@ -98,7 +98,8 @@ INISettingsInterface::KeyValueList::const_iterator INISettingsInterface::FindKey
return section.entries.end();
}
INISettingsInterface::KeyValueList::iterator INISettingsInterface::FindKey(Section& section, std::string_view key)
INISettingsInterface::SectionKeyValueList::iterator INISettingsInterface::FindKey(Section& section,
std::string_view key)
{
auto it = std::lower_bound(
section.entries.begin(), section.entries.end(), key,
@ -108,15 +109,16 @@ INISettingsInterface::KeyValueList::iterator INISettingsInterface::FindKey(Secti
return section.entries.end();
}
INISettingsInterface::KeyValueList::const_iterator INISettingsInterface::FindKeyEnd(const Section& section,
std::string_view key) const
INISettingsInterface::SectionKeyValueList::const_iterator INISettingsInterface::FindKeyEnd(const Section& section,
std::string_view key) const
{
return std::upper_bound(
section.entries.begin(), section.entries.end(), key,
[this](const std::string_view& k, const KeyValuePair& kv) { return (k < GetPoolStringView(kv.key)); });
}
INISettingsInterface::KeyValueList::iterator INISettingsInterface::FindKeyEnd(Section& section, std::string_view key)
INISettingsInterface::SectionKeyValueList::iterator INISettingsInterface::FindKeyEnd(Section& section,
std::string_view key)
{
return std::upper_bound(
section.entries.begin(), section.entries.end(), key,
@ -574,7 +576,7 @@ void INISettingsInterface::RemoveEmptySections()
}
}
std::vector<std::string> INISettingsInterface::GetStringList(const char* section, const char* key) const
INISettingsInterface::StringList INISettingsInterface::GetStringList(const char* section, const char* key) const
{
auto sit = FindSection(std::string_view(section));
if (sit == m_sections.end())
@ -586,14 +588,14 @@ std::vector<std::string> INISettingsInterface::GetStringList(const char* section
return {};
auto end_it = FindKeyEnd(*sit, key_sv);
std::vector<std::string> result;
StringList result;
result.reserve(static_cast<size_t>(end_it - begin_it));
for (auto it = begin_it; it != end_it; ++it)
result.emplace_back(GetPoolStringView(it->value));
return result;
}
void INISettingsInterface::SetStringList(const char* section, const char* key, const std::vector<std::string>& items)
void INISettingsInterface::SetStringList(const char* section, const char* key, const StringList& items)
{
const std::string_view section_sv(section);
const std::string_view key_sv(key);
@ -667,7 +669,7 @@ bool INISettingsInterface::AddToStringList(const char* section, const char* key,
return true;
}
std::vector<std::pair<std::string, std::string>> INISettingsInterface::GetKeyValueList(const char* section) const
INISettingsInterface::KeyValueList INISettingsInterface::GetKeyValueList(const char* section) const
{
auto sit = FindSection(section);
if (sit == m_sections.end())
@ -680,8 +682,7 @@ std::vector<std::pair<std::string, std::string>> INISettingsInterface::GetKeyVal
return result;
}
void INISettingsInterface::SetKeyValueList(const char* section,
const std::vector<std::pair<std::string, std::string>>& items)
void INISettingsInterface::SetKeyValueList(const char* section, const KeyValueList& items)
{
Section& sec = GetOrCreateSection(section);
sec.entries.clear();

@ -24,12 +24,12 @@ public:
PoolString key;
PoolString value;
};
using KeyValueList = std::vector<KeyValuePair>;
using SectionKeyValueList = std::vector<KeyValuePair>;
struct Section
{
PoolString name;
KeyValueList entries;
SectionKeyValueList entries;
};
using SectionList = std::vector<Section>;
@ -65,13 +65,13 @@ public:
void RemoveSection(const char* section) override;
void RemoveEmptySections() override;
std::vector<std::string> GetStringList(const char* section, const char* key) const override;
StringList GetStringList(const char* section, const char* key) const override;
void SetStringList(const char* section, const char* key, const std::vector<std::string>& items) override;
bool RemoveFromStringList(const char* section, const char* key, const char* item) override;
bool AddToStringList(const char* section, const char* key, const char* item) override;
std::vector<std::pair<std::string, std::string>> GetKeyValueList(const char* section) const override;
void SetKeyValueList(const char* section, const std::vector<std::pair<std::string, std::string>>& items) override;
KeyValueList GetKeyValueList(const char* section) const override;
void SetKeyValueList(const char* section, const KeyValueList& items) override;
private:
std::string_view GetPoolStringView(const PoolString& ps) const;
@ -81,10 +81,10 @@ private:
SectionList::iterator FindSection(std::string_view name);
Section& GetOrCreateSection(std::string_view name);
KeyValueList::const_iterator FindKey(const Section& section, std::string_view key) const;
KeyValueList::iterator FindKey(Section& section, std::string_view key);
KeyValueList::const_iterator FindKeyEnd(const Section& section, std::string_view key) const;
KeyValueList::iterator FindKeyEnd(Section& section, std::string_view key);
SectionKeyValueList::const_iterator FindKey(const Section& section, std::string_view key) const;
SectionKeyValueList::iterator FindKey(Section& section, std::string_view key);
SectionKeyValueList::const_iterator FindKeyEnd(const Section& section, std::string_view key) const;
SectionKeyValueList::iterator FindKeyEnd(Section& section, std::string_view key);
void InsertKeyValue(Section& section, std::string_view key, std::string_view value);

Loading…
Cancel
Save