lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / svl / source / inc / poolio.hxx
blob270b1402a11053bb268eda5f6c1c2c06a34e0994
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 .
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>
26 #include <deque>
27 #include <memory>
28 #include <unordered_map>
29 #include <vector>
31 class SfxPoolItem;
32 class SfxItemPoolUser;
34 static const sal_uInt32 SFX_ITEMS_DEFAULT = 0xfffffffe;
36 /**
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;
45 private:
46 std::vector<SfxPoolItem*> maPoolItemVector;
47 public:
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
59 void clear();
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
69 SfxBroadcaster aBC;
70 std::vector<std::unique_ptr<SfxPoolItemArray_Impl>> maPoolItems;
71 std::vector<SfxItemPoolUser*> maSfxItemPoolUsers; /// ObjectUser section
72 OUString aName;
73 std::vector<SfxPoolItem*> maPoolDefaults;
74 std::vector<SfxPoolItem*>* mpStaticDefaults;
75 SfxItemPool* mpMaster;
76 SfxItemPool* mpSecondary;
77 std::unique_ptr<sal_uInt16[]> mpPoolRanges;
78 sal_uInt16 mnStart;
79 sal_uInt16 mnEnd;
80 MapUnit eDefMetric;
82 SfxItemPool_Impl( SfxItemPool* pMaster, const OUString& rName, sal_uInt16 nStart, sal_uInt16 nEnd )
83 : maPoolItems(nEnd - nStart + 1)
84 , aName(rName)
85 , maPoolDefaults(nEnd - nStart + 1)
86 , mpStaticDefaults(nullptr)
87 , mpMaster(pMaster)
88 , mpSecondary(nullptr)
89 , mnStart(nStart)
90 , mnEnd(nEnd)
91 , eDefMetric(MapUnit::MapCM)
93 DBG_ASSERT(mnStart, "Start-Which-Id must be greater 0" );
96 ~SfxItemPool_Impl()
98 DeleteItems();
101 void DeleteItems()
103 maPoolItems.clear();
104 maPoolDefaults.clear();
105 mpPoolRanges.reset();
108 // unit testing
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: */