Add lookup index to editor settings category

Prevent adding duplicate settings there.
macos_ci_fix
elsid 1 year ago
parent 7c63522870
commit 88a6ecabae
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -24,6 +24,9 @@ CSMPrefs::State* CSMPrefs::Category::getState() const
void CSMPrefs::Category::addSetting(Setting* setting)
{
if (!mIndex.emplace(setting->getKey(), setting).second)
throw std::logic_error("Category " + mKey + " already has setting: " + setting->getKey());
mSettings.push_back(setting);
}
@ -39,11 +42,12 @@ CSMPrefs::Category::Iterator CSMPrefs::Category::end()
CSMPrefs::Setting& CSMPrefs::Category::operator[](const std::string& key)
{
for (Iterator iter = mSettings.begin(); iter != mSettings.end(); ++iter)
if ((*iter)->getKey() == key)
return **iter;
const auto it = mIndex.find(key);
if (it != mIndex.end())
return *it->second;
throw std::logic_error("Invalid user setting: " + key);
throw std::logic_error("Invalid user setting in " + mKey + " category: " + key);
}
void CSMPrefs::Category::update()

@ -3,6 +3,7 @@
#include <algorithm>
#include <string>
#include <unordered_map>
#include <vector>
namespace CSMPrefs
@ -20,6 +21,7 @@ namespace CSMPrefs
State* mParent;
std::string mKey;
Container mSettings;
std::unordered_map<std::string, Setting*> mIndex;
public:
Category(State* parent, const std::string& key);

Loading…
Cancel
Save