From d61f0b9607fa31a0a817c350889b7259f4d1d516 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 14 Jan 2015 20:01:05 +0100 Subject: [PATCH] [DEV] update new xml interface --- esvg/Base.cpp | 14 +++++++------- esvg/Base.h | 8 ++++---- esvg/Circle.cpp | 4 ++-- esvg/Circle.h | 2 +- esvg/Ellipse.cpp | 4 ++-- esvg/Ellipse.h | 2 +- esvg/Group.cpp | 14 +++++++------- esvg/Group.h | 2 +- esvg/Line.cpp | 4 ++-- esvg/Line.h | 2 +- esvg/Path.cpp | 12 ++++++------ esvg/Path.h | 2 +- esvg/Polygon.cpp | 4 ++-- esvg/Polygon.h | 2 +- esvg/Polyline.cpp | 4 ++-- esvg/Polyline.h | 2 +- esvg/Rectangle.cpp | 4 ++-- esvg/Rectangle.h | 2 +- esvg/Text.cpp | 2 +- esvg/Text.h | 2 +- esvg/esvg.cpp | 14 ++++++-------- 21 files changed, 52 insertions(+), 54 deletions(-) diff --git a/esvg/Base.cpp b/esvg/Base.cpp index 2057659..b8cfb1d 100644 --- a/esvg/Base.cpp +++ b/esvg/Base.cpp @@ -20,8 +20,8 @@ esvg::Base::Base(PaintState _parentPaintState) { m_paint = _parentPaintState; } -void esvg::Base::parseTransform(exml::Element* _element) { - if (NULL == _element) { +void esvg::Base::parseTransform(const std::shared_ptr& _element) { + if (_element == nullptr) { return; } std::string inputString = _element->getAttribute("transform"); @@ -85,11 +85,11 @@ void esvg::Base::parseTransform(exml::Element* _element) { * @param[out] _pos parsed position * @param[out] _size parsed dimention */ -void esvg::Base::parsePosition(const exml::Element *_element, etk::Vector2D &_pos, etk::Vector2D &_size) { +void esvg::Base::parsePosition(const std::shared_ptr& _element, etk::Vector2D &_pos, etk::Vector2D &_size) { _pos.setValue(0,0); _size.setValue(0,0); - if (NULL == _element) { + if (_element == nullptr) { return; } std::string content = _element->getAttribute("x"); @@ -194,8 +194,8 @@ int32_t extractPartOfStyle(const std::string& _data, std::string& _outputType, s * @brief parse a Painting attribute of a specific node * @param[in] _element Basic node of the XML that might be parsed */ -void esvg::Base::parsePaintAttr(const exml::Element *_element) { - if (_element == NULL) { +void esvg::Base::parsePaintAttr(const std::shared_ptr& _element) { + if (_element == nullptr) { return; } bool fillNone = false; @@ -389,7 +389,7 @@ draw::Color esvg::Base::parseColor(const std::string& _inputData) { * @param[in] _element standart XML node * @return true if no problem arrived */ -bool esvg::Base::parse(exml::Element* _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { +bool esvg::Base::parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { SVG_ERROR("NOT IMPLEMENTED"); _sizeMax.setValue(0,0); return false; diff --git a/esvg/Base.h b/esvg/Base.h index a1a5b90..f3d6396 100644 --- a/esvg/Base.h +++ b/esvg/Base.h @@ -38,15 +38,15 @@ namespace esvg { Base() {}; Base(PaintState _parentPaintState); virtual ~Base() { }; - virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); + virtual bool parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); //specific drawing for AAG librairy ... virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans) { }; virtual void display(int32_t _spacing) { }; - void parseTransform(exml::Element *_element); - void parsePosition(const exml::Element *_element, etk::Vector2D &_pos, etk::Vector2D &_size); + void parseTransform(const std::shared_ptr& _element); + void parsePosition(const std::shared_ptr& _element, etk::Vector2D &_pos, etk::Vector2D &_size); float parseLength(const std::string& _dataInput); - void parsePaintAttr(const exml::Element *_element); + void parsePaintAttr(const std::shared_ptr& _element); draw::Color parseColor(const std::string& _inputData); }; }; diff --git a/esvg/Circle.cpp b/esvg/Circle.cpp index d713fbe..e9be1e4 100644 --- a/esvg/Circle.cpp +++ b/esvg/Circle.cpp @@ -22,10 +22,10 @@ esvg::Circle::~Circle() { } -bool esvg::Circle::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { +bool esvg::Circle::parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { m_radius = 0.0; m_position.setValue(0,0); - if (NULL == _element) { + if (_element == nullptr) { return false; } parseTransform(_element); diff --git a/esvg/Circle.h b/esvg/Circle.h index 4968db7..a33d5de 100644 --- a/esvg/Circle.h +++ b/esvg/Circle.h @@ -19,7 +19,7 @@ namespace esvg { public: Circle(PaintState _parentPaintState); ~Circle(); - virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); + virtual bool parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); virtual void display(int32_t _spacing); virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans); }; diff --git a/esvg/Ellipse.cpp b/esvg/Ellipse.cpp index 6412756..c3a42b1 100644 --- a/esvg/Ellipse.cpp +++ b/esvg/Ellipse.cpp @@ -22,8 +22,8 @@ esvg::Ellipse::~Ellipse() { } -bool esvg::Ellipse::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { - if (NULL == _element) { +bool esvg::Ellipse::parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { + if (_element == nullptr) { return false; } parseTransform(_element); diff --git a/esvg/Ellipse.h b/esvg/Ellipse.h index 1469eb1..c40e1de 100644 --- a/esvg/Ellipse.h +++ b/esvg/Ellipse.h @@ -19,7 +19,7 @@ namespace esvg { public: Ellipse(PaintState _parentPaintState); ~Ellipse(); - virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); + virtual bool parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); virtual void display(int32_t _spacing); virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans); }; diff --git a/esvg/Group.cpp b/esvg/Group.cpp index 8f23f39..df13f80 100644 --- a/esvg/Group.cpp +++ b/esvg/Group.cpp @@ -31,8 +31,8 @@ esvg::Group::~Group() { } -bool esvg::Group::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { - if (NULL == _element) { +bool esvg::Group::parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { + if (_element == nullptr) { return false; } // parse ... @@ -52,12 +52,12 @@ bool esvg::Group::parse(exml::Element * _element, agg::trans_affine& _parentTran vec2 tmpPos(0,0); // parse all sub node : for(int32_t iii=0; iii<_element->size() ; iii++) { - exml::Element* child = _element->getElement(iii); - if (NULL == child) { + std::shared_ptr child = _element->getElement(iii); + if (child == nullptr) { // can be a comment ... continue; } - esvg::Base *elementParser = NULL; + esvg::Base *elementParser = nullptr; if (child->getValue() == "g") { elementParser = new esvg::Group(m_paint); } else if (child->getValue() == "a") { @@ -81,13 +81,13 @@ bool esvg::Group::parse(exml::Element * _element, agg::trans_affine& _parentTran } else { SVG_ERROR("(l "<getPos()<<") node not suported : \""<getValue()<<"\" must be [g,a,path,rect,circle,ellipse,line,polyline,polygon,text]"); } - if (NULL == elementParser) { + if (elementParser == nullptr) { SVG_ERROR("(l "<getPos()<<") error on node: \""<getValue()<<"\" allocation error or not supported ..."); } else { if (false == elementParser->parse(child, m_transformMatrix, tmpPos)) { SVG_ERROR("(l "<getPos()<<") error on node: \""<getValue()<<"\" Sub Parsing ERROR"); delete(elementParser); - elementParser = NULL; + elementParser = nullptr; } else { _sizeMax.setValue(std::max(_sizeMax.x(), tmpPos.x()), std::max(_sizeMax.y(), tmpPos.y())); diff --git a/esvg/Group.h b/esvg/Group.h index 5c5442d..883a526 100644 --- a/esvg/Group.h +++ b/esvg/Group.h @@ -19,7 +19,7 @@ namespace esvg { public: Group(PaintState _parentPaintState); ~Group(); - virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); + virtual bool parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); virtual void display(int32_t spacing); virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans); }; diff --git a/esvg/Line.cpp b/esvg/Line.cpp index fb1f0a1..532094f 100644 --- a/esvg/Line.cpp +++ b/esvg/Line.cpp @@ -23,10 +23,10 @@ esvg::Line::~Line() { } -bool esvg::Line::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { +bool esvg::Line::parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { // line must have a minimum size... m_paint.strokeWidth = 1; - if (NULL == _element) { + if (_element == nullptr) { return false; } parseTransform(_element); diff --git a/esvg/Line.h b/esvg/Line.h index 816f79a..e3dd692 100644 --- a/esvg/Line.h +++ b/esvg/Line.h @@ -19,7 +19,7 @@ namespace esvg { public: Line(PaintState _parentPaintState); ~Line(); - virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); + virtual bool parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); virtual void display(int32_t _spacing); virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans); }; diff --git a/esvg/Path.cpp b/esvg/Path.cpp index 1554b14..26a99ee 100644 --- a/esvg/Path.cpp +++ b/esvg/Path.cpp @@ -29,17 +29,17 @@ esvg::Path::~Path() { // return the next char position ... (after 'X' or NULL) const char * extractCmd(const char* _input, char& _cmd, std::vector& _outputList) { if (*_input == '\0') { - return NULL; + return nullptr; } _outputList.clear(); _cmd = '\0'; - const char * outputPointer = NULL; + const char * outputPointer = nullptr; if (!( ( _input[0] <= 'Z' && _input[0] >= 'A') || ( _input[0] <= 'z' && _input[0] >= 'a') ) ) { SVG_ERROR("Error in the SVG Path : \"" << _input << "\""); - return NULL; + return nullptr; } _cmd = _input[0]; SVG_VERBOSE("Find command : " << _cmd); @@ -65,8 +65,8 @@ const char * extractCmd(const char* _input, char& _cmd, std::vector& _out return outputPointer; } -bool esvg::Path::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { - if (NULL == _element) { +bool esvg::Path::parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { + if (_element == nullptr) { return false; } parseTransform(_element); @@ -89,7 +89,7 @@ bool esvg::Path::parse(exml::Element * _element, agg::trans_affine& _parentTrans const char* elementXML = elementXML1.c_str(); for( const char *sss=extractCmd(elementXML, command, listDot); - NULL != sss; + sss != nullptr; sss=extractCmd(sss, command, listDot) ) { PathBasic pathElement; switch(command) { diff --git a/esvg/Path.h b/esvg/Path.h index 071aae8..39a8b0d 100644 --- a/esvg/Path.h +++ b/esvg/Path.h @@ -42,7 +42,7 @@ namespace esvg { public: Path(PaintState _parentPaintState); ~Path(); - virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); + virtual bool parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); virtual void display(int32_t _spacing); virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans); private: diff --git a/esvg/Polygon.cpp b/esvg/Polygon.cpp index c7d1745..de0a8db 100644 --- a/esvg/Polygon.cpp +++ b/esvg/Polygon.cpp @@ -22,8 +22,8 @@ esvg::Polygon::~Polygon() { } -bool esvg::Polygon::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { - if (NULL == _element) { +bool esvg::Polygon::parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { + if (_element == nullptr) { return false; } parseTransform(_element); diff --git a/esvg/Polygon.h b/esvg/Polygon.h index 0464d5d..c626a83 100644 --- a/esvg/Polygon.h +++ b/esvg/Polygon.h @@ -26,7 +26,7 @@ namespace esvg { public: Polygon(PaintState parentPaintState); ~Polygon(); - virtual bool parse(exml::Element * _element, agg::trans_affine& parentTrans, etk::Vector2D& sizeMax); + virtual bool parse(const std::shared_ptr& _element, agg::trans_affine& parentTrans, etk::Vector2D& sizeMax); virtual void display(int32_t spacing); virtual void aggDraw(esvg::Renderer& myRenderer, agg::trans_affine& basicTrans); }; diff --git a/esvg/Polyline.cpp b/esvg/Polyline.cpp index 4e29e23..4b2c168 100644 --- a/esvg/Polyline.cpp +++ b/esvg/Polyline.cpp @@ -19,10 +19,10 @@ esvg::Polyline::~Polyline() { } -bool esvg::Polyline::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { +bool esvg::Polyline::parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { // line must have a minimum size... m_paint.strokeWidth = 1; - if (NULL == _element) { + if (_element == nullptr) { return false; } parseTransform(_element); diff --git a/esvg/Polyline.h b/esvg/Polyline.h index 345e9ce..4e6e06a 100644 --- a/esvg/Polyline.h +++ b/esvg/Polyline.h @@ -19,7 +19,7 @@ namespace esvg { public: Polyline(PaintState _parentPaintState); ~Polyline(); - virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); + virtual bool parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); virtual void display(int32_t _spacing); virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans); }; diff --git a/esvg/Rectangle.cpp b/esvg/Rectangle.cpp index 6425ba3..e9d241e 100644 --- a/esvg/Rectangle.cpp +++ b/esvg/Rectangle.cpp @@ -25,8 +25,8 @@ esvg::Rectangle::~Rectangle() { } -bool esvg::Rectangle::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { - if (NULL == _element) { +bool esvg::Rectangle::parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { + if (_element == nullptr) { return false; } m_position.setValue(0,0); diff --git a/esvg/Rectangle.h b/esvg/Rectangle.h index 13fc9c5..6c368ef 100644 --- a/esvg/Rectangle.h +++ b/esvg/Rectangle.h @@ -20,7 +20,7 @@ namespace esvg { public: Rectangle(PaintState _parentPaintState); ~Rectangle(); - virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); + virtual bool parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); virtual void display(int32_t _spacing); virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans); }; diff --git a/esvg/Text.cpp b/esvg/Text.cpp index 02faf3e..6f74783 100644 --- a/esvg/Text.cpp +++ b/esvg/Text.cpp @@ -20,7 +20,7 @@ esvg::Text::~Text() { } -bool esvg::Text::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { +bool esvg::Text::parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax) { _sizeMax.setValue(0,0); SVG_ERROR("NOT IMPLEMENTED"); return false; diff --git a/esvg/Text.h b/esvg/Text.h index 5cfe61e..2d7e38d 100644 --- a/esvg/Text.h +++ b/esvg/Text.h @@ -16,7 +16,7 @@ namespace esvg { public: Text(PaintState _parentPaintState); ~Text(); - virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); + virtual bool parse(const std::shared_ptr& _element, agg::trans_affine& _parentTrans, etk::Vector2D& _sizeMax); virtual void display(int32_t _spacing); }; }; diff --git a/esvg/esvg.cpp b/esvg/esvg.cpp index 6b1d748..ed2d054 100644 --- a/esvg/esvg.cpp +++ b/esvg/esvg.cpp @@ -36,7 +36,7 @@ esvg::Document::Document(const std::string& _fileName) : - m_renderedElement(NULL) { + m_renderedElement(nullptr) { m_fileName = _fileName; m_version = "0.0"; m_loadOK = true; @@ -56,15 +56,13 @@ esvg::Document::Document(const std::string& _fileName) : m_loadOK = false; return; } - if (0 == doc.size() ) { SVG_ERROR("(l ?) No nodes in the xml file ... \"" << m_fileName << "\""); m_loadOK = false; return; } - - exml::Element* root = (exml::Element*)doc.getNamed("svg" ); - if (NULL == root ) { + std::shared_ptr root = doc.getNamed("svg" ); + if (root == nullptr) { SVG_ERROR("(l ?) main node not find: \"svg\" in \"" << m_fileName << "\""); m_loadOK = false; return; @@ -81,12 +79,12 @@ esvg::Document::Document(const std::string& _fileName) : vec2 size(0,0); // parse all sub node : for(int32_t iii=0; iii< root->size(); iii++) { - exml::Element* child = root->getElement(iii); - if (child == NULL) { + std::shared_ptr child = root->getElement(iii); + if (child == nullptr) { // comment trsh here... continue; } - esvg::Base *elementParser = NULL; + esvg::Base *elementParser = nullptr; if (child->getValue() == "g") { elementParser = new esvg::Group(m_paint); } else if (child->getValue() == "a") {