From b6df5604e2eafbe5857efcf9a5cb6440c47ffd16 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 30 Oct 2018 14:22:23 +0200 Subject: loplugin:useuniqueptr in SdCustomShowList Change-Id: I604f4cd616ec6eb31198806456a660e7a1e915ca Reviewed-on: https://gerrit.libreoffice.org/62662 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sd/inc/cusshow.hxx | 2 ++ sd/inc/customshowlist.hxx | 34 +++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) (limited to 'sd/inc') diff --git a/sd/inc/cusshow.hxx b/sd/inc/cusshow.hxx index 612798bdc473..b8dafdd373aa 100644 --- a/sd/inc/cusshow.hxx +++ b/sd/inc/cusshow.hxx @@ -47,6 +47,8 @@ public: // @@@ copy ctor, but no copy assignment? @@@ SdCustomShow( const SdCustomShow& rShow ); + SdCustomShow& operator=( const SdCustomShow& rShow ) = delete; + /** Provides a direct access to the collection of the SdPage objects. */ PageVec& PagesVector() { return maPages;} /** diff --git a/sd/inc/customshowlist.hxx b/sd/inc/customshowlist.hxx index 1d30473e5050..5c70f8a63522 100644 --- a/sd/inc/customshowlist.hxx +++ b/sd/inc/customshowlist.hxx @@ -20,14 +20,15 @@ #ifndef INCLUDED_SD_INC_CUSTOMSHOWLIST_HXX #define INCLUDED_SD_INC_CUSTOMSHOWLIST_HXX +#include "sddllapi.h" #include class SdCustomShow; -class SdCustomShowList +class SD_DLLPUBLIC SdCustomShowList { private: - std::vector mShows; + std::vector> mShows; sal_uInt16 mnCurPos; public: SdCustomShowList() @@ -35,17 +36,20 @@ public: { } + SdCustomShowList& operator=( SdCustomShowList const & ) = delete; // MSVC2017 workaround + SdCustomShowList( SdCustomShowList const & ) = delete; // MSVC2017 workaround + bool empty() const {return mShows.empty();} size_t size() const {return mShows.size();} - SdCustomShow* &operator[](size_t i) {return mShows[i];} + std::unique_ptr& operator[](size_t i) {return mShows[i];} - std::vector::iterator begin() {return mShows.begin();} + std::vector>::iterator begin() {return mShows.begin();} - void erase(std::vector::iterator it) {mShows.erase(it);} + void erase(std::vector>::iterator it); - void push_back(SdCustomShow* p) {mShows.push_back(p);} + void push_back(std::unique_ptr p) {mShows.push_back(std::move(p));} sal_uInt16 GetCurPos() const { return mnCurPos; } void Seek(sal_uInt16 nNewPos) { mnCurPos = nNewPos; } @@ -55,12 +59,12 @@ public: if( mShows.empty() ) return nullptr; mnCurPos = 0; - return mShows[mnCurPos]; + return mShows[mnCurPos].get(); } SdCustomShow* Next() { ++mnCurPos; - return mnCurPos >= mShows.size() ? nullptr : mShows[mnCurPos]; + return mnCurPos >= mShows.size() ? nullptr : mShows[mnCurPos].get(); } void Last() { @@ -69,15 +73,15 @@ public: } SdCustomShow* GetCurObject() { - return mShows.empty() ? nullptr : mShows[mnCurPos]; + return mShows.empty() ? nullptr : mShows[mnCurPos].get(); } - SdCustomShow* Remove(SdCustomShow* p) + void erase(SdCustomShow* p) { - std::vector::iterator it = std::find(mShows.begin(), mShows.end(), p); - if( it == mShows.end() ) - return nullptr; - mShows.erase(it); - return p; + auto it = std::find_if(mShows.begin(), mShows.end(), + [&] (std::unique_ptr const &i) { return i.get() == p; }); + assert( it != mShows.end() ); + if( it != mShows.end() ) + mShows.erase(it); } }; -- cgit