1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00
OpenMW/apps/opencs/model/prefs/category.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.3 KiB
C++
Raw Normal View History

2015-12-06 12:06:28 +01:00
#include "category.hpp"
2015-12-11 11:50:06 +01:00
#include <stdexcept>
#include "setting.hpp"
2015-12-12 11:58:53 +01:00
#include "state.hpp"
2023-11-12 00:52:09 +01:00
#include "subcategory.hpp"
2015-12-11 11:50:06 +01:00
2015-12-08 09:56:42 +01:00
CSMPrefs::Category::Category(State* parent, const std::string& key)
: mParent(parent)
, mKey(key)
2015-12-06 12:06:28 +01:00
{
}
const std::string& CSMPrefs::Category::getKey() const
{
return mKey;
}
2015-12-08 17:21:58 +01:00
CSMPrefs::State* CSMPrefs::Category::getState() const
{
return mParent;
}
void CSMPrefs::Category::addSetting(Setting* setting)
{
if (!mIndex.emplace(setting->getKey(), setting).second)
throw std::logic_error("Category " + mKey + " already has setting: " + setting->getKey());
2015-12-08 17:21:58 +01:00
mSettings.push_back(setting);
}
2023-11-12 00:52:09 +01:00
void CSMPrefs::Category::addSubcategory(Subcategory* setting)
{
mSettings.push_back(setting);
}
2015-12-08 17:21:58 +01:00
CSMPrefs::Category::Iterator CSMPrefs::Category::begin()
{
return mSettings.begin();
}
CSMPrefs::Category::Iterator CSMPrefs::Category::end()
{
return mSettings.end();
}
2015-12-11 11:50:06 +01:00
CSMPrefs::Setting& CSMPrefs::Category::operator[](const std::string& key)
{
const auto it = mIndex.find(key);
if (it != mIndex.end())
return *it->second;
2015-12-11 11:50:06 +01:00
throw std::logic_error("Invalid user setting in " + mKey + " category: " + key);
2015-12-11 11:50:06 +01:00
}
2015-12-12 11:58:53 +01:00
void CSMPrefs::Category::update()
{
for (Iterator iter = mSettings.begin(); iter != mSettings.end(); ++iter)
mParent->update(**iter);
}