1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-24 00:23:53 +00:00
openmw/apps/opencs/view/doc/subviewfactory.cpp

34 lines
1.1 KiB
C++
Raw Normal View History

2012-12-11 12:22:43 +00:00
#include "subviewfactory.hpp"
#include <cassert>
#include <stdexcept>
2022-10-19 17:02:00 +00:00
#include <string>
#include <type_traits>
#include <utility>
#include <apps/opencs/model/world/universalid.hpp>
2012-12-11 12:22:43 +00:00
CSVDoc::SubViewFactoryManager::~SubViewFactoryManager()
{
2022-09-22 18:26:05 +00:00
for (std::map<CSMWorld::UniversalId::Type, SubViewFactoryBase*>::iterator iter(mSubViewFactories.begin());
iter != mSubViewFactories.end(); ++iter)
2012-12-11 12:22:43 +00:00
delete iter->second;
}
2022-09-22 18:26:05 +00:00
void CSVDoc::SubViewFactoryManager::add(const CSMWorld::UniversalId::Type& id, SubViewFactoryBase* factory)
2012-12-11 12:22:43 +00:00
{
2022-09-22 18:26:05 +00:00
assert(mSubViewFactories.find(id) == mSubViewFactories.end());
2012-12-11 12:22:43 +00:00
2022-09-22 18:26:05 +00:00
mSubViewFactories.insert(std::make_pair(id, factory));
2012-12-11 12:22:43 +00:00
}
2022-09-22 18:26:05 +00:00
CSVDoc::SubView* CSVDoc::SubViewFactoryManager::makeSubView(const CSMWorld::UniversalId& id, CSMDoc::Document& document)
2012-12-11 12:22:43 +00:00
{
2022-09-22 18:26:05 +00:00
std::map<CSMWorld::UniversalId::Type, SubViewFactoryBase*>::iterator iter = mSubViewFactories.find(id.getType());
2012-12-11 12:22:43 +00:00
2022-09-22 18:26:05 +00:00
if (iter == mSubViewFactories.end())
throw std::runtime_error("Failed to create a sub view for: " + id.toString());
2012-12-11 12:22:43 +00:00
2022-09-22 18:26:05 +00:00
return iter->second->makeSubView(id, document);
2015-03-11 14:54:45 +00:00
}