summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2017-04-23 19:14:45 +0200
committerDavid Tardon <dtardon@redhat.com>2017-04-23 19:14:45 +0200
commitbbe7f806b95ef427153ba18bff80e674b1704ae5 (patch)
tree78e6c4925dbcfcec444f06398a030499f9952dc9
parent8ff2475100ad7f46835fadc04941902c7d9027a8 (diff)
replace dumb pointers by smart ones
Change-Id: I9e70f71e67aff4d8ee5ffa1f2024d20686fea222
-rw-r--r--configure.ac1
-rw-r--r--src/lib/MSPUBCollector.cpp24
-rw-r--r--src/lib/MSPUBCollector.h11
-rw-r--r--src/lib/ShapeGroupElement.cpp8
-rw-r--r--src/lib/ShapeGroupElement.h5
5 files changed, 21 insertions, 28 deletions
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