GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svl / source / items / poolcach.cxx
blob909c33b78c67b30c132f2dcdec944d11a6dd720d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <limits.h>
23 #include <svl/itempool.hxx>
24 #include <svl/itemset.hxx>
25 #include <svl/poolcach.hxx>
27 // STATIC DATA -----------------------------------------------------------
29 DBG_NAME(SfxItemPoolCache)
32 SfxItemPoolCache::SfxItemPoolCache( SfxItemPool *pItemPool,
33 const SfxPoolItem *pPutItem ):
34 pPool(pItemPool),
35 pCache(new SfxItemModifyArr_Impl),
36 pSetToPut( 0 ),
37 pItemToPut( &pItemPool->Put(*pPutItem) )
39 DBG_CTOR(SfxItemPoolCache, 0);
40 DBG_ASSERT(pItemPool, "kein Pool angegeben");
44 SfxItemPoolCache::SfxItemPoolCache( SfxItemPool *pItemPool,
45 const SfxItemSet *pPutSet ):
46 pPool(pItemPool),
47 pCache(new SfxItemModifyArr_Impl),
48 pSetToPut( pPutSet ),
49 pItemToPut( 0 )
51 DBG_CTOR(SfxItemPoolCache, 0);
52 DBG_ASSERT(pItemPool, "kein Pool angegeben");
56 SfxItemPoolCache::~SfxItemPoolCache()
58 DBG_DTOR(SfxItemPoolCache, 0);
59 for ( size_t nPos = 0; nPos < pCache->size(); ++nPos ) {
60 pPool->Remove( *(*pCache)[nPos].pPoolItem );
61 pPool->Remove( *(*pCache)[nPos].pOrigItem );
63 delete pCache; pCache = 0;
65 if ( pItemToPut )
66 pPool->Remove( *pItemToPut );
70 const SfxSetItem& SfxItemPoolCache::ApplyTo( const SfxSetItem &rOrigItem, sal_Bool bNew )
72 DBG_CHKTHIS(SfxItemPoolCache, 0);
73 DBG_ASSERT( pPool == rOrigItem.GetItemSet().GetPool(), "invalid Pool" );
74 DBG_ASSERT( IsDefaultItem( &rOrigItem ) || IsPooledItem( &rOrigItem ),
75 "original not in pool" );
77 // Find whether this Transformations ever occurred
78 for ( size_t nPos = 0; nPos < pCache->size(); ++nPos )
80 SfxItemModifyImpl &rMapEntry = (*pCache)[nPos];
81 if ( rMapEntry.pOrigItem == &rOrigItem )
83 // aendert sich ueberhaupt etwas?
84 if ( rMapEntry.pPoolItem != &rOrigItem )
86 rMapEntry.pPoolItem->AddRef(2); // einen davon fuer den Cache
87 if ( bNew )
88 pPool->Put( rOrigItem ); //! AddRef??
90 return *rMapEntry.pPoolItem;
94 // die neue Attributierung in einem neuen Set eintragen
95 SfxSetItem *pNewItem = (SfxSetItem *)rOrigItem.Clone();
96 if ( pItemToPut )
98 pNewItem->GetItemSet().PutDirect( *pItemToPut );
99 DBG_ASSERT( &pNewItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut,
100 "wrong item in temporary set" );
102 else
103 pNewItem->GetItemSet().Put( *pSetToPut );
104 const SfxSetItem* pNewPoolItem = (const SfxSetItem*) &pPool->Put( *pNewItem );
105 DBG_ASSERT( pNewPoolItem != pNewItem, "Pool: rein == raus?" );
106 delete pNewItem;
108 // Refernzzaehler anpassen, je einen davon fuer den Cache
109 pNewPoolItem->AddRef( pNewPoolItem != &rOrigItem ? 2 : 1 );
110 if ( bNew )
111 pPool->Put( rOrigItem ); //! AddRef??
113 // die Transformation im Cache eintragen
114 SfxItemModifyImpl aModify;
115 aModify.pOrigItem = &rOrigItem;
116 aModify.pPoolItem = (SfxSetItem*) pNewPoolItem;
117 pCache->push_back( aModify );
119 DBG_ASSERT( !pItemToPut ||
120 &pNewPoolItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut,
121 "wrong item in resulting set" );
123 return *pNewPoolItem;
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */