1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

Use pointers in containers to guaranteed fixed address

This commit is contained in:
Ivan Savenko 2023-08-25 21:42:02 +03:00
parent a30e7ba321
commit 82989e6302
2 changed files with 8 additions and 8 deletions

View File

@ -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;
}

View File

@ -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;
};