[Libreoffice-commits] libvisio.git: 8 commits - src/lib
David Tardon
dtardon at redhat.com
Sun Mar 25 12:26:23 UTC 2018
src/lib/VSDCharacterList.cpp | 29 +++-----
src/lib/VSDCharacterList.h | 3
src/lib/VSDContentCollector.cpp | 3
src/lib/VSDFieldList.cpp | 31 +++------
src/lib/VSDFieldList.h | 3
src/lib/VSDGeometryList.cpp | 131 ++++++++++++++-------------------------
src/lib/VSDGeometryList.h | 5 -
src/lib/VSDOutputElementList.cpp | 19 -----
src/lib/VSDParagraphList.cpp | 11 ++-
src/lib/libvisio_utils.h | 12 +++
10 files changed, 101 insertions(+), 146 deletions(-)
New commits:
commit 40c8a1d8216bebfccfcea5ec55af2848f3a72170
Author: David Tardon <dtardon at redhat.com>
Date: Sun Mar 25 14:25:47 2018 +0200
guard against self-assignment
Change-Id: I2eff7abe7d341455c111291ecf81ff348846bc11
diff --git a/src/lib/VSDCharacterList.cpp b/src/lib/VSDCharacterList.cpp
index 65de7af..6f9fe8e 100644
--- a/src/lib/VSDCharacterList.cpp
+++ b/src/lib/VSDCharacterList.cpp
@@ -88,10 +88,13 @@ libvisio::VSDCharacterList::VSDCharacterList(const libvisio::VSDCharacterList &c
libvisio::VSDCharacterList &libvisio::VSDCharacterList::operator=(const libvisio::VSDCharacterList &charList)
{
- clear();
- for (auto iter = charList.m_elements.begin(); iter != charList.m_elements.end(); ++iter)
- m_elements[iter->first] = clone(iter->second);
- m_elementsOrder = charList.m_elementsOrder;
+ if (this != &charList)
+ {
+ clear();
+ for (auto iter = charList.m_elements.begin(); iter != charList.m_elements.end(); ++iter)
+ m_elements[iter->first] = clone(iter->second);
+ m_elementsOrder = charList.m_elementsOrder;
+ }
return *this;
}
diff --git a/src/lib/VSDGeometryList.cpp b/src/lib/VSDGeometryList.cpp
index ac1b616..92746d8 100644
--- a/src/lib/VSDGeometryList.cpp
+++ b/src/lib/VSDGeometryList.cpp
@@ -579,10 +579,13 @@ libvisio::VSDGeometryList::VSDGeometryList(const VSDGeometryList &geomList) :
libvisio::VSDGeometryList &libvisio::VSDGeometryList::operator=(const VSDGeometryList &geomList)
{
- clear();
- for (auto iter = geomList.m_elements.begin(); iter != geomList.m_elements.end(); ++iter)
- m_elements[iter->first] = clone(iter->second);
- m_elementsOrder = geomList.m_elementsOrder;
+ if (this != &geomList)
+ {
+ clear();
+ for (auto iter = geomList.m_elements.begin(); iter != geomList.m_elements.end(); ++iter)
+ m_elements[iter->first] = clone(iter->second);
+ m_elementsOrder = geomList.m_elementsOrder;
+ }
return *this;
}
diff --git a/src/lib/VSDParagraphList.cpp b/src/lib/VSDParagraphList.cpp
index f279bb8..c1863a1 100644
--- a/src/lib/VSDParagraphList.cpp
+++ b/src/lib/VSDParagraphList.cpp
@@ -89,10 +89,13 @@ libvisio::VSDParagraphList::VSDParagraphList(const libvisio::VSDParagraphList &p
libvisio::VSDParagraphList &libvisio::VSDParagraphList::operator=(const libvisio::VSDParagraphList ¶List)
{
- clear();
- for (auto iter = paraList.m_elements.begin(); iter != paraList.m_elements.end(); ++iter)
- m_elements[iter->first] = iter->second->clone();
- m_elementsOrder = paraList.m_elementsOrder;
+ if (this != ¶List)
+ {
+ clear();
+ for (auto iter = paraList.m_elements.begin(); iter != paraList.m_elements.end(); ++iter)
+ m_elements[iter->first] = iter->second->clone();
+ m_elementsOrder = paraList.m_elementsOrder;
+ }
return *this;
}
commit 467618a5b883c7303fc6ef8e10756e203ceaed11
Author: David Tardon <dtardon at redhat.com>
Date: Sun Mar 25 14:23:08 2018 +0200
avoid manual memory mgmt
Change-Id: I4694b93a135dc568beb234a6300a492326122257
diff --git a/src/lib/VSDCharacterList.cpp b/src/lib/VSDCharacterList.cpp
index ae702ef..65de7af 100644
--- a/src/lib/VSDCharacterList.cpp
+++ b/src/lib/VSDCharacterList.cpp
@@ -83,14 +83,14 @@ libvisio::VSDCharacterList::VSDCharacterList(const libvisio::VSDCharacterList &c
m_elementsOrder(charList.m_elementsOrder)
{
for (auto iter = charList.m_elements.begin(); iter != charList.m_elements.end(); ++iter)
- m_elements[iter->first] = iter->second->clone();
+ m_elements[iter->first] = clone(iter->second);
}
libvisio::VSDCharacterList &libvisio::VSDCharacterList::operator=(const libvisio::VSDCharacterList &charList)
{
clear();
for (auto iter = charList.m_elements.begin(); iter != charList.m_elements.end(); ++iter)
- m_elements[iter->first] = iter->second->clone();
+ m_elements[iter->first] = clone(iter->second);
m_elementsOrder = charList.m_elementsOrder;
return *this;
}
@@ -107,14 +107,11 @@ void libvisio::VSDCharacterList::addCharIX(unsigned id, unsigned level, unsigned
const boost::optional<bool> &allcaps, const boost::optional<bool> &initcaps, const boost::optional<bool> &smallcaps,
const boost::optional<bool> &superscript, const boost::optional<bool> &subscript, const boost::optional<double> &scaleWidth)
{
- auto *tmpElement = dynamic_cast<VSDCharIX *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDCharIX *>(m_elements[id].get());
if (!tmpElement)
{
- if (m_elements[id])
- delete m_elements[id];
-
- m_elements[id] = new VSDCharIX(id, level, charCount, font, fontColour, fontSize, bold, italic, underline, doubleunderline,
- strikeout, doublestrikeout, allcaps, initcaps, smallcaps, superscript, subscript, scaleWidth);
+ m_elements[id] = make_unique<VSDCharIX>(id, level, charCount, font, fontColour, fontSize, bold, italic, underline, doubleunderline,
+ strikeout, doublestrikeout, allcaps, initcaps, smallcaps, superscript, subscript, scaleWidth);
}
else
tmpElement->m_style.override(VSDOptionalCharStyle(charCount, font, fontColour, fontSize, bold, italic, underline,
@@ -168,19 +165,18 @@ void libvisio::VSDCharacterList::handle(VSDCollector *collector) const
{
if (empty())
return;
- std::map<unsigned, VSDCharacterListElement *>::const_iterator iter;
if (!m_elementsOrder.empty())
{
for (unsigned i = 0; i < m_elementsOrder.size(); i++)
{
- iter = m_elements.find(m_elementsOrder[i]);
+ auto iter = m_elements.find(m_elementsOrder[i]);
if (iter != m_elements.end() && (0 == i || iter->second->getCharCount()))
iter->second->handle(collector);
}
}
else
{
- for (iter = m_elements.begin(); iter != m_elements.end(); ++iter)
+ for (auto iter = m_elements.begin(); iter != m_elements.end(); ++iter)
if (m_elements.begin() == iter || iter->second->getCharCount())
iter->second->handle(collector);
}
@@ -188,8 +184,6 @@ void libvisio::VSDCharacterList::handle(VSDCollector *collector) const
void libvisio::VSDCharacterList::clear()
{
- for (auto &element : m_elements)
- delete element.second;
m_elements.clear();
m_elementsOrder.clear();
}
diff --git a/src/lib/VSDCharacterList.h b/src/lib/VSDCharacterList.h
index 5211384..555b9d6 100644
--- a/src/lib/VSDCharacterList.h
+++ b/src/lib/VSDCharacterList.h
@@ -10,6 +10,7 @@
#ifndef __VSDCHARACTERLIST_H__
#define __VSDCHARACTERLIST_H__
+#include <memory>
#include <vector>
#include <map>
#include "VSDTypes.h"
@@ -48,7 +49,7 @@ public:
return (m_elements.empty());
}
private:
- std::map<unsigned, VSDCharacterListElement *> m_elements;
+ std::map<unsigned, std::unique_ptr<VSDCharacterListElement>> m_elements;
std::vector<unsigned> m_elementsOrder;
};
commit 8dfa37807ee1d40f98729a911db3a52df0d2e65b
Author: David Tardon <dtardon at redhat.com>
Date: Sun Mar 25 14:18:41 2018 +0200
use make_unique
Change-Id: I74fb98a89eea16a230319d024017c37febf908f9
diff --git a/src/lib/VSDFieldList.cpp b/src/lib/VSDFieldList.cpp
index 3b8d60d..363d20e 100644
--- a/src/lib/VSDFieldList.cpp
+++ b/src/lib/VSDFieldList.cpp
@@ -10,6 +10,7 @@
#include <time.h>
#include "VSDCollector.h"
#include "VSDFieldList.h"
+#include "libvisio_utils.h"
void libvisio::VSDTextField::handle(VSDCollector *collector) const
{
@@ -171,7 +172,7 @@ libvisio::VSDFieldList::VSDFieldList(const libvisio::VSDFieldList &fieldList) :
m_level(fieldList.m_level)
{
for (auto iter = fieldList.m_elements.begin(); iter != fieldList.m_elements.end(); ++iter)
- m_elements[iter->first].reset(iter->second->clone());
+ m_elements[iter->first] = clone(iter->second);
}
libvisio::VSDFieldList &libvisio::VSDFieldList::operator=(const libvisio::VSDFieldList &fieldList)
@@ -180,7 +181,7 @@ libvisio::VSDFieldList &libvisio::VSDFieldList::operator=(const libvisio::VSDFie
{
clear();
for (auto iter = fieldList.m_elements.begin(); iter != fieldList.m_elements.end(); ++iter)
- m_elements[iter->first].reset(iter->second->clone());
+ m_elements[iter->first] = clone(iter->second);
m_elementsOrder = fieldList.m_elementsOrder;
m_id = fieldList.m_id;
m_level = fieldList.m_level;
@@ -208,13 +209,13 @@ void libvisio::VSDFieldList::addFieldList(unsigned id, unsigned level)
void libvisio::VSDFieldList::addTextField(unsigned id, unsigned level, int nameId, int formatStringId)
{
if (m_elements.find(id) == m_elements.end())
- m_elements[id].reset(new VSDTextField(id, level, nameId, formatStringId));
+ m_elements[id] = make_unique<VSDTextField>(id, level, nameId, formatStringId);
}
void libvisio::VSDFieldList::addNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId)
{
if (m_elements.find(id) == m_elements.end())
- m_elements[id].reset(new VSDNumericField(id, level, format, number, formatStringId));
+ m_elements[id] = make_unique<VSDNumericField>(id, level, format, number, formatStringId);
}
void libvisio::VSDFieldList::handle(VSDCollector *collector) const
commit 64c199140f8c5e3ebd6af9a9204a7f84b4746af1
Author: David Tardon <dtardon at redhat.com>
Date: Sun Mar 25 14:15:46 2018 +0200
avoid manual memory mgmt
Change-Id: I34c48bf74b8b1c0fdb5018b7d8fedba1b196beee
diff --git a/src/lib/VSDGeometryList.cpp b/src/lib/VSDGeometryList.cpp
index 49b2a70..ac1b616 100644
--- a/src/lib/VSDGeometryList.cpp
+++ b/src/lib/VSDGeometryList.cpp
@@ -574,31 +574,29 @@ libvisio::VSDGeometryList::VSDGeometryList(const VSDGeometryList &geomList) :
m_elementsOrder(geomList.m_elementsOrder)
{
for (auto iter = geomList.m_elements.begin(); iter != geomList.m_elements.end(); ++iter)
- m_elements[iter->first] = iter->second->clone();
+ m_elements[iter->first] = clone(iter->second);
}
libvisio::VSDGeometryList &libvisio::VSDGeometryList::operator=(const VSDGeometryList &geomList)
{
clear();
for (auto iter = geomList.m_elements.begin(); iter != geomList.m_elements.end(); ++iter)
- m_elements[iter->first] = iter->second->clone();
+ m_elements[iter->first] = clone(iter->second);
m_elementsOrder = geomList.m_elementsOrder;
return *this;
}
libvisio::VSDGeometryList::~VSDGeometryList()
{
- clear();
}
void libvisio::VSDGeometryList::addGeometry(unsigned id, unsigned level, const boost::optional<bool> &noFill,
const boost::optional<bool> &noLine, const boost::optional<bool> &noShow)
{
- auto *tmpElement = dynamic_cast<VSDGeometry *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDGeometry *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDGeometry(id, level, noFill, noLine, noShow);
+ m_elements[id] = make_unique<VSDGeometry>(id, level, noFill, noLine, noShow);
}
else
{
@@ -610,18 +608,16 @@ void libvisio::VSDGeometryList::addGeometry(unsigned id, unsigned level, const b
void libvisio::VSDGeometryList::addEmpty(unsigned id, unsigned level)
{
- clearElement(id);
- m_elements[id] = new VSDEmpty(id, level);
+ m_elements[id] = make_unique<VSDEmpty>(id, level);
}
void libvisio::VSDGeometryList::addMoveTo(unsigned id, unsigned level, const boost::optional<double> &x,
const boost::optional<double> &y)
{
- auto *tmpElement = dynamic_cast<VSDMoveTo *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDMoveTo *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDMoveTo(id, level, x, y);
+ m_elements[id] = make_unique<VSDMoveTo>(id, level, x, y);
}
else
{
@@ -632,11 +628,10 @@ void libvisio::VSDGeometryList::addMoveTo(unsigned id, unsigned level, const boo
void libvisio::VSDGeometryList::addLineTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y)
{
- auto *tmpElement = dynamic_cast<VSDLineTo *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDLineTo *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDLineTo(id, level, x, y);
+ m_elements[id] = make_unique<VSDLineTo>(id, level, x, y);
}
else
{
@@ -648,11 +643,10 @@ void libvisio::VSDGeometryList::addLineTo(unsigned id, unsigned level, const boo
void libvisio::VSDGeometryList::addArcTo(unsigned id, unsigned level, const boost::optional<double> &x2,
const boost::optional<double> &y2, const boost::optional<double> &bow)
{
- auto *tmpElement = dynamic_cast<VSDArcTo *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDArcTo *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDArcTo(id, level, x2, y2, bow);
+ m_elements[id] = make_unique<VSDArcTo>(id, level, x2, y2, bow);
}
else
{
@@ -665,25 +659,22 @@ void libvisio::VSDGeometryList::addArcTo(unsigned id, unsigned level, const boos
void libvisio::VSDGeometryList::addNURBSTo(unsigned id, unsigned level, double x2, double y2, unsigned char xType, unsigned char yType, unsigned degree,
const std::vector<std::pair<double, double> > &controlPoints, const std::vector<double> &knotVector, const std::vector<double> &weights)
{
- clearElement(id);
- m_elements[id] = new VSDNURBSTo1(id, level, x2, y2, xType, yType, degree, controlPoints, knotVector, weights);
+ m_elements[id] = libvisio::make_unique<VSDNURBSTo1>(id, level, x2, y2, xType, yType, degree, controlPoints, knotVector, weights);
}
void libvisio::VSDGeometryList::addNURBSTo(unsigned id, unsigned level, double x2, double y2, double knot, double knotPrev, double weight, double weightPrev, unsigned dataID)
{
- clearElement(id);
- m_elements[id] = new VSDNURBSTo2(id, level, x2, y2, knot, knotPrev, weight, weightPrev, dataID);
+ m_elements[id] = make_unique<VSDNURBSTo2>(id, level, x2, y2, knot, knotPrev, weight, weightPrev, dataID);
}
void libvisio::VSDGeometryList::addNURBSTo(unsigned id, unsigned level, const boost::optional<double> &x2, const boost::optional<double> &y2,
const boost::optional<double> &knot, const boost::optional<double> &knotPrev, const boost::optional<double> &weight,
const boost::optional<double> &weightPrev, const boost::optional<NURBSData> &data)
{
- auto *tmpElement = dynamic_cast<VSDNURBSTo3 *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDNURBSTo3 *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDNURBSTo3(id, level, x2, y2, knot, knotPrev, weight, weightPrev, data);
+ m_elements[id] = make_unique<VSDNURBSTo3>(id, level, x2, y2, knot, knotPrev, weight, weightPrev, data);
}
else
{
@@ -700,23 +691,20 @@ void libvisio::VSDGeometryList::addNURBSTo(unsigned id, unsigned level, const bo
void libvisio::VSDGeometryList::addPolylineTo(unsigned id, unsigned level, double x, double y, unsigned char xType, unsigned char yType,
const std::vector<std::pair<double, double> > &points)
{
- clearElement(id);
- m_elements[id] = new VSDPolylineTo1(id, level, x, y, xType, yType, points);
+ m_elements[id] = libvisio::make_unique<VSDPolylineTo1>(id, level, x, y, xType, yType, points);
}
void libvisio::VSDGeometryList::addPolylineTo(unsigned id, unsigned level, double x, double y, unsigned dataID)
{
- clearElement(id);
- m_elements[id] = new VSDPolylineTo2(id, level, x, y, dataID);
+ m_elements[id] = make_unique<VSDPolylineTo2>(id, level, x, y, dataID);
}
void libvisio::VSDGeometryList::addPolylineTo(unsigned id, unsigned level, boost::optional<double> &x, boost::optional<double> &y, boost::optional<PolylineData> &data)
{
- auto *tmpElement = dynamic_cast<VSDPolylineTo3 *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDPolylineTo3 *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDPolylineTo3(id, level, x, y, data);
+ m_elements[id] = make_unique<VSDPolylineTo3>(id, level, x, y, data);
}
else
{
@@ -730,11 +718,10 @@ void libvisio::VSDGeometryList::addEllipse(unsigned id, unsigned level, const bo
const boost::optional<double> &cy,const boost::optional<double> &xleft, const boost::optional<double> &yleft,
const boost::optional<double> &xtop, const boost::optional<double> &ytop)
{
- auto *tmpElement = dynamic_cast<VSDEllipse *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDEllipse *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDEllipse(id, level, cx, cy, xleft, yleft, xtop, ytop);
+ m_elements[id] = make_unique<VSDEllipse>(id, level, cx, cy, xleft, yleft, xtop, ytop);
}
else
{
@@ -751,11 +738,10 @@ void libvisio::VSDGeometryList::addEllipticalArcTo(unsigned id, unsigned level,
const boost::optional<double> &y3, const boost::optional<double> &x2, const boost::optional<double> &y2,
const boost::optional<double> &angle, const boost::optional<double> &ecc)
{
- auto *tmpElement = dynamic_cast<VSDEllipticalArcTo *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDEllipticalArcTo *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDEllipticalArcTo(id, level, x3, y3, x2, y2, angle, ecc);
+ m_elements[id] = make_unique<VSDEllipticalArcTo>(id, level, x3, y3, x2, y2, angle, ecc);
}
else
{
@@ -772,11 +758,10 @@ void libvisio::VSDGeometryList::addSplineStart(unsigned id, unsigned level, cons
const boost::optional<double> &y, const boost::optional<double> &secondKnot, const boost::optional<double> &firstKnot,
const boost::optional<double> &lastKnot, const boost::optional<unsigned> °ree)
{
- auto *tmpElement = dynamic_cast<VSDSplineStart *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDSplineStart *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDSplineStart(id, level, x, y, secondKnot, firstKnot, lastKnot, degree);
+ m_elements[id] = make_unique<VSDSplineStart>(id, level, x, y, secondKnot, firstKnot, lastKnot, degree);
}
else
{
@@ -792,11 +777,10 @@ void libvisio::VSDGeometryList::addSplineStart(unsigned id, unsigned level, cons
void libvisio::VSDGeometryList::addSplineKnot(unsigned id, unsigned level, const boost::optional<double> &x,
const boost::optional<double> &y, const boost::optional<double> &knot)
{
- auto *tmpElement = dynamic_cast<VSDSplineKnot *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDSplineKnot *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDSplineKnot(id, level, x, y, knot);
+ m_elements[id] = make_unique<VSDSplineKnot>(id, level, x, y, knot);
}
else
{
@@ -809,11 +793,10 @@ void libvisio::VSDGeometryList::addSplineKnot(unsigned id, unsigned level, const
void libvisio::VSDGeometryList::addInfiniteLine(unsigned id, unsigned level, const boost::optional<double> &x1,
const boost::optional<double> &y1, const boost::optional<double> &x2, const boost::optional<double> &y2)
{
- auto *tmpElement = dynamic_cast<VSDInfiniteLine *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDInfiniteLine *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDInfiniteLine(id, level, x1, y1, x2, y2);
+ m_elements[id] = make_unique<VSDInfiniteLine>(id, level, x1, y1, x2, y2);
}
else
{
@@ -828,11 +811,10 @@ void libvisio::VSDGeometryList::addRelCubBezTo(unsigned id, unsigned level, cons
const boost::optional<double> &y, const boost::optional<double> &a, const boost::optional<double> &b,
const boost::optional<double> &c, const boost::optional<double> &d)
{
- auto *tmpElement = dynamic_cast<VSDRelCubBezTo *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDRelCubBezTo *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDRelCubBezTo(id, level, x, y, a, b, c, d);
+ m_elements[id] = make_unique<VSDRelCubBezTo>(id, level, x, y, a, b, c, d);
}
else
{
@@ -849,11 +831,10 @@ void libvisio::VSDGeometryList::addRelEllipticalArcTo(unsigned id, unsigned leve
const boost::optional<double> &y3, const boost::optional<double> &x2, const boost::optional<double> &y2,
const boost::optional<double> &angle, const boost::optional<double> &ecc)
{
- auto *tmpElement = dynamic_cast<VSDRelEllipticalArcTo *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDRelEllipticalArcTo *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDRelEllipticalArcTo(id, level, x3, y3, x2, y2, angle, ecc);
+ m_elements[id] = make_unique<VSDRelEllipticalArcTo>(id, level, x3, y3, x2, y2, angle, ecc);
}
else
{
@@ -868,11 +849,10 @@ void libvisio::VSDGeometryList::addRelEllipticalArcTo(unsigned id, unsigned leve
void libvisio::VSDGeometryList::addRelMoveTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y)
{
- auto *tmpElement = dynamic_cast<VSDRelMoveTo *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDRelMoveTo *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDRelMoveTo(id, level, x, y);
+ m_elements[id] = make_unique<VSDRelMoveTo>(id, level, x, y);
}
else
{
@@ -883,11 +863,10 @@ void libvisio::VSDGeometryList::addRelMoveTo(unsigned id, unsigned level, const
void libvisio::VSDGeometryList::addRelLineTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y)
{
- auto *tmpElement = dynamic_cast<VSDRelLineTo *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDRelLineTo *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDRelLineTo(id, level, x, y);
+ m_elements[id] = make_unique<VSDRelLineTo>(id, level, x, y);
}
else
{
@@ -898,11 +877,10 @@ void libvisio::VSDGeometryList::addRelLineTo(unsigned id, unsigned level, const
void libvisio::VSDGeometryList::addRelQuadBezTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y, const boost::optional<double> &a, const boost::optional<double> &b)
{
- auto *tmpElement = dynamic_cast<VSDRelQuadBezTo *>(m_elements[id]);
+ auto *tmpElement = dynamic_cast<VSDRelQuadBezTo *>(m_elements[id].get());
if (!tmpElement)
{
- clearElement(id);
- m_elements[id] = new VSDRelQuadBezTo(id, level, x, y, a, b);
+ m_elements[id] = make_unique<VSDRelQuadBezTo>(id, level, x, y, a, b);
}
else
{
@@ -924,12 +902,11 @@ void libvisio::VSDGeometryList::handle(VSDCollector *collector) const
{
if (empty())
return;
- std::map<unsigned, VSDGeometryListElement *>::const_iterator iter;
if (!m_elementsOrder.empty())
{
for (unsigned int i : m_elementsOrder)
{
- iter = m_elements.find(i);
+ auto iter = m_elements.find(i);
if (iter != m_elements.end())
iter->second->handle(collector);
}
@@ -938,13 +915,13 @@ void libvisio::VSDGeometryList::handle(VSDCollector *collector) const
{
std::vector<unsigned> tmpVector;
- for (iter = m_elements.begin(); iter != m_elements.end(); ++iter)
+ for (auto iter = m_elements.begin(); iter != m_elements.end(); ++iter)
tmpVector.push_back(iter->first);
std::sort(tmpVector.begin(), tmpVector.end());
for (unsigned int i : tmpVector)
{
- iter = m_elements.find(i);
+ auto iter = m_elements.find(i);
if (iter != m_elements.end())
iter->second->handle(collector);
}
@@ -954,8 +931,6 @@ void libvisio::VSDGeometryList::handle(VSDCollector *collector) const
void libvisio::VSDGeometryList::clear()
{
- for (auto &element : m_elements)
- delete element.second;
m_elements.clear();
m_elementsOrder.clear();
}
@@ -967,22 +942,11 @@ libvisio::VSDGeometryListElement *libvisio::VSDGeometryList::getElement(unsigned
auto iter = m_elements.find(index);
if (iter != m_elements.end())
- return iter->second;
+ return iter->second.get();
else
return nullptr;
}
-void libvisio::VSDGeometryList::clearElement(unsigned id)
-{
- auto iter = m_elements.find(id);
- if (m_elements.end() != iter)
- {
- if (iter->second)
- delete iter->second;
- m_elements.erase(iter);
- }
-}
-
void libvisio::VSDGeometryList::resetLevel(unsigned level)
{
for (auto &element : m_elements)
diff --git a/src/lib/VSDGeometryList.h b/src/lib/VSDGeometryList.h
index 78e32cc..d5012d9 100644
--- a/src/lib/VSDGeometryList.h
+++ b/src/lib/VSDGeometryList.h
@@ -11,6 +11,7 @@
#define __VSDGEOMETRYLIST_H__
#include <map>
+#include <memory>
#include <vector>
#include <functional>
#include <algorithm>
@@ -110,8 +111,7 @@ public:
}
void resetLevel(unsigned level);
private:
- void clearElement(unsigned id);
- std::map<unsigned, VSDGeometryListElement *> m_elements;
+ std::map<unsigned, std::unique_ptr<VSDGeometryListElement>> m_elements;
std::vector<unsigned> m_elementsOrder;
};
diff --git a/src/lib/VSDOutputElementList.cpp b/src/lib/VSDOutputElementList.cpp
index 8c4853f..639737a 100644
--- a/src/lib/VSDOutputElementList.cpp
+++ b/src/lib/VSDOutputElementList.cpp
@@ -9,6 +9,8 @@
#include "VSDOutputElementList.h"
+#include "libvisio_utils.h"
+
namespace libvisio
{
@@ -320,23 +322,6 @@ public:
} // namespace libvisio
-namespace
-{
-
-template<typename T, typename... Args>
-std::unique_ptr<T> make_unique(Args &&... args)
-{
- return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
-}
-
-template<typename T>
-std::unique_ptr<T> clone(const std::unique_ptr<T> &other)
-{
- return std::unique_ptr<T>(other->clone());
-}
-
-}
-
libvisio::VSDStyleOutputElement::VSDStyleOutputElement(const librevenge::RVNGPropertyList &propList) :
m_propList(propList) {}
diff --git a/src/lib/libvisio_utils.h b/src/lib/libvisio_utils.h
index 2fda000..7409e65 100644
--- a/src/lib/libvisio_utils.h
+++ b/src/lib/libvisio_utils.h
@@ -55,6 +55,18 @@ struct VSDDummyDeleter
void operator()(void *) {}
};
+template<typename T, typename... Args>
+std::unique_ptr<T> make_unique(Args &&... args)
+{
+ return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
+}
+
+template<typename T>
+std::unique_ptr<T> clone(const std::unique_ptr<T> &other)
+{
+ return std::unique_ptr<T>(other->clone());
+}
+
uint8_t readU8(librevenge::RVNGInputStream *input);
uint16_t readU16(librevenge::RVNGInputStream *input);
int16_t readS16(librevenge::RVNGInputStream *input);
commit d6867e9e9041fc02a8ec7ffe084a08a51e97166b
Author: David Tardon <dtardon at redhat.com>
Date: Sun Mar 25 14:04:09 2018 +0200
drop duplicate include
Change-Id: I22f98e6680d1ef8fd78ce41f54b39a8839518d74
diff --git a/src/lib/VSDGeometryList.h b/src/lib/VSDGeometryList.h
index b528715..78e32cc 100644
--- a/src/lib/VSDGeometryList.h
+++ b/src/lib/VSDGeometryList.h
@@ -10,7 +10,6 @@
#ifndef __VSDGEOMETRYLIST_H__
#define __VSDGEOMETRYLIST_H__
-#include <vector>
#include <map>
#include <vector>
#include <functional>
commit 3dbae3c48fc17232fc9815ec4f16ea1a01c97474
Author: David Tardon <dtardon at redhat.com>
Date: Sun Mar 25 14:00:10 2018 +0200
avoid manual memory mgmt
Change-Id: Ife502d6cd180e91c5b4f220cf2f008260143a35e
diff --git a/src/lib/VSDContentCollector.cpp b/src/lib/VSDContentCollector.cpp
index 25907eb..cde0ad0 100644
--- a/src/lib/VSDContentCollector.cpp
+++ b/src/lib/VSDContentCollector.cpp
@@ -3441,7 +3441,7 @@ void libvisio::VSDContentCollector::collectNumericField(unsigned id, unsigned le
VSDFieldListElement *pElement = m_stencilFields.getElement(m_fields.size());
if (pElement)
{
- VSDFieldListElement *element = pElement->clone();
+ std::unique_ptr<VSDFieldListElement> element{pElement->clone()};
if (element)
{
element->setValue(number);
@@ -3455,7 +3455,6 @@ void libvisio::VSDContentCollector::collectNumericField(unsigned id, unsigned le
element->setFormat(format);
m_fields.push_back(element->getString(m_names));
- delete element;
}
}
else
diff --git a/src/lib/VSDFieldList.cpp b/src/lib/VSDFieldList.cpp
index c1e31d4..3b8d60d 100644
--- a/src/lib/VSDFieldList.cpp
+++ b/src/lib/VSDFieldList.cpp
@@ -171,7 +171,7 @@ libvisio::VSDFieldList::VSDFieldList(const libvisio::VSDFieldList &fieldList) :
m_level(fieldList.m_level)
{
for (auto iter = fieldList.m_elements.begin(); iter != fieldList.m_elements.end(); ++iter)
- m_elements[iter->first] = iter->second->clone();
+ m_elements[iter->first].reset(iter->second->clone());
}
libvisio::VSDFieldList &libvisio::VSDFieldList::operator=(const libvisio::VSDFieldList &fieldList)
@@ -180,7 +180,7 @@ libvisio::VSDFieldList &libvisio::VSDFieldList::operator=(const libvisio::VSDFie
{
clear();
for (auto iter = fieldList.m_elements.begin(); iter != fieldList.m_elements.end(); ++iter)
- m_elements[iter->first] = iter->second->clone();
+ m_elements[iter->first].reset(iter->second->clone());
m_elementsOrder = fieldList.m_elementsOrder;
m_id = fieldList.m_id;
m_level = fieldList.m_level;
@@ -190,7 +190,6 @@ libvisio::VSDFieldList &libvisio::VSDFieldList::operator=(const libvisio::VSDFie
libvisio::VSDFieldList::~VSDFieldList()
{
- clear();
}
void libvisio::VSDFieldList::setElementsOrder(const std::vector<unsigned> &elementsOrder)
@@ -209,13 +208,13 @@ void libvisio::VSDFieldList::addFieldList(unsigned id, unsigned level)
void libvisio::VSDFieldList::addTextField(unsigned id, unsigned level, int nameId, int formatStringId)
{
if (m_elements.find(id) == m_elements.end())
- m_elements[id] = new VSDTextField(id, level, nameId, formatStringId);
+ m_elements[id].reset(new VSDTextField(id, level, nameId, formatStringId));
}
void libvisio::VSDFieldList::addNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId)
{
if (m_elements.find(id) == m_elements.end())
- m_elements[id] = new VSDNumericField(id, level, format, number, formatStringId);
+ m_elements[id].reset(new VSDNumericField(id, level, format, number, formatStringId));
}
void libvisio::VSDFieldList::handle(VSDCollector *collector) const
@@ -224,27 +223,24 @@ void libvisio::VSDFieldList::handle(VSDCollector *collector) const
return;
collector->collectFieldList(m_id, m_level);
- std::map<unsigned, VSDFieldListElement *>::const_iterator iter;
if (!m_elementsOrder.empty())
{
for (unsigned int i : m_elementsOrder)
{
- iter = m_elements.find(i);
+ auto iter = m_elements.find(i);
if (iter != m_elements.end())
iter->second->handle(collector);
}
}
else
{
- for (iter = m_elements.begin(); iter != m_elements.end(); ++iter)
+ for (auto iter = m_elements.begin(); iter != m_elements.end(); ++iter)
iter->second->handle(collector);
}
}
void libvisio::VSDFieldList::clear()
{
- for (auto &element : m_elements)
- delete element.second;
m_elements.clear();
m_elementsOrder.clear();
}
@@ -254,9 +250,9 @@ libvisio::VSDFieldListElement *libvisio::VSDFieldList::getElement(unsigned index
if (m_elementsOrder.size() > index)
index = m_elementsOrder[index];
- std::map<unsigned, VSDFieldListElement *>::const_iterator iter = m_elements.find(index);
+ auto iter = m_elements.find(index);
if (iter != m_elements.end())
- return iter->second;
+ return iter->second.get();
else
return nullptr;
}
diff --git a/src/lib/VSDFieldList.h b/src/lib/VSDFieldList.h
index f77463e..9d47bb3 100644
--- a/src/lib/VSDFieldList.h
+++ b/src/lib/VSDFieldList.h
@@ -10,6 +10,7 @@
#ifndef __VSDFIELDLIST_H__
#define __VSDFIELDLIST_H__
+#include <memory>
#include <vector>
#include <map>
#include <librevenge/librevenge.h>
@@ -102,7 +103,7 @@ public:
}
VSDFieldListElement *getElement(unsigned index);
private:
- std::map<unsigned, VSDFieldListElement *> m_elements;
+ std::map<unsigned, std::unique_ptr<VSDFieldListElement>> m_elements;
std::vector<unsigned> m_elementsOrder;
unsigned m_id, m_level;
};
commit a6990f6f931dbfd33b61be5ae7063b904680daa4
Author: David Tardon <dtardon at redhat.com>
Date: Sun Mar 25 13:49:18 2018 +0200
simplify a bit
Change-Id: I27ebb6af37ce169a657e7ed52a7bc77e323e1eb2
diff --git a/src/lib/VSDFieldList.cpp b/src/lib/VSDFieldList.cpp
index bbc6dfb..c1e31d4 100644
--- a/src/lib/VSDFieldList.cpp
+++ b/src/lib/VSDFieldList.cpp
@@ -140,11 +140,8 @@ librevenge::RVNGString libvisio::VSDNumericField::getString(const std::map<unsig
return datetimeToString("%x %X", m_number);
default:
{
- librevenge::RVNGString result;
std::unique_ptr<librevenge::RVNGProperty> pProp{librevenge::RVNGPropertyFactory::newDoubleProp(m_number)};
- if (pProp)
- result = pProp->getStr();
- return result;
+ return pProp ? pProp->getStr() : librevenge::RVNGString();
}
}
}
commit b6380006ba9395d30a2263a0a3467fc8bc9f52ba
Author: David Tardon <dtardon at redhat.com>
Date: Sun Mar 25 13:49:09 2018 +0200
use unique_ptr
Change-Id: I15a0ece5b4a71fa82f23bff85ad9e5011129edf6
diff --git a/src/lib/VSDFieldList.cpp b/src/lib/VSDFieldList.cpp
index 530bb20..bbc6dfb 100644
--- a/src/lib/VSDFieldList.cpp
+++ b/src/lib/VSDFieldList.cpp
@@ -141,12 +141,9 @@ librevenge::RVNGString libvisio::VSDNumericField::getString(const std::map<unsig
default:
{
librevenge::RVNGString result;
- librevenge::RVNGProperty *pProp = librevenge::RVNGPropertyFactory::newDoubleProp(m_number);
+ std::unique_ptr<librevenge::RVNGProperty> pProp{librevenge::RVNGPropertyFactory::newDoubleProp(m_number)};
if (pProp)
- {
result = pProp->getStr();
- delete pProp;
- }
return result;
}
}
More information about the Libreoffice-commits
mailing list