Kaydet (Commit) 2ae25894 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in BaseContainerControl

Change-Id: If78893d47d2b504b01652575579c6972a3863a09
Reviewed-on: https://gerrit.libreoffice.org/60620
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 3a1aa1c2
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <com/sun/star/container/ContainerEvent.hpp> #include <com/sun/star/container/ContainerEvent.hpp>
#include <com/sun/star/container/XIndexReplace.hpp> #include <com/sun/star/container/XIndexReplace.hpp>
#include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/container/XNameContainer.hpp>
#include <memory>
#include <vector> #include <vector>
#include "basecontrol.hxx" #include "basecontrol.hxx"
...@@ -152,10 +153,8 @@ protected: ...@@ -152,10 +153,8 @@ protected:
private: private:
void impl_activateTabControllers(); void impl_activateTabControllers();
void impl_cleanMemory();
// list of pointer of "struct IMPL_ControlInfo" to hold child-controls // list of pointer of "struct IMPL_ControlInfo" to hold child-controls
::std::vector< IMPL_ControlInfo* > maControlInfoList; ::std::vector< std::unique_ptr<IMPL_ControlInfo> > maControlInfoList;
// list of references of XTabController to hold tab-order in this container // list of references of XTabController to hold tab-order in this container
css::uno::Sequence< css::uno::Reference< css::awt::XTabController > > m_xTabControllerList; css::uno::Sequence< css::uno::Reference< css::awt::XTabController > > m_xTabControllerList;
......
...@@ -43,7 +43,6 @@ BaseContainerControl::BaseContainerControl( const Reference< XComponentContext > ...@@ -43,7 +43,6 @@ BaseContainerControl::BaseContainerControl( const Reference< XComponentContext >
BaseContainerControl::~BaseContainerControl() BaseContainerControl::~BaseContainerControl()
{ {
impl_cleanMemory();
} }
// XInterface // XInterface
...@@ -207,7 +206,7 @@ void SAL_CALL BaseContainerControl::addControl ( const OUString& rName, const Re ...@@ -207,7 +206,7 @@ void SAL_CALL BaseContainerControl::addControl ( const OUString& rName, const Re
pNewControl->xControl = rControl; pNewControl->xControl = rControl;
// and insert in list // and insert in list
maControlInfoList.push_back( pNewControl ); maControlInfoList.emplace_back( pNewControl );
// initialize new control // initialize new control
pNewControl->xControl->setContext ( static_cast<OWeakObject*>(this) ); pNewControl->xControl->setContext ( static_cast<OWeakObject*>(this) );
...@@ -257,7 +256,7 @@ void SAL_CALL BaseContainerControl::removeControl ( const Reference< XControl > ...@@ -257,7 +256,7 @@ void SAL_CALL BaseContainerControl::removeControl ( const Reference< XControl >
for ( size_t n = 0; n < nControls; n++ ) for ( size_t n = 0; n < nControls; n++ )
{ {
// Search for right control // Search for right control
IMPL_ControlInfo* pControl = maControlInfoList[ n ]; IMPL_ControlInfo* pControl = maControlInfoList[ n ].get();
if ( rControl == pControl->xControl ) if ( rControl == pControl->xControl )
{ {
//.is it found ... remove listener from control //.is it found ... remove listener from control
...@@ -265,10 +264,7 @@ void SAL_CALL BaseContainerControl::removeControl ( const Reference< XControl > ...@@ -265,10 +264,7 @@ void SAL_CALL BaseContainerControl::removeControl ( const Reference< XControl >
pControl->xControl->setContext ( Reference< XInterface > () ); pControl->xControl->setContext ( Reference< XInterface > () );
// ... free memory // ... free memory
delete pControl; maControlInfoList.erase(maControlInfoList.begin() + n);
::std::vector<IMPL_ControlInfo*>::iterator itr = maControlInfoList.begin();
::std::advance(itr, n);
maControlInfoList.erase(itr);
// Send message to all other listener // Send message to all other listener
OInterfaceContainerHelper * pInterfaceContainer = m_aListeners.getContainer( cppu::UnoType<XContainerListener>::get()); OInterfaceContainerHelper * pInterfaceContainer = m_aListeners.getContainer( cppu::UnoType<XContainerListener>::get());
...@@ -319,7 +315,7 @@ Reference< XControl > SAL_CALL BaseContainerControl::getControl ( const OUString ...@@ -319,7 +315,7 @@ Reference< XControl > SAL_CALL BaseContainerControl::getControl ( const OUString
// Search for right control // Search for right control
for( size_t nCount = 0; nCount < nControls; ++nCount ) for( size_t nCount = 0; nCount < nControls; ++nCount )
{ {
IMPL_ControlInfo* pSearchControl = maControlInfoList[ nCount ]; IMPL_ControlInfo* pSearchControl = maControlInfoList[ nCount ].get();
if ( pSearchControl->sName == rName ) if ( pSearchControl->sName == rName )
{ {
...@@ -348,7 +344,7 @@ Sequence< Reference< XControl > > SAL_CALL BaseContainerControl::getControls () ...@@ -348,7 +344,7 @@ Sequence< Reference< XControl > > SAL_CALL BaseContainerControl::getControls ()
// Copy controls to sequence // Copy controls to sequence
for( nCount = 0; nCount < nControls; ++nCount ) for( nCount = 0; nCount < nControls; ++nCount )
{ {
IMPL_ControlInfo* pCopyControl = maControlInfoList[ nCount ]; IMPL_ControlInfo* pCopyControl = maControlInfoList[ nCount ].get();
pDestination [ nCount ] = pCopyControl->xControl; pDestination [ nCount ] = pCopyControl->xControl;
} }
...@@ -414,29 +410,6 @@ void BaseContainerControl::impl_activateTabControllers () ...@@ -414,29 +410,6 @@ void BaseContainerControl::impl_activateTabControllers ()
} }
} }
// private method
void BaseContainerControl::impl_cleanMemory ()
{
// Get count of listitems.
size_t nMaxCount = maControlInfoList.size();
size_t nCount = 0;
// Delete all items.
for ( nCount = 0; nCount < nMaxCount; ++nCount )
{
// Delete every time first element of list!
// We count from 0 to MAX, where "MAX=count of items" BEFORE we delete some elements!
// If we use "GetObject ( nCount )" ... it can be, that we have an index greater then count of current elements!
IMPL_ControlInfo* pSearchControl = maControlInfoList[ nCount ];
delete pSearchControl;
}
// Delete list himself.
maControlInfoList.clear ();
}
} // namespace unocontrols } // namespace unocontrols
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment