1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #ifndef INCLUDED_SVL_SOURCE_INC_POOLIO_HXX
21 #define INCLUDED_SVL_SOURCE_INC_POOLIO_HXX
23 #include <svl/itempool.hxx>
24 #include <svl/SfxBroadcaster.hxx>
25 #include <tools/debug.hxx>
28 #include <unordered_map>
32 class SfxItemPoolUser
;
34 static const sal_uInt32 SFX_ITEMS_DEFAULT
= 0xfffffffe;
37 * This array contains a set of SfxPoolItems, if those items are
38 * poolable then each item has a unique set of properties, and we
39 * often search linearly to ensure uniqueness. If they are
40 * non-poolable we maintain an (often large) list of pointers.
42 struct SfxPoolItemArray_Impl
44 typedef std::unordered_map
<SfxPoolItem
*,sal_uInt32
> PoolItemPtrToIndexMap
;
46 std::vector
<SfxPoolItem
*> maPoolItemVector
;
48 /// Track list of indices into our array that contain an empty slot
49 std::vector
<sal_uInt32
> maFree
;
50 /// Hash of SfxPoolItem pointer to index into our array that contains that slot
51 PoolItemPtrToIndexMap maPtrToIndex
;
53 SfxPoolItemArray_Impl () {}
54 SfxPoolItem
*& operator[](size_t n
) {return maPoolItemVector
[n
];}
55 std::vector
<SfxPoolItem
*>::iterator
begin() {return maPoolItemVector
.begin();}
56 std::vector
<SfxPoolItem
*>::iterator
end() {return maPoolItemVector
.end();}
57 /// clear array of PoolItem variants after all PoolItems are deleted
58 /// or all ref counts are decreased
60 size_t size() const {return maPoolItemVector
.size();}
61 void push_back(SfxPoolItem
* pItem
) {maPoolItemVector
.push_back(pItem
);}
63 /// re-build the list of free slots and hash from clean
64 void SVL_DLLPUBLIC
ReHash();
67 struct SfxItemPool_Impl
70 std::vector
<std::unique_ptr
<SfxPoolItemArray_Impl
>> maPoolItems
;
71 std::vector
<SfxItemPoolUser
*> maSfxItemPoolUsers
; /// ObjectUser section
73 std::vector
<SfxPoolItem
*> maPoolDefaults
;
74 std::vector
<SfxPoolItem
*>* mpStaticDefaults
;
75 SfxItemPool
* mpMaster
;
76 SfxItemPool
* mpSecondary
;
77 std::unique_ptr
<sal_uInt16
[]> mpPoolRanges
;
82 SfxItemPool_Impl( SfxItemPool
* pMaster
, const OUString
& rName
, sal_uInt16 nStart
, sal_uInt16 nEnd
)
83 : maPoolItems(nEnd
- nStart
+ 1)
85 , maPoolDefaults(nEnd
- nStart
+ 1)
86 , mpStaticDefaults(nullptr)
88 , mpSecondary(nullptr)
91 , eDefMetric(MapUnit::MapCM
)
93 DBG_ASSERT(mnStart
, "Start-Which-Id must be greater 0" );
104 maPoolDefaults
.clear();
105 mpPoolRanges
.reset();
109 friend class PoolItemTest
;
110 static SfxItemPool_Impl
*GetImpl(SfxItemPool
const *pPool
) { return pPool
->pImpl
.get(); }
114 #define SFX_ITEMPOOL_VER_MAJOR sal_uInt8(2)
115 #define SFX_ITEMPOOL_VER_MINOR sal_uInt8(0)
117 #define SFX_ITEMPOOL_TAG_STARTPOOL_4 sal_uInt16(0x1111)
118 #define SFX_ITEMPOOL_TAG_STARTPOOL_5 sal_uInt16(0xBBBB)
119 #define SFX_ITEMPOOL_TAG_TRICK4OLD sal_uInt16(0xFFFF)
121 #define SFX_ITEMPOOL_REC sal_uInt8(0x01)
122 #define SFX_ITEMPOOL_REC_HEADER sal_uInt8(0x10)
123 #define SFX_ITEMPOOL_REC_VERSIONMAP sal_uInt16(0x0020)
124 #define SFX_ITEMPOOL_REC_WHICHIDS sal_uInt16(0x0030)
125 #define SFX_ITEMPOOL_REC_ITEMS sal_uInt16(0x0040)
126 #define SFX_ITEMPOOL_REC_DEFAULTS sal_uInt16(0x0050)
128 #endif // INCLUDED_SVL_SOURCE_INC_POOLIO_HXX
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */