mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 07:39:41 +00:00
Add lookup index to editor settings category
Prevent adding duplicate settings there.
This commit is contained in:
parent
7c63522870
commit
88a6ecabae
2 changed files with 10 additions and 4 deletions
|
@ -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);
|
||||
|
||||
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()
|
||||
|
|
|
@ -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…
Reference in a new issue