LibreOffice Module svl (master) 1
poolcach.cxx
Go to the documentation of this file.
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 <svl/itempool.hxx>
22#include <svl/itemset.hxx>
23#include <svl/setitem.hxx>
24#include <svl/poolcach.hxx>
25#include <tools/debug.hxx>
26
28 const SfxPoolItem *pPutItem ):
29 pPool(pItemPool),
30 pSetToPut( nullptr ),
31 pItemToPut( &pItemPool->Put(*pPutItem) )
32{
33 DBG_ASSERT(pItemPool, "No Pool provided");
34}
35
36
38 const SfxItemSet *pPutSet ):
39 pPool(pItemPool),
40 pSetToPut( pPutSet ),
41 pItemToPut( nullptr )
42{
43 DBG_ASSERT(pItemPool, "No Pool provided");
44}
45
46
48{
49 for (const SfxItemModifyImpl & rImpl : m_aCache) {
50 pPool->Remove( *rImpl.pPoolItem );
51 pPool->Remove( *rImpl.pOrigItem );
52 }
53
54 if ( pItemToPut )
56}
57
58
60{
61 DBG_ASSERT( pPool == rOrigItem.GetItemSet().GetPool(), "invalid Pool" );
62 DBG_ASSERT( IsDefaultItem( &rOrigItem ) || IsPooledItem( &rOrigItem ),
63 "original not in pool" );
64
65 // Find whether this Transformations ever occurred
66 for (const SfxItemModifyImpl & rMapEntry : m_aCache)
67 {
68 if ( rMapEntry.pOrigItem == &rOrigItem )
69 {
70 // Did anything change at all?
71 if ( rMapEntry.pPoolItem != &rOrigItem )
72 {
73 rMapEntry.pPoolItem->AddRef(2); // One for the cache
74 pPool->Put( rOrigItem ); //FIXME: AddRef?
75 }
76 return *rMapEntry.pPoolItem;
77 }
78 }
79
80 // Insert the new attributes in a new Set
81 std::unique_ptr<SfxSetItem> pNewItem(rOrigItem.Clone());
82 if ( pItemToPut )
83 {
84 pNewItem->GetItemSet().PutDirect( *pItemToPut );
85 DBG_ASSERT( &pNewItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut,
86 "wrong item in temporary set" );
87 }
88 else
89 pNewItem->GetItemSet().Put( *pSetToPut );
90 const SfxSetItem* pNewPoolItem = &pPool->Put( std::move(pNewItem) );
91
92 // Adapt refcount; one each for the cache
93 pNewPoolItem->AddRef( pNewPoolItem != &rOrigItem ? 2 : 1 );
94 pPool->Put( rOrigItem ); //FIXME: AddRef?
95
96 // Add the transformation to the cache
97 SfxItemModifyImpl aModify;
98 aModify.pOrigItem = &rOrigItem;
99 aModify.pPoolItem = const_cast<SfxSetItem*>(pNewPoolItem);
100 m_aCache.push_back( aModify );
101
103 &pNewPoolItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut,
104 "wrong item in resulting set" );
105
106 return *pNewPoolItem;
107}
108
109
110/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< SfxItemModifyImpl > m_aCache
Definition: poolcach.hxx:40
SfxItemPool * pPool
Definition: poolcach.hxx:38
SfxItemPoolCache(SfxItemPool *pPool, const SfxPoolItem *pPutItem)
Definition: poolcach.cxx:27
const SfxItemSet * pSetToPut
Definition: poolcach.hxx:41
const SfxPoolItem * pItemToPut
Definition: poolcach.hxx:42
const SfxSetItem & ApplyTo(const SfxSetItem &rSetItem)
Definition: poolcach.cxx:59
Base class for providers of defaults of SfxPoolItems.
Definition: itempool.hxx:51
const T & Put(std::unique_ptr< T > xItem, sal_uInt16 nWhich=0)
Definition: itempool.hxx:138
void Remove(const SfxPoolItem &)
Definition: itempool.cxx:751
SfxItemPool * GetPool() const
Definition: itemset.hxx:202
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
Definition: itemset.cxx:795
void AddRef(sal_uInt32 n=1) const
Definition: poolitem.hxx:254
sal_uInt16 Which() const
Definition: poolitem.hxx:149
const SfxItemSet & GetItemSet() const
Definition: setitem.hxx:47
virtual SfxSetItem * Clone(SfxItemPool *pPool=nullptr) const override=0
#define DBG_ASSERT(sCon, aError)
Put
bool IsDefaultItem(const SfxPoolItem *pItem)
Definition: poolitem.hxx:279
bool IsPooledItem(const SfxPoolItem *pItem)
Definition: poolitem.hxx:284