Branch data 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 : 5116 : SfxItemPoolCache::SfxItemPoolCache( SfxItemPool *pItemPool,
34 : : const SfxPoolItem *pPutItem ):
35 : : pPool(pItemPool),
36 [ + - ]: 5116 : pCache(new SfxItemModifyArr_Impl),
37 : : pSetToPut( 0 ),
38 : 10232 : pItemToPut( &pItemPool->Put(*pPutItem) )
39 : : {
40 : : DBG_CTOR(SfxItemPoolCache, 0);
41 : : DBG_ASSERT(pItemPool, "kein Pool angegeben");
42 : 5116 : }
43 : :
44 : : //------------------------------------------------------------------------
45 : :
46 : 79448 : SfxItemPoolCache::SfxItemPoolCache( SfxItemPool *pItemPool,
47 : : const SfxItemSet *pPutSet ):
48 : : pPool(pItemPool),
49 [ + - ]: 79448 : pCache(new SfxItemModifyArr_Impl),
50 : : pSetToPut( pPutSet ),
51 : 79448 : pItemToPut( 0 )
52 : : {
53 : : DBG_CTOR(SfxItemPoolCache, 0);
54 : : DBG_ASSERT(pItemPool, "kein Pool angegeben");
55 : 79448 : }
56 : :
57 : : //------------------------------------------------------------------------
58 : :
59 : 84564 : SfxItemPoolCache::~SfxItemPoolCache()
60 : : {
61 : : DBG_DTOR(SfxItemPoolCache, 0);
62 [ + + ]: 169188 : for ( size_t nPos = 0; nPos < pCache->size(); ++nPos ) {
63 : 84624 : pPool->Remove( *(*pCache)[nPos].pPoolItem );
64 : 84624 : pPool->Remove( *(*pCache)[nPos].pOrigItem );
65 : : }
66 [ + - ]: 84564 : delete pCache; pCache = 0;
67 : :
68 [ + + ]: 84564 : if ( pItemToPut )
69 : 5116 : pPool->Remove( *pItemToPut );
70 : 84564 : }
71 : :
72 : : //------------------------------------------------------------------------
73 : :
74 : 85276 : 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 [ + + ]: 85336 : for ( size_t nPos = 0; nPos < pCache->size(); ++nPos )
83 : : {
84 : 712 : SfxItemModifyImpl &rMapEntry = (*pCache)[nPos];
85 [ + + ]: 712 : if ( rMapEntry.pOrigItem == &rOrigItem )
86 : : {
87 : : // aendert sich ueberhaupt etwas?
88 [ + + ]: 652 : if ( rMapEntry.pPoolItem != &rOrigItem )
89 : : {
90 : 522 : rMapEntry.pPoolItem->AddRef(2); // einen davon fuer den Cache
91 [ + - ]: 522 : if ( bNew )
92 [ + - ]: 522 : pPool->Put( rOrigItem ); //! AddRef??
93 : : }
94 : 652 : return *rMapEntry.pPoolItem;
95 : : }
96 : : }
97 : :
98 : : // die neue Attributierung in einem neuen Set eintragen
99 [ + - ]: 84624 : SfxSetItem *pNewItem = (SfxSetItem *)rOrigItem.Clone();
100 [ + + ]: 84624 : if ( pItemToPut )
101 : : {
102 [ + - ]: 5116 : pNewItem->GetItemSet().PutDirect( *pItemToPut );
103 : : DBG_ASSERT( &pNewItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut,
104 : : "wrong item in temporary set" );
105 : : }
106 : : else
107 [ + - ]: 79508 : pNewItem->GetItemSet().Put( *pSetToPut );
108 [ + - ]: 84624 : const SfxSetItem* pNewPoolItem = (const SfxSetItem*) &pPool->Put( *pNewItem );
109 : : DBG_ASSERT( pNewPoolItem != pNewItem, "Pool: rein == raus?" );
110 [ + - ][ + - ]: 84624 : delete pNewItem;
111 : :
112 : : // Refernzzaehler anpassen, je einen davon fuer den Cache
113 [ + + ]: 84624 : pNewPoolItem->AddRef( pNewPoolItem != &rOrigItem ? 2 : 1 );
114 [ + - ]: 84624 : if ( bNew )
115 [ + - ]: 84624 : pPool->Put( rOrigItem ); //! AddRef??
116 : :
117 : : // die Transformation im Cache eintragen
118 : : SfxItemModifyImpl aModify;
119 : 84624 : aModify.pOrigItem = &rOrigItem;
120 : 84624 : aModify.pPoolItem = (SfxSetItem*) pNewPoolItem;
121 [ + - ]: 84624 : pCache->push_back( aModify );
122 : :
123 : : DBG_ASSERT( !pItemToPut ||
124 : : &pNewPoolItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut,
125 : : "wrong item in resulting set" );
126 : :
127 : 85276 : return *pNewPoolItem;
128 : : }
129 : :
130 : :
131 : :
132 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|