configure.ac | 1 - src/lib/MSPUBCollector.cpp | 24 +++++++++++------------- src/lib/MSPUBCollector.h | 11 +++++------ src/lib/MSPUBParser2k.cpp | 10 ++++------ src/lib/ShapeGroupElement.cpp | 8 ++------ src/lib/ShapeGroupElement.h | 5 +++-- 6 files changed, 25 insertions(+), 34 deletions(-)
New commits: commit bbe7f806b95ef427153ba18bff80e674b1704ae5 Author: David Tardon <dtar...@redhat.com> Date: Sun Apr 23 19:14:45 2017 +0200 replace dumb pointers by smart ones Change-Id: I9e70f71e67aff4d8ee5ffa1f2024d20686fea222 diff --git a/configure.ac b/configure.ac index a83aedd..c058bca 100644 --- a/configure.ac +++ b/configure.ac @@ -97,7 +97,6 @@ AC_SUBST(ZLIB_LIBS) AC_CHECK_HEADERS( boost/numeric/conversion/cast.hpp \ boost/optional.hpp \ - boost/ptr_container/ptr_vector.hpp \ , [], [AC_MSG_ERROR(Required boost headers not found. Install boost)], diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp index 1dd2ce2..d900893 100644 --- a/src/lib/MSPUBCollector.cpp +++ b/src/lib/MSPUBCollector.cpp @@ -442,7 +442,7 @@ void MSPUBCollector::setShapeClipPath(unsigned seqNum, const std::vector<Vertex> void MSPUBCollector::beginGroup() { - ShapeGroupElement *tmp = new ShapeGroupElement(m_currentShapeGroup); + auto tmp = std::make_shared<ShapeGroupElement>(m_currentShapeGroup.get()); if (!m_currentShapeGroup) { m_topLevelShapes.push_back(tmp); @@ -456,7 +456,9 @@ bool MSPUBCollector::endGroup() { return false; } - m_currentShapeGroup = m_currentShapeGroup->getParent(); + auto parent = m_currentShapeGroup->getParent(); + if (parent) + m_currentShapeGroup = parent->shared_from_this(); return true; } @@ -492,13 +494,13 @@ bool MSPUBCollector::setCurrentGroupSeqNum(unsigned seqNum) return false; } m_currentShapeGroup->setSeqNum(seqNum); - m_groupsBySeqNum.insert(std::pair<unsigned, ShapeGroupElement *>(seqNum, m_currentShapeGroup)); + m_groupsBySeqNum.insert(std::make_pair(seqNum, m_currentShapeGroup)); return true; } void MSPUBCollector::setShapeOrder(unsigned seqNum) { - ShapeGroupElement *tmp = new ShapeGroupElement(m_currentShapeGroup, seqNum); + auto tmp = std::make_shared<ShapeGroupElement>(m_currentShapeGroup.get(), seqNum); if (!m_currentShapeGroup) { m_topLevelShapes.push_back(tmp); @@ -1618,14 +1620,14 @@ void MSPUBCollector::assignShapesToPages() { for (unsigned i = 0; i < m_topLevelShapes.size(); ++i) { - unsigned *ptr_pageSeqNum = getIfExists(m_pageSeqNumsByShapeSeqNum, m_topLevelShapes[i].getSeqNum()); - m_topLevelShapes[i].setup(std::bind(&MSPUBCollector::setupShapeStructures, this, _1)); + unsigned *ptr_pageSeqNum = getIfExists(m_pageSeqNumsByShapeSeqNum, m_topLevelShapes[i]->getSeqNum()); + m_topLevelShapes[i]->setup(std::bind(&MSPUBCollector::setupShapeStructures, this, _1)); if (ptr_pageSeqNum) { PageInfo *ptr_page = getIfExists(m_pagesBySeqNum, *ptr_pageSeqNum); if (ptr_page) { - ptr_page->m_shapeGroupsOrdered.push_back(&m_topLevelShapes[i]); + ptr_page->m_shapeGroupsOrdered.push_back(m_topLevelShapes[i]); } } } @@ -1654,7 +1656,7 @@ void MSPUBCollector::writePage(unsigned pageSeqNum) const { pageProps.insert("svg:height", m_height); } - const std::vector<ShapeGroupElement *> &shapeGroupsOrdered = pageInfo.m_shapeGroupsOrdered; + const auto &shapeGroupsOrdered = pageInfo.m_shapeGroupsOrdered; if (!shapeGroupsOrdered.empty()) { m_painter->startPage(pageProps); @@ -1677,12 +1679,8 @@ void MSPUBCollector::writePage(unsigned pageSeqNum) const void MSPUBCollector::writePageShapes(unsigned pageSeqNum) const { const PageInfo &pageInfo = m_pagesBySeqNum.find(pageSeqNum)->second; - const std::vector<ShapeGroupElement *> &shapeGroupsOrdered = pageInfo.m_shapeGroupsOrdered; - for (unsigned i = 0; i < shapeGroupsOrdered.size(); ++i) - { - ShapeGroupElement *shapeGroup = shapeGroupsOrdered[i]; + for (const auto &shapeGroup : pageInfo.m_shapeGroupsOrdered) shapeGroup->visit(std::bind(&MSPUBCollector::paintShape, this, _1, _2, _3, _4, _5)); - } } void MSPUBCollector::writePageBackground(unsigned pageSeqNum) const diff --git a/src/lib/MSPUBCollector.h b/src/lib/MSPUBCollector.h index b260e6f..d40b021 100644 --- a/src/lib/MSPUBCollector.h +++ b/src/lib/MSPUBCollector.h @@ -14,12 +14,11 @@ #include <list> #include <vector> #include <map> +#include <memory> #include <set> #include <string> #include <algorithm> -#include <boost/ptr_container/ptr_vector.hpp> - #include <librevenge/librevenge.h> #include <librevenge/librevenge.h> @@ -132,7 +131,7 @@ private: struct PageInfo { - std::vector<ShapeGroupElement *> m_shapeGroupsOrdered; + std::vector<std::shared_ptr<ShapeGroupElement>> m_shapeGroupsOrdered; PageInfo() : m_shapeGroupsOrdered() { } }; @@ -158,9 +157,9 @@ private: std::map<unsigned, unsigned> m_pageSeqNumsByShapeSeqNum; std::map<unsigned, unsigned> m_bgShapeSeqNumsByPageSeqNum; std::set<unsigned> m_skipIfNotBgSeqNums; - ShapeGroupElement *m_currentShapeGroup; - boost::ptr_vector<ShapeGroupElement> m_topLevelShapes; - std::map<unsigned, ShapeGroupElement *> m_groupsBySeqNum; + std::shared_ptr<ShapeGroupElement> m_currentShapeGroup; + std::vector<std::shared_ptr<ShapeGroupElement>> m_topLevelShapes; + std::map<unsigned, std::shared_ptr<ShapeGroupElement>> m_groupsBySeqNum; std::list<EmbeddedFontInfo> m_embeddedFonts; std::map<unsigned, ShapeInfo> m_shapeInfosBySeqNum; std::set<unsigned> m_masterPages; diff --git a/src/lib/ShapeGroupElement.cpp b/src/lib/ShapeGroupElement.cpp index 529156b..f94ce8e 100644 --- a/src/lib/ShapeGroupElement.cpp +++ b/src/lib/ShapeGroupElement.cpp @@ -16,23 +16,19 @@ ShapeGroupElement::ShapeGroupElement(ShapeGroupElement *parent) : m_shapeInfo(), { if (m_parent) { - m_parent->m_children.push_back(this); + m_parent->m_children.push_back(shared_from_this()); } } ShapeGroupElement::~ShapeGroupElement() { - for (unsigned i = 0; i < m_children.size(); ++i) - { - delete m_children[i]; - } } ShapeGroupElement::ShapeGroupElement(ShapeGroupElement *parent, unsigned seqNum) : m_shapeInfo(), m_parent(parent), m_children(), m_seqNum(seqNum), m_transform() { if (m_parent) { - m_parent->m_children.push_back(this); + m_parent->m_children.push_back(shared_from_this()); } } diff --git a/src/lib/ShapeGroupElement.h b/src/lib/ShapeGroupElement.h index 86ea888..ef7d175 100644 --- a/src/lib/ShapeGroupElement.h +++ b/src/lib/ShapeGroupElement.h @@ -11,6 +11,7 @@ #define __SHAPEGROUPELEMENT_H__ #include <boost/optional.hpp> #include <functional> +#include <memory> #include <vector> #include "ShapeInfo.h" @@ -18,11 +19,11 @@ namespace libmspub { -class ShapeGroupElement +class ShapeGroupElement : public std::enable_shared_from_this<ShapeGroupElement> { boost::optional<ShapeInfo> m_shapeInfo; ShapeGroupElement *m_parent; - std::vector<ShapeGroupElement *> m_children; + std::vector<std::shared_ptr<ShapeGroupElement>> m_children; unsigned m_seqNum; ShapeGroupElement &operator=(const ShapeGroupElement &); //not implemented ShapeGroupElement(const ShapeGroupElement &); //not implemented commit 8ff2475100ad7f46835fadc04941902c7d9027a8 Author: David Tardon <dtar...@redhat.com> Date: Sun Apr 23 18:44:47 2017 +0200 replace dumb pointers by smart ones Change-Id: I1490bee34ce0ab9f1a9777b46753b1e5cba5adad diff --git a/src/lib/MSPUBParser2k.cpp b/src/lib/MSPUBParser2k.cpp index e68bd93..62342c4 100644 --- a/src/lib/MSPUBParser2k.cpp +++ b/src/lib/MSPUBParser2k.cpp @@ -769,28 +769,26 @@ void MSPUBParser2k::parseShapeLine(librevenge::RVNGInputStream *input, bool isRe bool MSPUBParser2k::parse() { - librevenge::RVNGInputStream *contents = m_input->getSubStreamByName("Contents"); + std::unique_ptr<librevenge::RVNGInputStream> contents(m_input->getSubStreamByName("Contents")); if (!contents) { MSPUB_DEBUG_MSG(("Couldn't get contents stream.\n")); return false; } - if (!parseContents(contents)) + if (!parseContents(contents.get())) { MSPUB_DEBUG_MSG(("Couldn't parse contents stream.\n")); - delete contents; return false; } - librevenge::RVNGInputStream *quill = m_input->getSubStreamByName("Quill/QuillSub/CONTENTS"); + std::unique_ptr<librevenge::RVNGInputStream> quill(m_input->getSubStreamByName("Quill/QuillSub/CONTENTS")); if (!quill) { MSPUB_DEBUG_MSG(("Couldn't get quill stream.\n")); return false; } - if (!parseQuill(quill)) + if (!parseQuill(quill.get())) { MSPUB_DEBUG_MSG(("Couldn't parse quill stream.\n")); - delete quill; return false; } return m_collector->go(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits