LCOV - code coverage report
Current view: top level - svtools/source/misc - itemdel.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 19 19 100.0 %
Date: 2014-04-11 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 <svtools/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             : // STATIC DATA -----------------------------------------------------------
      32             : 
      33             : 
      34             : 
      35             : 
      36             : class SfxItemDesruptor_Impl: private boost::noncopyable
      37             : {
      38             :     SfxPoolItem *pItem;
      39             :     Link         aLink;
      40             : 
      41             : private:
      42             :     DECL_LINK( Delete, void* );
      43             : 
      44             : public:
      45             :     SfxItemDesruptor_Impl( SfxPoolItem *pItemToDesrupt );
      46             :     void LaunchDeleteOnIdle();
      47             :     ~SfxItemDesruptor_Impl();
      48             : };
      49             : 
      50             : 
      51       53914 : SfxItemDesruptor_Impl::SfxItemDesruptor_Impl( SfxPoolItem *pItemToDesrupt ):
      52             :     pItem(pItemToDesrupt),
      53       53914 :     aLink( LINK(this, SfxItemDesruptor_Impl, Delete) )
      54             : {
      55             : 
      56             :     DBG_ASSERT( 0 == pItem->GetRefCount(), "disrupting pooled item" );
      57       53914 :     pItem->SetKind( SFX_ITEMS_DELETEONIDLE );
      58       53914 : }
      59             : 
      60       53914 : void SfxItemDesruptor_Impl::LaunchDeleteOnIdle()
      61             : {
      62             :     // process in Idle
      63       53914 :     GetpApp()->InsertIdleHdl( aLink, 1 );
      64       53914 : }
      65             : 
      66             : 
      67       52572 : SfxItemDesruptor_Impl::~SfxItemDesruptor_Impl()
      68             : {
      69             : 
      70             :     // remove from Idle-Handler
      71       52572 :     GetpApp()->RemoveIdleHdl( aLink );
      72             : 
      73             :     // reset RefCount (was set to SFX_ITEMS_SPECIAL before!)
      74       52572 :     pItem->SetRefCount( 0 );
      75             : 
      76       52572 :     delete pItem;
      77       52572 : }
      78             : 
      79             : 
      80      105144 : IMPL_LINK_NOARG(SfxItemDesruptor_Impl, Delete)
      81             : {
      82       52572 :     delete this;
      83       52572 :     return 0;
      84             : }
      85             : 
      86       53914 : void DeleteItemOnIdle(SfxPoolItem* pItem)
      87             : {
      88             :     DBG_ASSERT( 0 == pItem->GetRefCount(), "deleting item in use" );
      89       53914 :     SfxItemDesruptor_Impl *pDesruptor = new SfxItemDesruptor_Impl(pItem);
      90       53914 :     pDesruptor->LaunchDeleteOnIdle();
      91       53914 : }
      92             : 
      93             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10