diff --git a/xmlParser/CMakeLists.txt b/xmlParser/CMakeLists.txt index e1acc4e..c0d5b84 100644 --- a/xmlParser/CMakeLists.txt +++ b/xmlParser/CMakeLists.txt @@ -37,6 +37,8 @@ target_link_libraries(xmlParser sfml-graphics pugixml) +target_compile_options(xmlParser PRIVATE -Wall -Wpedantic -Wextra) + add_executable(gTestXMLParser gTestXMLParser.cpp) target_compile_options(gTestXMLParser PRIVATE -pthread) diff --git a/xmlParser/Circle.cpp b/xmlParser/Circle.cpp index 338ed92..343d535 100644 --- a/xmlParser/Circle.cpp +++ b/xmlParser/Circle.cpp @@ -9,7 +9,7 @@ namespace xmlParser Circle::Circle(std::string label, float x, float y, float r, const sf::Color& color) : DrawingElement(std::move(label),x,y,color), r(2) { - shape = new sf::CircleShape(r); + shape = std::unique_ptr(new sf::CircleShape(r)); shape->setPosition(x-r,y-r); shape->setFillColor(color); } @@ -20,16 +20,11 @@ namespace xmlParser { label = "Test Circle"; } - shape = new sf::CircleShape(r); + shape = std::unique_ptr(new sf::CircleShape(r)); shape->setPosition(x-r,y-r); shape->setFillColor(color); } - void Circle::draw(sf::RenderWindow& window) - { - window.draw(*(dynamic_cast(shape))); - } - float Circle::getR() const { return r; @@ -38,7 +33,7 @@ namespace xmlParser void Circle::setR(float newR) { r = newR; - dynamic_cast(shape)->setRadius(r); + dynamic_cast(shape.get())->setRadius(r); shape->setPosition(x-r,y-r); } diff --git a/xmlParser/Circle.h b/xmlParser/Circle.h index d7fc924..ee945e3 100644 --- a/xmlParser/Circle.h +++ b/xmlParser/Circle.h @@ -22,8 +22,6 @@ namespace xmlParser explicit Circle(const pugi::xml_node&); - void draw(sf::RenderWindow&) override; - void setX(float newX) override; void setY(float newY) override; diff --git a/xmlParser/DrawingElement.cpp b/xmlParser/DrawingElement.cpp index 8c83d87..573b894 100644 --- a/xmlParser/DrawingElement.cpp +++ b/xmlParser/DrawingElement.cpp @@ -9,16 +9,21 @@ namespace xmlParser { - DrawingElement::DrawingElement(std::string label, float x, float y, const sf::Color& color) : x(x), y(-y), label(std::move(label)), + DrawingElement::DrawingElement(std::string label, float x, float y, const sf::Color& color) : label(std::move(label)), x(x), y(-y), color(color), shape(nullptr) {} - DrawingElement::DrawingElement(const pugi::xml_node& node) : x(node.attribute("x").as_int(0)), - y(-node.attribute("y").as_int(1)), label(node.attribute("label").as_string("Test DrawingElement")), shape(nullptr) + DrawingElement::DrawingElement(const pugi::xml_node& node) : label(node.attribute("label").as_string("Test DrawingElement")), + x(node.attribute("x").as_int(0)), y(-node.attribute("y").as_int(1)), shape(nullptr) { setColor(node.attribute("color").as_string("Yellow")); } + void DrawingElement::draw(sf::RenderWindow& window) + { + window.draw(*shape); + } + void DrawingElement::draw(sf::RenderWindow& window, float referenceX, float referenceY) { setX(x+referenceX); @@ -37,7 +42,7 @@ namespace xmlParser { x = newX; - if(shape != nullptr) + if(shape) { shape->setPosition(x,-y); } @@ -52,7 +57,7 @@ namespace xmlParser { y = newY; - if(shape != nullptr) + if(shape) { shape->setPosition(x,-y); } @@ -83,19 +88,6 @@ namespace xmlParser color = strToColor(stringColor); } - const std::string DrawingElement::toString(int indent) const - { - std::stringstream string; - for(int i = 0;i shape; }; }