include/sfx2/msg.hxx                      |    8 ++++----
 sfx2/source/control/bindings.cxx          |   13 ++++++-------
 sfx2/source/control/sfxstatuslistener.cxx |   21 ++++++++++-----------
 sfx2/source/control/statcach.cxx          |   18 ++++++++----------
 sfx2/source/dialog/splitwin.cxx           |    4 ++--
 sfx2/source/dialog/tplcitem.cxx           |    7 +++----
 sfx2/source/doc/sfxbasemodel.cxx          |    8 +++-----
 sfx2/source/statbar/stbitem.cxx           |   19 +++++++++----------
 sfx2/source/toolbox/tbxitem.cxx           |   21 ++++++++++-----------
 9 files changed, 55 insertions(+), 64 deletions(-)

New commits:
commit d2b3ea4d377bf05830f6eb11d53fd55ea6b435fc
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Sep 4 13:08:59 2018 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Sep 5 09:31:50 2018 +0200

    loplugin:useuniqueptr in sfx2
    
    Change-Id: I7b406cd07cae579de608faa3ec47dd1190dea411
    Reviewed-on: https://gerrit.libreoffice.org/60003
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/sfx2/msg.hxx b/include/sfx2/msg.hxx
index f3c60afb52b0..a9000398103b 100644
--- a/include/sfx2/msg.hxx
+++ b/include/sfx2/msg.hxx
@@ -108,8 +108,8 @@ struct SfxType
     SfxTypeAttrib   aAttrib[1]; // variable length
 
     const std::type_info* Type() const{return pType;}
-    SfxPoolItem*    CreateItem() const
-                    { return createSfxPoolItemFunc(); }
+    std::unique_ptr<SfxPoolItem> CreateItem() const
+                    { return 
std::unique_ptr<SfxPoolItem>(createSfxPoolItemFunc()); }
 };
 
 struct SfxType0
@@ -175,8 +175,8 @@ struct SfxFormalArgument
     const char*     pName;    // Name of the sParameters
     sal_uInt16      nSlotId;  // Slot-Id for identification of the Parameters
 
-    SfxPoolItem*            CreateItem() const
-                            { return pType->createSfxPoolItemFunc(); }
+    std::unique_ptr<SfxPoolItem> CreateItem() const
+                            { return pType->CreateItem(); }
 };
 
 
diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx
index b65ccbf08892..031a52694dc0 100644
--- a/sfx2/source/control/bindings.cxx
+++ b/sfx2/source/control/bindings.cxx
@@ -1040,27 +1040,26 @@ void SfxBindings::Execute_Impl( SfxRequest& aReq, const 
SfxSlot* pSlot, SfxShell
             else if ( SfxItemState::DONTCARE == eState )
             {
                 // Create one Status-Item for each Factory
-                SfxPoolItem *pNewItem = pSlot->GetType()->CreateItem();
+                std::unique_ptr<SfxPoolItem> pNewItem = 
pSlot->GetType()->CreateItem();
                 DBG_ASSERT( pNewItem, "Toggle to slot without ItemFactory" );
                 pNewItem->SetWhich( nWhich );
 
-                if ( dynamic_cast< const SfxBoolItem *>( pNewItem ) !=  
nullptr )
+                if ( auto pNewBoolItem = dynamic_cast<SfxBoolItem *>( 
pNewItem.get() ) )
                 {
                   // we can toggle Bools
-                    static_cast<SfxBoolItem*>(pNewItem)->SetValue( true );
+                    pNewBoolItem->SetValue( true );
                     aReq.AppendItem( *pNewItem );
                 }
-                else if ( dynamic_cast< const SfxEnumItemInterface *>( 
pNewItem ) !=  nullptr &&
-                        static_cast<SfxEnumItemInterface 
*>(pNewItem)->HasBoolValue())
+                else if ( dynamic_cast< const SfxEnumItemInterface *>( 
pNewItem.get() ) !=  nullptr &&
+                        static_cast<SfxEnumItemInterface 
*>(pNewItem.get())->HasBoolValue())
                 {
                     // and Enums with Bool-Interface
-                    
static_cast<SfxEnumItemInterface*>(pNewItem)->SetBoolValue(true);
+                    
static_cast<SfxEnumItemInterface*>(pNewItem.get())->SetBoolValue(true);
                     aReq.AppendItem( *pNewItem );
                 }
                 else {
                     OSL_FAIL( "Toggle only for Enums and Bools allowed" );
                 }
-                delete pNewItem;
             }
             else {
                 OSL_FAIL( "suspicious Toggle-Slot" );
diff --git a/sfx2/source/control/sfxstatuslistener.cxx 
b/sfx2/source/control/sfxstatuslistener.cxx
index 9197f4af64a0..9323def48af9 100644
--- a/sfx2/source/control/sfxstatuslistener.cxx
+++ b/sfx2/source/control/sfxstatuslistener.cxx
@@ -159,7 +159,7 @@ void SAL_CALL SfxStatusListener::statusChanged( const 
FeatureStateEvent& rEvent)
     const SfxSlot* pSlot = rPool.GetSlot( m_nSlotID );
 
     SfxItemState eState = SfxItemState::DISABLED;
-    SfxPoolItem* pItem = nullptr;
+    std::unique_ptr<SfxPoolItem> pItem;
     if ( rEvent.IsEnabled )
     {
         eState = SfxItemState::DEFAULT;
@@ -167,45 +167,45 @@ void SAL_CALL SfxStatusListener::statusChanged( const 
FeatureStateEvent& rEvent)
 
         if ( aType == ::cppu::UnoType<void>::get() )
         {
-            pItem = new SfxVoidItem( m_nSlotID );
+            pItem.reset(new SfxVoidItem( m_nSlotID ));
             eState = SfxItemState::UNKNOWN;
         }
         else if ( aType == cppu::UnoType< bool >::get() )
         {
             bool bTemp = false;
             rEvent.State >>= bTemp ;
-            pItem = new SfxBoolItem( m_nSlotID, bTemp );
+            pItem.reset(new SfxBoolItem( m_nSlotID, bTemp ));
         }
         else if ( aType == cppu::UnoType< ::cppu::UnoUnsignedShortType 
>::get() )
         {
             sal_uInt16 nTemp = 0;
             rEvent.State >>= nTemp ;
-            pItem = new SfxUInt16Item( m_nSlotID, nTemp );
+            pItem.reset(new SfxUInt16Item( m_nSlotID, nTemp ));
         }
         else if ( aType == cppu::UnoType<sal_uInt32>::get() )
         {
             sal_uInt32 nTemp = 0;
             rEvent.State >>= nTemp ;
-            pItem = new SfxUInt32Item( m_nSlotID, nTemp );
+            pItem.reset(new SfxUInt32Item( m_nSlotID, nTemp ));
         }
         else if ( aType == cppu::UnoType<OUString>::get() )
         {
             OUString sTemp ;
             rEvent.State >>= sTemp ;
-            pItem = new SfxStringItem( m_nSlotID, sTemp );
+            pItem.reset(new SfxStringItem( m_nSlotID, sTemp ));
         }
         else if ( aType == cppu::UnoType< css::frame::status::ItemStatus 
>::get() )
         {
             ItemStatus aItemStatus;
             rEvent.State >>= aItemStatus;
             eState = static_cast<SfxItemState>(aItemStatus.State);
-            pItem = new SfxVoidItem( m_nSlotID );
+            pItem.reset(new SfxVoidItem( m_nSlotID ));
         }
         else if ( aType == cppu::UnoType< css::frame::status::Visibility 
>::get() )
         {
             Visibility aVisibilityStatus;
             rEvent.State >>= aVisibilityStatus;
-            pItem = new SfxVisibilityItem( m_nSlotID, 
aVisibilityStatus.bVisible );
+            pItem.reset(new SfxVisibilityItem( m_nSlotID, 
aVisibilityStatus.bVisible ));
         }
         else
         {
@@ -217,12 +217,11 @@ void SAL_CALL SfxStatusListener::statusChanged( const 
FeatureStateEvent& rEvent)
                 pItem->PutValue( rEvent.State, 0 );
             }
             else
-                pItem = new SfxVoidItem( m_nSlotID );
+                pItem.reset(new SfxVoidItem( m_nSlotID ));
         }
     }
 
-    StateChanged( m_nSlotID, eState, pItem );
-    delete pItem;
+    StateChanged( m_nSlotID, eState, pItem.get() );
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/control/statcach.cxx b/sfx2/source/control/statcach.cxx
index ad140aaf45bd..71658da4e654 100644
--- a/sfx2/source/control/statcach.cxx
+++ b/sfx2/source/control/statcach.cxx
@@ -78,7 +78,7 @@ void SAL_CALL  BindDispatch_Impl::statusChanged( const 
css::frame::FeatureStateE
         pCache->Invalidate( true );
     else
     {
-        SfxPoolItem *pItem=nullptr;
+        std::unique_ptr<SfxPoolItem> pItem;
         sal_uInt16 nId = pCache->GetId();
         SfxItemState eState = SfxItemState::DISABLED;
         if ( !aStatus.IsEnabled )
@@ -95,25 +95,25 @@ void SAL_CALL  BindDispatch_Impl::statusChanged( const 
css::frame::FeatureStateE
             {
                 bool bTemp = false;
                 aAny >>= bTemp ;
-                pItem = new SfxBoolItem( nId, bTemp );
+                pItem.reset( new SfxBoolItem( nId, bTemp ) );
             }
             else if ( aType == ::cppu::UnoType< ::cppu::UnoUnsignedShortType 
>::get() )
             {
                 sal_uInt16 nTemp = 0;
                 aAny >>= nTemp ;
-                pItem = new SfxUInt16Item( nId, nTemp );
+                pItem.reset( new SfxUInt16Item( nId, nTemp ) );
             }
             else if ( aType == cppu::UnoType<sal_uInt32>::get() )
             {
                 sal_uInt32 nTemp = 0;
                 aAny >>= nTemp ;
-                pItem = new SfxUInt32Item( nId, nTemp );
+                pItem.reset( new SfxUInt32Item( nId, nTemp ) );
             }
             else if ( aType == cppu::UnoType<OUString>::get() )
             {
                 OUString sTemp ;
                 aAny >>= sTemp ;
-                pItem = new SfxStringItem( nId, sTemp );
+                pItem.reset( new SfxStringItem( nId, sTemp ) );
             }
             else
             {
@@ -125,22 +125,20 @@ void SAL_CALL  BindDispatch_Impl::statusChanged( const 
css::frame::FeatureStateE
                     pItem->PutValue( aAny, 0 );
                 }
                 else
-                    pItem = new SfxVoidItem( nId );
+                    pItem.reset( new SfxVoidItem( nId ) );
             }
         }
         else
         {
             // DONTCARE status
-            pItem = new SfxVoidItem(0);
+            pItem.reset( new SfxVoidItem(0) );
             eState = SfxItemState::UNKNOWN;
         }
 
         for ( SfxControllerItem *pCtrl = pCache->GetItemLink();
             pCtrl;
             pCtrl = pCtrl->GetItemLink() )
-            pCtrl->StateChanged( nId, eState, pItem );
-
-       delete pItem;
+            pCtrl->StateChanged( nId, eState, pItem.get() );
     }
 }
 
diff --git a/sfx2/source/dialog/splitwin.cxx b/sfx2/source/dialog/splitwin.cxx
index ac0530433bdf..88f0c860f7d4 100644
--- a/sfx2/source/dialog/splitwin.cxx
+++ b/sfx2/source/dialog/splitwin.cxx
@@ -658,7 +658,7 @@ void SfxSplitWindow::InsertWindow_Impl( SfxDock_Impl const 
* pDock,
         nWinSize = rSize.Height();
     }
 
-    DeactivateUpdateMode* pDeactivateUpdateMode = new DeactivateUpdateMode( 
*this );
+    std::unique_ptr<DeactivateUpdateMode> pDeactivateUpdateMode(new 
DeactivateUpdateMode( *this ));
 
     if ( bNewLine || nLine == GetItemCount() )
     {
@@ -728,7 +728,7 @@ void SfxSplitWindow::InsertWindow_Impl( SfxDock_Impl const 
* pDock,
         pWorkWin->ShowChildren_Impl();
     }
 
-    delete pDeactivateUpdateMode;
+    pDeactivateUpdateMode.reset();
 
     // workaround insufficiency of <SplitWindow> regarding dock layouting:
     // apply FIXED item size as 'original' item size to improve layouting of 
undock-dock-cycle of a window
diff --git a/sfx2/source/dialog/tplcitem.cxx b/sfx2/source/dialog/tplcitem.cxx
index ec732fe08768..1254e4163161 100644
--- a/sfx2/source/dialog/tplcitem.cxx
+++ b/sfx2/source/dialog/tplcitem.cxx
@@ -156,16 +156,15 @@ void SfxTemplateControllerItem::StateChanged( sal_uInt16 
nSID, SfxItemState eSta
 IMPL_LINK_NOARG(SfxTemplateControllerItem, SetWaterCanStateHdl_Impl, void*, 
void)
 {
     nUserEventId = nullptr;
-    SfxBoolItem* pState = nullptr;
+    std::unique_ptr<SfxBoolItem> pState;
     switch(nWaterCanState)
     {
         case 0 :
         case 1 :
-            pState = new SfxBoolItem(SID_STYLE_WATERCAN, nWaterCanState != 0);
+            pState.reset(new SfxBoolItem(SID_STYLE_WATERCAN, nWaterCanState != 
0));
         break;
     }
-    rTemplateDlg.SetWaterCanState(pState);
-    delete pState;
+    rTemplateDlg.SetWaterCanState(pState.get());
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index 09fa01d8f6de..39a304dd5bbe 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -432,7 +432,7 @@ class SfxSaveGuard
     private:
         Reference< frame::XModel > m_xModel;
         IMPL_SfxBaseModel_DataContainer* m_pData;
-        SfxOwnFramesLocker* m_pFramesLock;
+        std::unique_ptr<SfxOwnFramesLocker> m_pFramesLock;
 
         SfxSaveGuard(SfxSaveGuard &) = delete;
         void operator =(const SfxSaveGuard&) = delete;
@@ -453,14 +453,12 @@ SfxSaveGuard::SfxSaveGuard(const Reference< frame::XModel 
>&             xModel
         throw lang::DisposedException("Object already disposed.");
 
     m_pData->m_bSaving = true;
-    m_pFramesLock = new SfxOwnFramesLocker( m_pData->m_pObjectShell.get() );
+    m_pFramesLock.reset(new SfxOwnFramesLocker( m_pData->m_pObjectShell.get() 
));
 }
 
 SfxSaveGuard::~SfxSaveGuard()
 {
-    SfxOwnFramesLocker* pFramesLock = m_pFramesLock;
-    m_pFramesLock = nullptr;
-    delete pFramesLock;
+    m_pFramesLock.reset();
 
     m_pData->m_bSaving = false;
 
diff --git a/sfx2/source/statbar/stbitem.cxx b/sfx2/source/statbar/stbitem.cxx
index 2949ec86a578..9512c25c1bf6 100644
--- a/sfx2/source/statbar/stbitem.cxx
+++ b/sfx2/source/statbar/stbitem.cxx
@@ -224,7 +224,7 @@ void SAL_CALL SfxStatusBarControl::statusChanged( const 
frame::FeatureStateEvent
         else
         {
             SfxItemState eState = SfxItemState::DISABLED;
-            SfxPoolItem* pItem = nullptr;
+            std::unique_ptr<SfxPoolItem> pItem;
             if ( rEvent.IsEnabled )
             {
                 eState = SfxItemState::DEFAULT;
@@ -232,39 +232,39 @@ void SAL_CALL SfxStatusBarControl::statusChanged( const 
frame::FeatureStateEvent
 
                 if ( aType == cppu::UnoType<void>::get() )
                 {
-                    pItem = new SfxVoidItem( nSlotID );
+                    pItem.reset( new SfxVoidItem( nSlotID ) );
                     eState = SfxItemState::UNKNOWN;
                 }
                 else if ( aType == cppu::UnoType<bool>::get() )
                 {
                     bool bTemp = false;
                     rEvent.State >>= bTemp ;
-                    pItem = new SfxBoolItem( nSlotID, bTemp );
+                    pItem.reset( new SfxBoolItem( nSlotID, bTemp ) );
                 }
                 else if ( aType == ::cppu::UnoType< 
::cppu::UnoUnsignedShortType >::get() )
                 {
                     sal_uInt16 nTemp = 0;
                     rEvent.State >>= nTemp ;
-                    pItem = new SfxUInt16Item( nSlotID, nTemp );
+                    pItem.reset( new SfxUInt16Item( nSlotID, nTemp ) );
                 }
                 else if ( aType == cppu::UnoType<sal_uInt32>::get() )
                 {
                     sal_uInt32 nTemp = 0;
                     rEvent.State >>= nTemp ;
-                    pItem = new SfxUInt32Item( nSlotID, nTemp );
+                    pItem.reset( new SfxUInt32Item( nSlotID, nTemp ) );
                 }
                 else if ( aType == cppu::UnoType<OUString>::get() )
                 {
                     OUString sTemp ;
                     rEvent.State >>= sTemp ;
-                    pItem = new SfxStringItem( nSlotID, sTemp );
+                    pItem.reset( new SfxStringItem( nSlotID, sTemp ) );
                 }
                 else if ( aType == cppu::UnoType< 
css::frame::status::ItemStatus>::get() )
                 {
                     frame::status::ItemStatus aItemStatus;
                     rEvent.State >>= aItemStatus;
                     eState = static_cast<SfxItemState>(aItemStatus.State);
-                    pItem = new SfxVoidItem( nSlotID );
+                    pItem.reset( new SfxVoidItem( nSlotID ) );
                 }
                 else
                 {
@@ -276,12 +276,11 @@ void SAL_CALL SfxStatusBarControl::statusChanged( const 
frame::FeatureStateEvent
                         pItem->PutValue( rEvent.State, 0 );
                     }
                     else
-                        pItem = new SfxVoidItem( nSlotID );
+                        pItem.reset( new SfxVoidItem( nSlotID ) );
                 }
             }
 
-            StateChanged( nSlotID, eState, pItem );
-            delete pItem;
+            StateChanged( nSlotID, eState, pItem.get() );
         }
     }
 }
diff --git a/sfx2/source/toolbox/tbxitem.cxx b/sfx2/source/toolbox/tbxitem.cxx
index 04cf849cfc1f..c5d698be764c 100644
--- a/sfx2/source/toolbox/tbxitem.cxx
+++ b/sfx2/source/toolbox/tbxitem.cxx
@@ -449,7 +449,7 @@ void SAL_CALL SfxToolBoxControl::statusChanged( const 
FeatureStateEvent& rEvent
         else
         {
             SfxItemState eState = SfxItemState::DISABLED;
-            SfxPoolItem* pItem = nullptr;
+            std::unique_ptr<SfxPoolItem> pItem;
             if ( rEvent.IsEnabled )
             {
                 eState = SfxItemState::DEFAULT;
@@ -457,32 +457,32 @@ void SAL_CALL SfxToolBoxControl::statusChanged( const 
FeatureStateEvent& rEvent
 
                 if ( aType == cppu::UnoType<void>::get() )
                 {
-                    pItem = new SfxVoidItem( nSlotId );
+                    pItem.reset(new SfxVoidItem( nSlotId ));
                     eState = SfxItemState::UNKNOWN;
                 }
                 else if ( aType == cppu::UnoType<bool>::get() )
                 {
                     bool bTemp = false;
                     rEvent.State >>= bTemp ;
-                    pItem = new SfxBoolItem( nSlotId, bTemp );
+                    pItem.reset(new SfxBoolItem( nSlotId, bTemp ));
                 }
                 else if ( aType == ::cppu::UnoType< 
::cppu::UnoUnsignedShortType >::get())
                 {
                     sal_uInt16 nTemp = 0;
                     rEvent.State >>= nTemp ;
-                    pItem = new SfxUInt16Item( nSlotId, nTemp );
+                    pItem.reset(new SfxUInt16Item( nSlotId, nTemp ));
                 }
                 else if ( aType == cppu::UnoType<sal_uInt32>::get() )
                 {
                     sal_uInt32 nTemp = 0;
                     rEvent.State >>= nTemp ;
-                    pItem = new SfxUInt32Item( nSlotId, nTemp );
+                    pItem.reset(new SfxUInt32Item( nSlotId, nTemp ));
                 }
                 else if ( aType == cppu::UnoType<OUString>::get() )
                 {
                     OUString sTemp ;
                     rEvent.State >>= sTemp ;
-                    pItem = new SfxStringItem( nSlotId, sTemp );
+                    pItem.reset(new SfxStringItem( nSlotId, sTemp ));
                 }
                 else if ( aType == cppu::UnoType< 
css::frame::status::ItemStatus>::get() )
                 {
@@ -495,13 +495,13 @@ void SAL_CALL SfxToolBoxControl::statusChanged( const 
FeatureStateEvent& rEvent
                         tmpState != SfxItemState::DEFAULT && tmpState != 
SfxItemState::SET)
                         throw css::uno::RuntimeException("unknown status");
                     eState = tmpState;
-                    pItem = new SfxVoidItem( nSlotId );
+                    pItem.reset(new SfxVoidItem( nSlotId ));
                 }
                 else if ( aType == cppu::UnoType< 
css::frame::status::Visibility>::get() )
                 {
                     Visibility aVisibilityStatus;
                     rEvent.State >>= aVisibilityStatus;
-                    pItem = new SfxVisibilityItem( nSlotId, 
aVisibilityStatus.bVisible );
+                    pItem.reset(new SfxVisibilityItem( nSlotId, 
aVisibilityStatus.bVisible ));
                 }
                 else
                 {
@@ -513,12 +513,11 @@ void SAL_CALL SfxToolBoxControl::statusChanged( const 
FeatureStateEvent& rEvent
                         pItem->PutValue( rEvent.State, 0 );
                     }
                     else
-                        pItem = new SfxVoidItem( nSlotId );
+                        pItem.reset(new SfxVoidItem( nSlotId ));
                 }
             }
 
-            StateChanged( nSlotId, eState, pItem );
-            delete pItem;
+            StateChanged( nSlotId, eState, pItem.get() );
         }
     }
 }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to