From 86273890ae5007f6bbb0d027e29908b5b596db28 Mon Sep 17 00:00:00 2001 From: trotFunky Date: Wed, 22 May 2019 18:47:48 +0200 Subject: [PATCH] Smart pointers to manage DrawingElements --- xmlParser/Group.cpp | 10 +++++----- xmlParser/Group.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/xmlParser/Group.cpp b/xmlParser/Group.cpp index 08a2e6d..a9735b6 100644 --- a/xmlParser/Group.cpp +++ b/xmlParser/Group.cpp @@ -6,7 +6,7 @@ namespace xmlParser { - Group::Group(std::string label, float x, float y, const sf::Color& color) : DrawingElement(std::move(label),x,y,color), drawingElements({}) + Group::Group(std::string label, float x, float y, const sf::Color& color) : DrawingElement(std::move(label),x,y,color), drawingElements() {} Group::Group(const pugi::xml_node& node) : DrawingElement(node) @@ -32,7 +32,7 @@ namespace xmlParser !strncmp(childNode.name(),"Group",5) ? dynamic_cast(new Group(childNode)) : nullptr; if(newElement != nullptr) { - drawingElements.insert(std::make_pair(newElement->label,newElement)); + drawingElements.emplace(std::make_pair(newElement->label,std::move(std::unique_ptr(newElement)))); } } } @@ -42,13 +42,13 @@ namespace xmlParser std::transform(elements.begin(),elements.end(),std::inserter(drawingElements,drawingElements.begin()), [](std::pair pair) { - return(pair); + return(std::make_pair(pair.first,std::move(std::unique_ptr(pair.second)))); }); } bool Group::addDrawingElement(DrawingElement* drawingElement) { - return(drawingElements.insert(std::make_pair(drawingElement->label,drawingElement)).second); + return(drawingElements.insert(std::make_pair(drawingElement->label,std::move(std::unique_ptr(drawingElement)))).second); } bool Group::removeDrawingElement(const std::string& label) @@ -58,7 +58,7 @@ namespace xmlParser DrawingElement* Group::getDrawingElement(const std::string& label) { - return(drawingElements.at(label)); + return(drawingElements.at(label).get()); } void Group::draw(sf::RenderWindow& window) diff --git a/xmlParser/Group.h b/xmlParser/Group.h index f1c9141..1d7b2c7 100644 --- a/xmlParser/Group.h +++ b/xmlParser/Group.h @@ -36,7 +36,7 @@ namespace xmlParser const std::string toString(int indent) const override; private: - std::map drawingElements; + std::map> drawingElements; }; }