// // Created by trotfunky on 15/05/19. // #include "Group.h" 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(const pugi::xml_node& node) : DrawingElement(node) { if(label == "Test DrawingElement") { label = "Test Group"; } if(!strncmp(node.name(),"Drawing",7)) { x = 0; y = 0; label = "Drawing"; color = sf::Color::Transparent; } pugi::xml_object_range circleChildren = node.children(); for(pugi::xml_node_iterator child : circleChildren) { pugi::xml_node& childNode = (*child); DrawingElement* newElement = !strncmp(childNode.name(),"Circle",6) ? dynamic_cast(new Circle(childNode)) : !strncmp(childNode.name(),"Group",5) ? dynamic_cast(new Group(childNode)) : nullptr; if(newElement != nullptr) { drawingElements.emplace(std::make_pair(newElement->label,std::move(std::unique_ptr(newElement)))); } } } Group::Group(const std::map& elements) : Group() { std::transform(elements.begin(),elements.end(),std::inserter(drawingElements,drawingElements.begin()), [](std::pair 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,std::move(std::unique_ptr(drawingElement)))).second); } bool Group::removeDrawingElement(const std::string& label) { return(drawingElements.erase(label)); } DrawingElement* Group::getDrawingElement(const std::string& label) { return(drawingElements.at(label).get()); } void Group::draw(sf::RenderWindow& window) { for(const auto& element : drawingElements) { element.second->draw(window,x,y); } } const std::string Group::toString(int indent) const { std::stringstream string; for(int i = 0;itoString(indent+1) << std::endl; } return(string.str()); } }