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

Generated by: LCOV version 1.10