From 1f75cda1d842717248c6dc926a9d2cd06f39d85b Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 16 Jan 2018 15:28:46 +0200 Subject: loplugin:useuniqueptr in HelpInterceptor_Impl Change-Id: I75c1ca2d6b0e03604bb6c96d2613261a1a05b988 Reviewed-on: https://gerrit.libreoffice.org/48297 Reviewed-by: Noel Grandin Tested-by: Noel Grandin --- sfx2/source/appl/helpinterceptor.cxx | 20 +++++--------------- sfx2/source/appl/helpinterceptor.hxx | 5 ++--- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/sfx2/source/appl/helpinterceptor.cxx b/sfx2/source/appl/helpinterceptor.cxx index 03f81a25e358..a41fc472a02b 100644 --- a/sfx2/source/appl/helpinterceptor.cxx +++ b/sfx2/source/appl/helpinterceptor.cxx @@ -47,29 +47,20 @@ HelpInterceptor_Impl::HelpInterceptor_Impl() : HelpInterceptor_Impl::~HelpInterceptor_Impl() { - if ( m_pHistory ) - { - for (HelpHistoryEntry_Impl* p : *m_pHistory) - delete p; - delete m_pHistory; - } } void HelpInterceptor_Impl::addURL( const OUString& rURL ) { if ( !m_pHistory ) - m_pHistory = new HelpHistoryList_Impl; + m_pHistory.reset( new std::vector> ); size_t nCount = m_pHistory->size(); if ( nCount && m_nCurPos < ( nCount - 1 ) ) { for ( size_t i = nCount - 1; i > m_nCurPos; i-- ) { - delete m_pHistory->at( i ); - HelpHistoryList_Impl::iterator it = m_pHistory->begin(); - ::std::advance( it, i ); - m_pHistory->erase( it ); + m_pHistory->erase( m_pHistory->begin() + i ); } } Reference xFrame(m_xIntercepted, UNO_QUERY); @@ -83,7 +74,7 @@ void HelpInterceptor_Impl::addURL( const OUString& rURL ) m_aCurrentURL = rURL; Any aEmptyViewData; - m_pHistory->push_back( new HelpHistoryEntry_Impl( rURL, aEmptyViewData ) ); + m_pHistory->emplace_back( new HelpHistoryEntry_Impl( rURL, aEmptyViewData ) ); m_nCurPos = m_pHistory->size() - 1; // TODO ? if ( m_xListener.is() ) @@ -229,9 +220,8 @@ void SAL_CALL HelpInterceptor_Impl::dispatch( if ( nPos < ULONG_MAX ) { - HelpHistoryEntry_Impl* pEntry = m_pHistory->at( nPos ); - if ( pEntry ) - m_pWindow->loadHelpContent(pEntry->aURL, false); // false => don't add item to history again! + HelpHistoryEntry_Impl* pEntry = m_pHistory->at( nPos ).get(); + m_pWindow->loadHelpContent(pEntry->aURL, false); // false => don't add item to history again! } m_pWindow->UpdateToolbox(); diff --git a/sfx2/source/appl/helpinterceptor.hxx b/sfx2/source/appl/helpinterceptor.hxx index 41d9665f264b..92897d892343 100644 --- a/sfx2/source/appl/helpinterceptor.hxx +++ b/sfx2/source/appl/helpinterceptor.hxx @@ -29,6 +29,7 @@ #include #include #include +#include struct HelpHistoryEntry_Impl { @@ -39,8 +40,6 @@ struct HelpHistoryEntry_Impl aURL( rURL ), aViewData(rViewData) {} }; -typedef ::std::vector< HelpHistoryEntry_Impl* > HelpHistoryList_Impl; - class SfxHelpWindow_Impl; class HelpInterceptor_Impl : public ::cppu::WeakImplHelper< css::frame::XDispatchProviderInterceptor, @@ -61,7 +60,7 @@ friend class SfxHelpWindow_Impl; css::uno::Reference< css::frame::XStatusListener > m_xListener; - HelpHistoryList_Impl* m_pHistory; + std::unique_ptr>> m_pHistory; VclPtr m_pWindow; sal_uIntPtr m_nCurPos; OUString m_aCurrentURL; -- cgit