From 82989e630291fbeedd1bf43bff62d8e41fa9d05c Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 25 Aug 2023 21:42:02 +0300 Subject: [PATCH] Use pointers in containers to guaranteed fixed address --- lib/rmg/CRmgTemplateStorage.cpp | 14 +++++++------- lib/rmg/CRmgTemplateStorage.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/rmg/CRmgTemplateStorage.cpp b/lib/rmg/CRmgTemplateStorage.cpp index ae5f01c00..9e6423b9b 100644 --- a/lib/rmg/CRmgTemplateStorage.cpp +++ b/lib/rmg/CRmgTemplateStorage.cpp @@ -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 CRmgTemplateStorage::getTemplates() const @@ -76,7 +76,7 @@ std::vector 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; } diff --git a/lib/rmg/CRmgTemplateStorage.h b/lib/rmg/CRmgTemplateStorage.h index 2837fc262..8a129dff1 100644 --- a/lib/rmg/CRmgTemplateStorage.h +++ b/lib/rmg/CRmgTemplateStorage.h @@ -37,7 +37,7 @@ public: std::vector getTemplates() const; private: - std::map templates; + std::map> templates; };