LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svl/source/items - poolcach.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 38 38 100.0 %
Date: 2013-07-09 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             : // STATIC DATA -----------------------------------------------------------
      28             : 
      29             : DBG_NAME(SfxItemPoolCache)
      30             : 
      31             : //------------------------------------------------------------------------
      32             : 
      33        2225 : SfxItemPoolCache::SfxItemPoolCache( SfxItemPool *pItemPool,
      34             :                                     const SfxPoolItem *pPutItem ):
      35             :     pPool(pItemPool),
      36        2225 :     pCache(new SfxItemModifyArr_Impl),
      37             :     pSetToPut( 0 ),
      38        4450 :     pItemToPut( &pItemPool->Put(*pPutItem) )
      39             : {
      40             :     DBG_CTOR(SfxItemPoolCache, 0);
      41             :     DBG_ASSERT(pItemPool, "kein Pool angegeben");
      42        2225 : }
      43             : 
      44             : //------------------------------------------------------------------------
      45             : 
      46       30088 : SfxItemPoolCache::SfxItemPoolCache( SfxItemPool *pItemPool,
      47             :                                     const SfxItemSet *pPutSet ):
      48             :     pPool(pItemPool),
      49       30088 :     pCache(new SfxItemModifyArr_Impl),
      50             :     pSetToPut( pPutSet ),
      51       60176 :     pItemToPut( 0 )
      52             : {
      53             :     DBG_CTOR(SfxItemPoolCache, 0);
      54             :     DBG_ASSERT(pItemPool, "kein Pool angegeben");
      55       30088 : }
      56             : 
      57             : //------------------------------------------------------------------------
      58             : 
      59       32313 : SfxItemPoolCache::~SfxItemPoolCache()
      60             : {
      61             :     DBG_DTOR(SfxItemPoolCache, 0);
      62       64684 :     for ( size_t nPos = 0; nPos < pCache->size(); ++nPos ) {
      63       32371 :         pPool->Remove( *(*pCache)[nPos].pPoolItem );
      64       32371 :         pPool->Remove( *(*pCache)[nPos].pOrigItem );
      65             :     }
      66       32313 :     delete pCache; pCache = 0;
      67             : 
      68       32313 :     if ( pItemToPut )
      69        2225 :         pPool->Remove( *pItemToPut );
      70       32313 : }
      71             : 
      72             : //------------------------------------------------------------------------
      73             : 
      74       32783 : const SfxSetItem& SfxItemPoolCache::ApplyTo( const SfxSetItem &rOrigItem, sal_Bool bNew )
      75             : {
      76             :     DBG_CHKTHIS(SfxItemPoolCache, 0);
      77             :     DBG_ASSERT( pPool == rOrigItem.GetItemSet().GetPool(), "invalid Pool" );
      78             :     DBG_ASSERT( IsDefaultItem( &rOrigItem ) || IsPooledItem( &rOrigItem ),
      79             :                 "original not in pool" );
      80             : 
      81             :     // Find whether this Transformations ever occurred
      82       32877 :     for ( size_t nPos = 0; nPos < pCache->size(); ++nPos )
      83             :     {
      84         506 :         SfxItemModifyImpl &rMapEntry = (*pCache)[nPos];
      85         506 :         if ( rMapEntry.pOrigItem == &rOrigItem )
      86             :         {
      87             :             // aendert sich ueberhaupt etwas?
      88         412 :             if ( rMapEntry.pPoolItem != &rOrigItem )
      89             :             {
      90         412 :                 rMapEntry.pPoolItem->AddRef(2); // einen davon fuer den Cache
      91         412 :                 if ( bNew )
      92         412 :                     pPool->Put( rOrigItem );    //! AddRef??
      93             :             }
      94         412 :             return *rMapEntry.pPoolItem;
      95             :         }
      96             :     }
      97             : 
      98             :     // die neue Attributierung in einem neuen Set eintragen
      99       32371 :     SfxSetItem *pNewItem = (SfxSetItem *)rOrigItem.Clone();
     100       32371 :     if ( pItemToPut )
     101             :     {
     102        2225 :         pNewItem->GetItemSet().PutDirect( *pItemToPut );
     103             :         DBG_ASSERT( &pNewItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut,
     104             :                     "wrong item in temporary set" );
     105             :     }
     106             :     else
     107       30146 :         pNewItem->GetItemSet().Put( *pSetToPut );
     108       32371 :     const SfxSetItem* pNewPoolItem = (const SfxSetItem*) &pPool->Put( *pNewItem );
     109             :     DBG_ASSERT( pNewPoolItem != pNewItem, "Pool: rein == raus?" );
     110       32371 :     delete pNewItem;
     111             : 
     112             :     // Refernzzaehler anpassen, je einen davon fuer den Cache
     113       32371 :     pNewPoolItem->AddRef( pNewPoolItem != &rOrigItem ? 2 : 1 );
     114       32371 :     if ( bNew )
     115       32371 :         pPool->Put( rOrigItem );    //! AddRef??
     116             : 
     117             :     // die Transformation im Cache eintragen
     118             :     SfxItemModifyImpl aModify;
     119       32371 :     aModify.pOrigItem = &rOrigItem;
     120       32371 :     aModify.pPoolItem = (SfxSetItem*) pNewPoolItem;
     121       32371 :     pCache->push_back( aModify );
     122             : 
     123             :     DBG_ASSERT( !pItemToPut ||
     124             :                 &pNewPoolItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut,
     125             :                 "wrong item in resulting set" );
     126             : 
     127       32371 :     return *pNewPoolItem;
     128             : }
     129             : 
     130             : 
     131             : 
     132             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10