diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-05-02 10:16:19 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-05-03 14:24:53 +0200 |
commit | ab17afd9beeb2a2cef3e7b67a6acd2581d78b823 (patch) | |
tree | 7c64f2961f5126e9dce148bac5ae71ee708462f4 | |
parent | 12fe762438d761d8cf32f264a0e1c2d57b65aeb8 (diff) |
loplugin:useuniqueptr in SdrMarkList
Change-Id: I36e7af3b1b74a78103c079da58ae1a820b164720
Reviewed-on: https://gerrit.libreoffice.org/53753
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/svx/svdmark.hxx | 3 | ||||
-rw-r--r-- | svx/source/svdraw/svdmark.cxx | 45 |
2 files changed, 17 insertions, 31 deletions
diff --git a/include/svx/svdmark.hxx b/include/svx/svdmark.hxx index 071f1ce568cb..4b901f6ab2ad 100644 --- a/include/svx/svdmark.hxx +++ b/include/svx/svdmark.hxx @@ -25,6 +25,7 @@ #include <svx/sdrobjectuser.hxx> #include <tools/solar.h> +#include <memory> #include <set> #include <vector> @@ -134,7 +135,7 @@ public: class SVX_DLLPUBLIC SdrMarkList final { - std::vector<SdrMark*> maList; + std::vector<std::unique_ptr<SdrMark>> maList; OUString maMarkName; OUString maPointName; diff --git a/svx/source/svdraw/svdmark.cxx b/svx/source/svdraw/svdmark.cxx index da4f03051999..00901afc309e 100644 --- a/svx/source/svdraw/svdmark.cxx +++ b/svx/source/svdraw/svdmark.cxx @@ -119,7 +119,7 @@ SdrMark& SdrMark::operator=(const SdrMark& rMark) return *this; } -static bool ImpSdrMarkListSorter(SdrMark* const& lhs, SdrMark* const& rhs) +static bool ImpSdrMarkListSorter(std::unique_ptr<SdrMark> const& lhs, std::unique_ptr<SdrMark> const& rhs) { SdrObject* pObj1 = lhs->GetMarkedSdrObj(); SdrObject* pObj2 = rhs->GetMarkedSdrObj(); @@ -161,13 +161,11 @@ void SdrMarkList::ImpForceSort() // remove invalid if(nCount > 0 ) { - for(std::vector<SdrMark*>::iterator it = maList.begin(); it != maList.end(); ) + for(auto it = maList.begin(); it != maList.end(); ) { - SdrMark* pCurrent = *it; - if(pCurrent->GetMarkedSdrObj() == nullptr) + if(it->get()->GetMarkedSdrObj() == nullptr) { it = maList.erase( it ); - delete pCurrent; } else ++it; @@ -182,11 +180,11 @@ void SdrMarkList::ImpForceSort() // remove duplicates if(maList.size() > 1) { - SdrMark* pCurrent = maList.back(); + SdrMark* pCurrent = maList.back().get(); for (size_t count = maList.size() - 1; count; --count) { size_t i = count - 1; - SdrMark* pCmp = maList[i]; + SdrMark* pCmp = maList[i].get(); assert(pCurrent->GetMarkedSdrObj()); if(pCurrent->GetMarkedSdrObj() == pCmp->GetMarkedSdrObj()) { @@ -199,8 +197,6 @@ void SdrMarkList::ImpForceSort() // delete pCmp maList.erase(maList.begin() + i); - - delete pCmp; } else { @@ -214,10 +210,6 @@ void SdrMarkList::ImpForceSort() void SdrMarkList::Clear() { - for (auto const& elem : maList) - { - delete elem; - } maList.clear(); mbSorted = true; //we're empty, so can be considered sorted SetNameDirty(); @@ -230,8 +222,7 @@ SdrMarkList& SdrMarkList::operator=(const SdrMarkList& rLst) for(size_t i = 0; i < rLst.GetMarkCount(); ++i) { SdrMark* pMark = rLst.GetMark(i); - SdrMark* pNewMark = new SdrMark(*pMark); - maList.push_back(pNewMark); + maList.emplace_back(new SdrMark(*pMark)); } maMarkName = rLst.maMarkName; @@ -245,7 +236,7 @@ SdrMarkList& SdrMarkList::operator=(const SdrMarkList& rLst) SdrMark* SdrMarkList::GetMark(size_t nNum) const { - return (nNum < maList.size()) ? maList[nNum] : nullptr; + return (nNum < maList.size()) ? maList[nNum].get() : nullptr; } size_t SdrMarkList::FindObject(const SdrObject* pObj) const @@ -283,7 +274,7 @@ void SdrMarkList::InsertEntry(const SdrMark& rMark, bool bChkSort) if(!bChkSort) mbSorted = false; - maList.push_back(new SdrMark(rMark)); + maList.emplace_back(new SdrMark(rMark)); } else { @@ -303,8 +294,7 @@ void SdrMarkList::InsertEntry(const SdrMark& rMark, bool bChkSort) } else { - SdrMark* pCopy = new SdrMark(rMark); - maList.push_back(pCopy); + maList.emplace_back(new SdrMark(rMark)); // now check if the sort is ok const SdrObjList* pLastOL = pLastObj!=nullptr ? pLastObj->getParentOfSdrObject() : nullptr; @@ -338,7 +328,6 @@ void SdrMarkList::DeleteMark(size_t nNum) if(pMark) { maList.erase(maList.begin() + nNum); - delete pMark; if (maList.empty()) mbSorted = true; //we're empty, so can be considered sorted SetNameDirty(); @@ -352,10 +341,8 @@ void SdrMarkList::ReplaceMark(const SdrMark& rNewMark, size_t nNum) if(pMark) { - delete pMark; SetNameDirty(); - SdrMark* pCopy = new SdrMark(rNewMark); - maList[nNum] = pCopy; + maList[nNum].reset(new SdrMark(rNewMark)); mbSorted = false; } } @@ -374,7 +361,7 @@ void SdrMarkList::Merge(const SdrMarkList& rSrcList, bool bReverse) { for(size_t i = 0; i < nCount; ++i) { - SdrMark* pM = rSrcList.maList[i]; + SdrMark* pM = rSrcList.maList[i].get(); InsertEntry(*pM); } } @@ -383,7 +370,7 @@ void SdrMarkList::Merge(const SdrMarkList& rSrcList, bool bReverse) for(size_t i = nCount; i > 0;) { --i; - SdrMark* pM = rSrcList.maList[i]; + SdrMark* pM = rSrcList.maList[i].get(); InsertEntry(*pM); } } @@ -393,14 +380,13 @@ bool SdrMarkList::DeletePageView(const SdrPageView& rPV) { bool bChgd(false); - for(std::vector<SdrMark*>::iterator it = maList.begin(); it != maList.end(); ) + for(auto it = maList.begin(); it != maList.end(); ) { - SdrMark* pMark = *it; + SdrMark* pMark = it->get(); if(pMark->GetPageView()==&rPV) { it = maList.erase(it); - delete pMark; SetNameDirty(); bChgd = true; } @@ -425,8 +411,7 @@ bool SdrMarkList::InsertPageView(const SdrPageView& rPV) if(bDoIt) { - SdrMark* pM = new SdrMark(pObj, const_cast<SdrPageView*>(&rPV)); - maList.push_back(pM); + maList.emplace_back(new SdrMark(pObj, const_cast<SdrPageView*>(&rPV))); SetNameDirty(); bChgd = true; } |