From 3b8cd4f95d214e79ffc7e69af094ed0df1cc4788 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 28 Feb 2018 10:03:07 +0200 Subject: loplugin:useuniqueptr in SvgNode Change-Id: I7ab382bd90050302c24464eed645d20a435dbd63 Reviewed-on: https://gerrit.libreoffice.org/50657 Tested-by: Jenkins Reviewed-by: Noel Grandin --- svgio/inc/svgnode.hxx | 6 +++--- svgio/source/svgreader/svgdocumenthandler.cxx | 8 ++++---- svgio/source/svgreader/svggradientnode.cxx | 2 +- svgio/source/svgreader/svgnode.cxx | 19 ++++++------------- svgio/source/svgreader/svgtextnode.cxx | 8 ++++---- 5 files changed, 18 insertions(+), 25 deletions(-) (limited to 'svgio') diff --git a/svgio/inc/svgnode.hxx b/svgio/inc/svgnode.hxx index fd4e45c5ccc4..7fd8129a48b8 100644 --- a/svgio/inc/svgnode.hxx +++ b/svgio/inc/svgnode.hxx @@ -91,7 +91,7 @@ namespace svgio const SvgNode* mpAlternativeParent; /// sub hierarchy - SvgNodeVector maChildren; + std::vector< std::unique_ptr > maChildren; /// Id svan value std::unique_ptr mpId; @@ -111,7 +111,7 @@ namespace svgio ::std::vector< const SvgStyleAttributes* > maCssStyleVector; /// possible local CssStyle, e.g. style="fill:red; stroke:red;" - SvgStyleAttributes* mpLocalCssStyle; + std::unique_ptr mpLocalCssStyle; // flag if maCssStyleVector is already computed (done only once) bool mbCssStyleVectorBuilt : 1; @@ -152,7 +152,7 @@ namespace svgio SVGToken getType() const { return maType; } const SvgDocument& getDocument() const { return mrDocument; } const SvgNode* getParent() const { if(mpAlternativeParent) return mpAlternativeParent; return mpParent; } - const SvgNodeVector& getChildren() const { return maChildren; } + const std::vector< std::unique_ptr > & getChildren() const { return maChildren; } /// InfoProvider support for %, em and ex values virtual const basegfx::B2DRange getCurrentViewPort() const override; diff --git a/svgio/source/svgreader/svgdocumenthandler.cxx b/svgio/source/svgreader/svgdocumenthandler.cxx index 8288a40be6ce..87dc67e00273 100644 --- a/svgio/source/svgreader/svgdocumenthandler.cxx +++ b/svgio/source/svgreader/svgdocumenthandler.cxx @@ -54,12 +54,12 @@ namespace { if(pNode) { - const svgio::svgreader::SvgNodeVector& rChilds = pNode->getChildren(); + const auto& rChilds = pNode->getChildren(); const sal_uInt32 nCount(rChilds.size()); for(sal_uInt32 a(0); a < nCount; a++) { - svgio::svgreader::SvgNode* pCandidate = rChilds[a]; + svgio::svgreader::SvgNode* pCandidate = rChilds[a].get(); if(pCandidate) { @@ -564,12 +564,12 @@ namespace svgio case SVGTokenTspan: case SVGTokenTextPath: { - const SvgNodeVector& rChilds = mpTarget->getChildren(); + const auto& rChilds = mpTarget->getChildren(); SvgCharacterNode* pTarget = nullptr; if(rChilds.size()) { - pTarget = dynamic_cast< SvgCharacterNode* >(rChilds[rChilds.size() - 1]); + pTarget = dynamic_cast< SvgCharacterNode* >(rChilds[rChilds.size() - 1].get()); } if(pTarget) diff --git a/svgio/source/svgreader/svggradientnode.cxx b/svgio/source/svgreader/svggradientnode.cxx index 81617c8814dc..4496a809a8cf 100644 --- a/svgio/source/svgreader/svggradientnode.cxx +++ b/svgio/source/svgreader/svggradientnode.cxx @@ -257,7 +257,7 @@ namespace svgio for(sal_uInt32 a(0); a < nCount; a++) { - const SvgGradientStopNode* pCandidate = dynamic_cast< const SvgGradientStopNode* >(getChildren()[a]); + const SvgGradientStopNode* pCandidate = dynamic_cast< const SvgGradientStopNode* >(getChildren()[a].get()); if(pCandidate) { diff --git a/svgio/source/svgreader/svgnode.cxx b/svgio/source/svgreader/svgnode.cxx index f953ec5667c0..9f3687e67a25 100644 --- a/svgio/source/svgreader/svgnode.cxx +++ b/svgio/source/svgreader/svgnode.cxx @@ -185,7 +185,7 @@ namespace svgio if(mpLocalCssStyle) { // if we have one, use as first entry - maCssStyleVector.push_back(mpLocalCssStyle); + maCssStyleVector.push_back(mpLocalCssStyle.get()); } // check the hierarchy for concatenated patterns of Selectors @@ -275,7 +275,7 @@ namespace svgio if(pParent) { - pParent->maChildren.push_back(this); + pParent->maChildren.emplace_back(this); } else { @@ -290,13 +290,6 @@ namespace svgio SvgNode::~SvgNode() { - while(maChildren.size()) - { - delete maChildren[maChildren.size() - 1]; - maChildren.pop_back(); - } - - delete mpLocalCssStyle; } void SvgNode::readLocalCssStyle(const OUString& aContent) @@ -304,7 +297,7 @@ namespace svgio if(!mpLocalCssStyle) { // create LocalCssStyle if needed but not yet added - mpLocalCssStyle = new SvgStyleAttributes(*this); + mpLocalCssStyle.reset(new SvgStyleAttributes(*this)); } else { @@ -504,7 +497,7 @@ namespace svgio } } - const SvgNodeVector& rChildren = getChildren(); + const auto& rChildren = getChildren(); if(!rChildren.empty()) { @@ -512,11 +505,11 @@ namespace svgio for(sal_uInt32 a(0); a < nCount; a++) { - SvgNode* pCandidate = rChildren[a]; + SvgNode* pCandidate = rChildren[a].get(); if(pCandidate && Display_none != pCandidate->getDisplay()) { - const SvgNodeVector& rGrandChildren = pCandidate->getChildren(); + const auto& rGrandChildren = pCandidate->getChildren(); const SvgStyleAttributes* pChildStyles = pCandidate->getSvgStyleAttributes(); // decompose: // - visible terminal nodes diff --git a/svgio/source/svgreader/svgtextnode.cxx b/svgio/source/svgreader/svgtextnode.cxx index 0760f2c184b5..3cb5ea9fce38 100644 --- a/svgio/source/svgreader/svgtextnode.cxx +++ b/svgio/source/svgreader/svgtextnode.cxx @@ -123,7 +123,7 @@ namespace svgio { // direct TextPath decompose const SvgTextPathNode& rSvgTextPathNode = static_cast< const SvgTextPathNode& >(rCandidate); - const SvgNodeVector& rChildren = rSvgTextPathNode.getChildren(); + const auto& rChildren = rSvgTextPathNode.getChildren(); const sal_uInt32 nCount(rChildren.size()); if(nCount && rSvgTextPathNode.isValid()) @@ -159,7 +159,7 @@ namespace svgio { // Tspan may have children, call recursively const SvgTspanNode& rSvgTspanNode = static_cast< const SvgTspanNode& >(rCandidate); - const SvgNodeVector& rChildren = rSvgTspanNode.getChildren(); + const auto& rChildren = rSvgTspanNode.getChildren(); const sal_uInt32 nCount(rChildren.size()); if(nCount) @@ -188,7 +188,7 @@ namespace svgio if(pRefText) { - const SvgNodeVector& rChildren = pRefText->getChildren(); + const auto& rChildren = pRefText->getChildren(); const sal_uInt32 nCount(rChildren.size()); drawinglayer::primitive2d::Primitive2DContainer aNewTarget; @@ -234,7 +234,7 @@ namespace svgio { SvgTextPosition aSvgTextPosition(nullptr, *this, maSvgTextPositions); drawinglayer::primitive2d::Primitive2DContainer aNewTarget; - const SvgNodeVector& rChildren = getChildren(); + const auto& rChildren = getChildren(); const sal_uInt32 nCount(rChildren.size()); for(sal_uInt32 a(0); a < nCount; a++) -- cgit