mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Use pointers in containers to guaranteed fixed address
This commit is contained in:
parent
a30e7ba321
commit
82989e6302
@ -29,7 +29,7 @@ void CRmgTemplateStorage::afterLoadFinalization()
|
||||
{
|
||||
for (auto& temp : templates)
|
||||
{
|
||||
temp.second.afterLoad();
|
||||
temp.second->afterLoad();
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,10 +39,10 @@ void CRmgTemplateStorage::loadObject(std::string scope, std::string name, const
|
||||
{
|
||||
JsonDeserializer handler(nullptr, data);
|
||||
auto fullKey = scope + ":" + name; //actually it's not used
|
||||
templates[fullKey].setId(fullKey);
|
||||
templates[fullKey].serializeJson(handler);
|
||||
templates[fullKey].setName(name);
|
||||
templates[fullKey].validate();
|
||||
templates[fullKey]->setId(fullKey);
|
||||
templates[fullKey]->serializeJson(handler);
|
||||
templates[fullKey]->setName(name);
|
||||
templates[fullKey]->validate();
|
||||
}
|
||||
catch(const std::exception & e)
|
||||
{
|
||||
@ -67,7 +67,7 @@ const CRmgTemplate * CRmgTemplateStorage::getTemplate(const std::string & templa
|
||||
auto iter = templates.find(templateName);
|
||||
if(iter==templates.end())
|
||||
return nullptr;
|
||||
return &iter->second;
|
||||
return iter->second.get();
|
||||
}
|
||||
|
||||
std::vector<const CRmgTemplate *> CRmgTemplateStorage::getTemplates() const
|
||||
@ -76,7 +76,7 @@ std::vector<const CRmgTemplate *> CRmgTemplateStorage::getTemplates() const
|
||||
result.reserve(templates.size());
|
||||
for(const auto & i : templates)
|
||||
{
|
||||
result.push_back(&i.second);
|
||||
result.push_back(i.second.get());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
std::vector<const CRmgTemplate *> getTemplates() const;
|
||||
|
||||
private:
|
||||
std::map<std::string, CRmgTemplate> templates;
|
||||
std::map<std::string, std::unique_ptr<CRmgTemplate>> templates;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user