LCOV - code coverage report
Current view: top level - svl/source/items - poolcach.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 38 38 100.0 %
Date: 2014-04-11 Functions: 4 4 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             : 
      21             : #include <limits.h>
      22             : 
      23             : #include <svl/itempool.hxx>
      24             : #include <svl/itemset.hxx>
      25             : #include <svl/poolcach.hxx>
      26             : 
      27        2306 : SfxItemPoolCache::SfxItemPoolCache( SfxItemPool *pItemPool,
      28             :                                     const SfxPoolItem *pPutItem ):
      29             :     pPool(pItemPool),
      30        2306 :     pCache(new SfxItemModifyArr_Impl),
      31             :     pSetToPut( 0 ),
      32        4612 :     pItemToPut( &pItemPool->Put(*pPutItem) )
      33             : {
      34             :     DBG_ASSERT(pItemPool, "kein Pool angegeben");
      35        2306 : }
      36             : 
      37             : 
      38       51249 : SfxItemPoolCache::SfxItemPoolCache( SfxItemPool *pItemPool,
      39             :                                     const SfxItemSet *pPutSet ):
      40             :     pPool(pItemPool),
      41       51249 :     pCache(new SfxItemModifyArr_Impl),
      42             :     pSetToPut( pPutSet ),
      43      102498 :     pItemToPut( 0 )
      44             : {
      45             :     DBG_ASSERT(pItemPool, "kein Pool angegeben");
      46       51249 : }
      47             : 
      48             : 
      49       53555 : SfxItemPoolCache::~SfxItemPoolCache()
      50             : {
      51      107176 :     for ( size_t nPos = 0; nPos < pCache->size(); ++nPos ) {
      52       53621 :         pPool->Remove( *(*pCache)[nPos].pPoolItem );
      53       53621 :         pPool->Remove( *(*pCache)[nPos].pOrigItem );
      54             :     }
      55       53555 :     delete pCache; pCache = 0;
      56             : 
      57       53555 :     if ( pItemToPut )
      58        2306 :         pPool->Remove( *pItemToPut );
      59       53555 : }
      60             : 
      61             : 
      62       59221 : const SfxSetItem& SfxItemPoolCache::ApplyTo( const SfxSetItem &rOrigItem, bool bNew )
      63             : {
      64             :     DBG_ASSERT( pPool == rOrigItem.GetItemSet().GetPool(), "invalid Pool" );
      65             :     DBG_ASSERT( IsDefaultItem( &rOrigItem ) || IsPooledItem( &rOrigItem ),
      66             :                 "original not in pool" );
      67             : 
      68             :     // Find whether this Transformations ever occurred
      69       59323 :     for ( size_t nPos = 0; nPos < pCache->size(); ++nPos )
      70             :     {
      71        5702 :         SfxItemModifyImpl &rMapEntry = (*pCache)[nPos];
      72        5702 :         if ( rMapEntry.pOrigItem == &rOrigItem )
      73             :         {
      74             :             // aendert sich ueberhaupt etwas?
      75        5600 :             if ( rMapEntry.pPoolItem != &rOrigItem )
      76             :             {
      77        5600 :                 rMapEntry.pPoolItem->AddRef(2); // einen davon fuer den Cache
      78        5600 :                 if ( bNew )
      79        5600 :                     pPool->Put( rOrigItem );    //! AddRef??
      80             :             }
      81        5600 :             return *rMapEntry.pPoolItem;
      82             :         }
      83             :     }
      84             : 
      85             :     // die neue Attributierung in einem neuen Set eintragen
      86       53621 :     SfxSetItem *pNewItem = (SfxSetItem *)rOrigItem.Clone();
      87       53621 :     if ( pItemToPut )
      88             :     {
      89        2306 :         pNewItem->GetItemSet().PutDirect( *pItemToPut );
      90             :         DBG_ASSERT( &pNewItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut,
      91             :                     "wrong item in temporary set" );
      92             :     }
      93             :     else
      94       51315 :         pNewItem->GetItemSet().Put( *pSetToPut );
      95       53621 :     const SfxSetItem* pNewPoolItem = (const SfxSetItem*) &pPool->Put( *pNewItem );
      96             :     DBG_ASSERT( pNewPoolItem != pNewItem, "Pool: rein == raus?" );
      97       53621 :     delete pNewItem;
      98             : 
      99             :     // Refernzzaehler anpassen, je einen davon fuer den Cache
     100       53621 :     pNewPoolItem->AddRef( pNewPoolItem != &rOrigItem ? 2 : 1 );
     101       53621 :     if ( bNew )
     102       53621 :         pPool->Put( rOrigItem );    //! AddRef??
     103             : 
     104             :     // die Transformation im Cache eintragen
     105             :     SfxItemModifyImpl aModify;
     106       53621 :     aModify.pOrigItem = &rOrigItem;
     107       53621 :     aModify.pPoolItem = (SfxSetItem*) pNewPoolItem;
     108       53621 :     pCache->push_back( aModify );
     109             : 
     110             :     DBG_ASSERT( !pItemToPut ||
     111             :                 &pNewPoolItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut,
     112             :                 "wrong item in resulting set" );
     113             : 
     114       53621 :     return *pNewPoolItem;
     115             : }
     116             : 
     117             : 
     118             : 
     119             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10