mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-02 07:21:07 +00:00
Add lookup index to editor settings category
Prevent adding duplicate settings there.
This commit is contained in:
parent
7c63522870
commit
88a6ecabae
@ -24,6 +24,9 @@ CSMPrefs::State* CSMPrefs::Category::getState() const
|
|||||||
|
|
||||||
void CSMPrefs::Category::addSetting(Setting* setting)
|
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);
|
mSettings.push_back(setting);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,11 +42,12 @@ CSMPrefs::Category::Iterator CSMPrefs::Category::end()
|
|||||||
|
|
||||||
CSMPrefs::Setting& CSMPrefs::Category::operator[](const std::string& key)
|
CSMPrefs::Setting& CSMPrefs::Category::operator[](const std::string& key)
|
||||||
{
|
{
|
||||||
for (Iterator iter = mSettings.begin(); iter != mSettings.end(); ++iter)
|
const auto it = mIndex.find(key);
|
||||||
if ((*iter)->getKey() == key)
|
|
||||||
return **iter;
|
|
||||||
|
|
||||||
throw std::logic_error("Invalid user setting: " + key);
|
if (it != mIndex.end())
|
||||||
|
return *it->second;
|
||||||
|
|
||||||
|
throw std::logic_error("Invalid user setting in " + mKey + " category: " + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMPrefs::Category::update()
|
void CSMPrefs::Category::update()
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace CSMPrefs
|
namespace CSMPrefs
|
||||||
@ -20,6 +21,7 @@ namespace CSMPrefs
|
|||||||
State* mParent;
|
State* mParent;
|
||||||
std::string mKey;
|
std::string mKey;
|
||||||
Container mSettings;
|
Container mSettings;
|
||||||
|
std::unordered_map<std::string, Setting*> mIndex;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Category(State* parent, const std::string& key);
|
Category(State* parent, const std::string& key);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user