summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-09-25 13:23:48 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-09-26 08:58:42 +0200
commit6cc5c6dea2b03a14e051728aa513fb206929ea86 (patch)
tree1f7f38dbc0ffdf59addbbac239f16bd125bfad36 /svgio
parent0699a18c622149ac6dbc898bf920c47c45ccd5b9 (diff)
loplugin:useuniqueptr in SvgDocument
Change-Id: I299e97c276b60be86491bfeee22d46774739ca44 Reviewed-on: https://gerrit.libreoffice.org/60969 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svgio')
-rw-r--r--svgio/inc/svgdocument.hxx6
-rw-r--r--svgio/inc/svgnode.hxx2
-rw-r--r--svgio/source/svgreader/svgdocument.cxx12
-rw-r--r--svgio/source/svgreader/svgdocumenthandler.cxx5
-rw-r--r--svgio/source/svguno/xsvgparser.cxx7
5 files changed, 12 insertions, 20 deletions
diff --git a/svgio/inc/svgdocument.hxx b/svgio/inc/svgdocument.hxx
index de7fbc304c88..e414b19390db 100644
--- a/svgio/inc/svgdocument.hxx
+++ b/svgio/inc/svgdocument.hxx
@@ -21,12 +21,16 @@
#define INCLUDED_SVGIO_INC_SVGDOCUMENT_HXX
#include "svgnode.hxx"
+#include <memory>
#include <unordered_map>
+#include <vector>
namespace svgio
{
namespace svgreader
{
+ typedef std::vector< std::unique_ptr<SvgNode> > SvgNodeVector;
+
class SvgDocument
{
private:
@@ -52,7 +56,7 @@ namespace svgio
SvgDocument& operator=(const SvgDocument&) = delete;
/// append another root node, ownership changes
- void appendNode(SvgNode* pNode);
+ void appendNode(std::unique_ptr<SvgNode> pNode);
/// add/remove nodes with Id to mapper
void addSvgNodeToMapper(const OUString& rStr, const SvgNode& rNode);
diff --git a/svgio/inc/svgnode.hxx b/svgio/inc/svgnode.hxx
index 2db5d490fa14..1f08f5fa5acf 100644
--- a/svgio/inc/svgnode.hxx
+++ b/svgio/inc/svgnode.hxx
@@ -45,8 +45,6 @@ namespace svgio
{
namespace svgreader
{
- typedef ::std::vector< SvgNode* > SvgNodeVector;
-
enum XmlSpace
{
XmlSpace_notset,
diff --git a/svgio/source/svgreader/svgdocument.cxx b/svgio/source/svgreader/svgdocument.cxx
index 44fb0d507eec..716db822a83c 100644
--- a/svgio/source/svgreader/svgdocument.cxx
+++ b/svgio/source/svgreader/svgdocument.cxx
@@ -33,18 +33,12 @@ namespace svgio
SvgDocument::~SvgDocument()
{
- while(!maNodes.empty())
- {
- SvgNode* pCandidate = maNodes[maNodes.size() - 1];
- delete pCandidate;
- maNodes.pop_back();
- }
}
- void SvgDocument::appendNode(SvgNode* pNode)
+ void SvgDocument::appendNode(std::unique_ptr<SvgNode> pNode)
{
- OSL_ENSURE(pNode, "OOps, empty node added (!)");
- maNodes.push_back(pNode);
+ assert(pNode);
+ maNodes.push_back(std::move(pNode));
}
void SvgDocument::addSvgNodeToMapper(const OUString& rStr, const SvgNode& rNode)
diff --git a/svgio/source/svgreader/svgdocumenthandler.cxx b/svgio/source/svgreader/svgdocumenthandler.cxx
index d8a36c99c073..447221b55215 100644
--- a/svgio/source/svgreader/svgdocumenthandler.cxx
+++ b/svgio/source/svgreader/svgdocumenthandler.cxx
@@ -153,7 +153,8 @@ namespace svgio
mpTarget = const_cast< SvgNode* >(mpTarget->getParent());
const SvgNodeVector& rOwnedTopLevels = maDocument.getSvgNodeVector();
- if (std::find(rOwnedTopLevels.begin(), rOwnedTopLevels.end(), mpTarget) == rOwnedTopLevels.end())
+ if (std::none_of(rOwnedTopLevels.begin(), rOwnedTopLevels.end(),
+ [&](std::unique_ptr<SvgNode> const & p) { return p.get() == mpTarget; }))
delete mpTarget;
}
OSL_ENSURE(!maCssContents.size(), "SvgDocHdl destructed with active css style stack entry (!)");
@@ -487,7 +488,7 @@ namespace svgio
if(!mpTarget->getParent())
{
// last element closing, save this tree
- maDocument.appendNode(mpTarget);
+ maDocument.appendNode(std::unique_ptr<SvgNode>(mpTarget));
}
mpTarget = const_cast< SvgNode* >(mpTarget->getParent());
diff --git a/svgio/source/svguno/xsvgparser.cxx b/svgio/source/svguno/xsvgparser.cxx
index 46ada4858a42..2f2a51c5c318 100644
--- a/svgio/source/svguno/xsvgparser.cxx
+++ b/svgio/source/svguno/xsvgparser.cxx
@@ -143,13 +143,8 @@ namespace svgio
}
// decompose to primitives
- const SvgNodeVector& rResults = pSvgDocHdl->getSvgDocument().getSvgNodeVector();
- const sal_uInt32 nCount(rResults.size());
-
- for(sal_uInt32 a(0); a < nCount; a++)
+ for(std::unique_ptr<SvgNode> const & pCandidate : pSvgDocHdl->getSvgDocument().getSvgNodeVector())
{
- SvgNode* pCandidate = rResults[a];
-
if(Display_none != pCandidate->getDisplay())
{
pCandidate->decomposeSvgNode(aRetval, false);