LCOV - code coverage report
Current view: top level - svl/source/items - poolcach.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 38 38 100.0 %
Date: 2014-11-03 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        4784 : SfxItemPoolCache::SfxItemPoolCache( SfxItemPool *pItemPool,
      28             :                                     const SfxPoolItem *pPutItem ):
      29             :     pPool(pItemPool),
      30        4784 :     pCache(new SfxItemModifyArr_Impl),
      31             :     pSetToPut( 0 ),
      32        9568 :     pItemToPut( &pItemPool->Put(*pPutItem) )
      33             : {
      34             :     DBG_ASSERT(pItemPool, "No Pool provided");
      35        4784 : }
      36             : 
      37             : 
      38      135016 : SfxItemPoolCache::SfxItemPoolCache( SfxItemPool *pItemPool,
      39             :                                     const SfxItemSet *pPutSet ):
      40             :     pPool(pItemPool),
      41      135016 :     pCache(new SfxItemModifyArr_Impl),
      42             :     pSetToPut( pPutSet ),
      43      270032 :     pItemToPut( 0 )
      44             : {
      45             :     DBG_ASSERT(pItemPool, "No Pool provided");
      46      135016 : }
      47             : 
      48             : 
      49      139800 : SfxItemPoolCache::~SfxItemPoolCache()
      50             : {
      51      279724 :     for ( size_t nPos = 0; nPos < pCache->size(); ++nPos ) {
      52      139924 :         pPool->Remove( *(*pCache)[nPos].pPoolItem );
      53      139924 :         pPool->Remove( *(*pCache)[nPos].pOrigItem );
      54             :     }
      55      139800 :     delete pCache; pCache = 0;
      56             : 
      57      139800 :     if ( pItemToPut )
      58        4784 :         pPool->Remove( *pItemToPut );
      59      139800 : }
      60             : 
      61             : 
      62      155398 : 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      155594 :     for ( size_t nPos = 0; nPos < pCache->size(); ++nPos )
      70             :     {
      71       15670 :         SfxItemModifyImpl &rMapEntry = (*pCache)[nPos];
      72       15670 :         if ( rMapEntry.pOrigItem == &rOrigItem )
      73             :         {
      74             :             // Did anything change at all?
      75       15474 :             if ( rMapEntry.pPoolItem != &rOrigItem )
      76             :             {
      77       13516 :                 rMapEntry.pPoolItem->AddRef(2); // One for the cache
      78       13516 :                 if ( bNew )
      79       13516 :                     pPool->Put( rOrigItem );    //FIXME: AddRef?
      80             :             }
      81       15474 :             return *rMapEntry.pPoolItem;
      82             :         }
      83             :     }
      84             : 
      85             :     // Insert the new attributes in a new Set
      86      139924 :     SfxSetItem *pNewItem = static_cast<SfxSetItem *>(rOrigItem.Clone());
      87      139924 :     if ( pItemToPut )
      88             :     {
      89        4784 :         pNewItem->GetItemSet().PutDirect( *pItemToPut );
      90             :         DBG_ASSERT( &pNewItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut,
      91             :                     "wrong item in temporary set" );
      92             :     }
      93             :     else
      94      135140 :         pNewItem->GetItemSet().Put( *pSetToPut );
      95      139924 :     const SfxSetItem* pNewPoolItem = static_cast<const SfxSetItem*>(&pPool->Put( *pNewItem ));
      96             :     DBG_ASSERT( pNewPoolItem != pNewItem, "Pool: same in and out?" );
      97      139924 :     delete pNewItem;
      98             : 
      99             :     // Adapt refcount; one each for the cache
     100      139924 :     pNewPoolItem->AddRef( pNewPoolItem != &rOrigItem ? 2 : 1 );
     101      139924 :     if ( bNew )
     102      139924 :         pPool->Put( rOrigItem );    //FIXME: AddRef?
     103             : 
     104             :     // Add the transformation to the cache
     105             :     SfxItemModifyImpl aModify;
     106      139924 :     aModify.pOrigItem = &rOrigItem;
     107      139924 :     aModify.pPoolItem = (SfxSetItem*) pNewPoolItem;
     108      139924 :     pCache->push_back( aModify );
     109             : 
     110             :     DBG_ASSERT( !pItemToPut ||
     111             :                 &pNewPoolItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut,
     112             :                 "wrong item in resulting set" );
     113             : 
     114      139924 :     return *pNewPoolItem;
     115             : }
     116             : 
     117             : 
     118             : 
     119             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10