LCOV - code coverage report
Current view: top level - sfx2/source/control - itemdel.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 19 19 100.0 %
Date: 2015-06-13 12:38:46 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/config.h>
      21             : 
      22             : #include <boost/noncopyable.hpp>
      23             : #include "itemdel.hxx"
      24             : #include <vcl/svapp.hxx>
      25             : #include <tools/errcode.hxx>
      26             : #include <limits.h>
      27             : #include <vector>
      28             : 
      29             : #include <svl/itempool.hxx>
      30             : 
      31             : class SfxItemDisruptor_Impl: private boost::noncopyable
      32             : {
      33             :     SfxPoolItem *pItem;
      34             :     Link<>       aLink;
      35             : 
      36             : private:
      37             :     DECL_LINK( Delete, void* );
      38             : 
      39             : public:
      40             :     SfxItemDisruptor_Impl( SfxPoolItem *pItemToDesrupt );
      41             :     void LaunchDeleteOnIdle();
      42             :     ~SfxItemDisruptor_Impl();
      43             : };
      44             : 
      45       87356 : SfxItemDisruptor_Impl::SfxItemDisruptor_Impl( SfxPoolItem *pItemToDesrupt ):
      46             :     pItem(pItemToDesrupt),
      47       87356 :     aLink( LINK(this, SfxItemDisruptor_Impl, Delete) )
      48             : {
      49             : 
      50             :     DBG_ASSERT( 0 == pItem->GetRefCount(), "disrupting pooled item" );
      51       87356 :     pItem->SetKind( SFX_ITEMS_DELETEONIDLE );
      52       87356 : }
      53             : 
      54       87356 : void SfxItemDisruptor_Impl::LaunchDeleteOnIdle()
      55             : {
      56             :     // process in Idle
      57       87356 :     Application::InsertIdleHdl( aLink, 1 );
      58       87356 : }
      59             : 
      60       87355 : SfxItemDisruptor_Impl::~SfxItemDisruptor_Impl()
      61             : {
      62             : 
      63             :     // remove from Idle-Handler
      64       87355 :     Application::RemoveIdleHdl( aLink );
      65             : 
      66             :     // reset RefCount (was set to SFX_ITEMS_SPECIAL before!)
      67       87355 :     pItem->SetRefCount( 0 );
      68             : 
      69       87355 :     delete pItem;
      70       87355 : }
      71             : 
      72      174710 : IMPL_LINK_NOARG(SfxItemDisruptor_Impl, Delete)
      73             : {
      74       87355 :     delete this;
      75       87355 :     return 0;
      76             : }
      77             : 
      78       87356 : void DeleteItemOnIdle(SfxPoolItem* pItem)
      79             : {
      80             :     DBG_ASSERT( 0 == pItem->GetRefCount(), "deleting item in use" );
      81       87356 :     SfxItemDisruptor_Impl *pDesruptor = new SfxItemDisruptor_Impl(pItem);
      82       87356 :     pDesruptor->LaunchDeleteOnIdle();
      83             :     // coverity[leaked_storage] pDesruptor takes care of its own destruction at idle time
      84       87356 : }
      85             : 
      86             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11