LibreOffice Module svl (master) 1
poolio.hxx
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#ifndef INCLUDED_SVL_SOURCE_INC_POOLIO_HXX
21#define INCLUDED_SVL_SOURCE_INC_POOLIO_HXX
22
23#include <rtl/ref.hxx>
24#include <svl/itempool.hxx>
26#include <tools/debug.hxx>
27#include <memory>
29#include <utility>
30
31class SfxPoolItem;
32class SfxItemPoolUser;
33
34const sal_uInt32 SFX_ITEMS_DEFAULT = 0xfffffffe;
35
36static bool CompareSortablePoolItems(SfxPoolItem const* lhs, SfxPoolItem const* rhs)
37{
38 return (*lhs) < (*rhs);
39}
47{
48private:
50 // In some cases, e.g. subclasses of NameOrIndex, the parent class (NameOrIndex) is sortable,
51 // but the subclasses do not define an operator<, which means that we don't get an ordering
52 // strong enough to enforce uniqueness purely with operator<, which means we need to do
53 // a partial scan with operator==
54 std::vector<SfxPoolItem*> maSortablePoolItems;
55public:
60 void clear();
61 size_t size() const {return maPoolItemSet.size();}
62 bool empty() const {return maPoolItemSet.empty();}
64 void insert(SfxPoolItem* pItem)
65 {
66 bool bInserted = maPoolItemSet.insert(pItem).second;
67 assert( bInserted && "duplicate item?" );
68 (void)bInserted;
69
70 if (pItem->IsSortable())
71 {
72 // bail early if someone modified one of these things underneath me
73 assert( std::is_sorted_until(maSortablePoolItems.begin(), maSortablePoolItems.end(), CompareSortablePoolItems) == maSortablePoolItems.end());
74
75 auto it = std::lower_bound(maSortablePoolItems.begin(), maSortablePoolItems.end(), pItem, CompareSortablePoolItems);
76 maSortablePoolItems.insert(maSortablePoolItems.begin() + (it - maSortablePoolItems.begin()), pItem);
77 }
78 }
79 const SfxPoolItem* findByLessThan(const SfxPoolItem* pNeedle) const
80 {
81 // bail early if someone modified one of these things underneath me
82 assert( std::is_sorted_until(maSortablePoolItems.begin(), maSortablePoolItems.end(), CompareSortablePoolItems) == maSortablePoolItems.end());
83 assert( maPoolItemSet.empty() || maPoolItemSet.front()->IsSortable() );
84
85 auto it = std::lower_bound(maSortablePoolItems.begin(), maSortablePoolItems.end(), pNeedle, CompareSortablePoolItems);
86 for (;;)
87 {
88 if (it == maSortablePoolItems.end())
89 return nullptr;
90 if (*pNeedle < **it)
91 return nullptr;
92 if (*pNeedle == **it)
93 return *it;
94 ++it;
95 }
96 }
97 std::vector<const SfxPoolItem*> findSurrogateRange(const SfxPoolItem* pNeedle) const
98 {
99 std::vector<const SfxPoolItem*> rv;
100 if (!maSortablePoolItems.empty())
101 {
102 // bail early if someone modified one of these things underneath me
103 assert( std::is_sorted_until(maSortablePoolItems.begin(), maSortablePoolItems.end(), CompareSortablePoolItems) == maSortablePoolItems.end());
104
105 auto range = std::equal_range(maSortablePoolItems.begin(), maSortablePoolItems.end(), pNeedle, CompareSortablePoolItems);
106 rv.reserve(std::distance(range.first, range.second));
107 for (auto it = range.first; it != range.second; ++it)
108 rv.push_back(*it);
109 }
110 else
111 {
112 for (const SfxPoolItem* p : maPoolItemSet)
113 if (*pNeedle == *p)
114 rv.push_back(p);
115 }
116 return rv;
117 }
119 {
120 auto pNeedle = *it;
121 if ((*it)->IsSortable())
122 {
123 // bail early if someone modified one of these things underneath me
124 assert( std::is_sorted_until(maSortablePoolItems.begin(), maSortablePoolItems.end(), CompareSortablePoolItems) == maSortablePoolItems.end());
125
126 auto sortIt = std::lower_bound(maSortablePoolItems.begin(), maSortablePoolItems.end(), pNeedle, CompareSortablePoolItems);
127 for (;;)
128 {
129 if (sortIt == maSortablePoolItems.end())
130 {
131 assert(false && "did not find item?");
132 break;
133 }
134 if (*pNeedle < **sortIt)
135 {
136 assert(false && "did not find item?");
137 break;
138 }
139 // need to compare by pointer here, since we might have duplicates
140 if (*sortIt == pNeedle)
141 {
142 maSortablePoolItems.erase(sortIt);
143 break;
144 }
145 ++sortIt;
146 }
147 }
149 }
150};
151
153{
155 std::vector<SfxPoolItemArray_Impl> maPoolItemArrays;
156 OUString aName;
157 std::vector<SfxPoolItem*> maPoolDefaults;
158 std::vector<SfxPoolItem*>* mpStaticDefaults;
162 sal_uInt16 mnStart;
163 sal_uInt16 mnEnd;
165
166 SfxItemPool_Impl( SfxItemPool* pMaster, OUString _aName, sal_uInt16 nStart, sal_uInt16 nEnd )
167 : maPoolItemArrays(nEnd - nStart + 1)
168 , aName(std::move(_aName))
169 , maPoolDefaults(nEnd - nStart + 1)
170 , mpStaticDefaults(nullptr)
171 , mpMaster(pMaster)
172 , mnStart(nStart)
173 , mnEnd(nEnd)
175 {
176 DBG_ASSERT(mnStart, "Start-Which-Id must be greater 0" );
177 }
178
180 {
181 DeleteItems();
182 }
183
185 {
186 maPoolItemArrays.clear();
187 maPoolDefaults.clear();
189 }
190
191 // unit testing
192 friend class PoolItemTest;
193 static SfxItemPool_Impl *GetImpl(SfxItemPool const *pPool) { return pPool->pImpl.get(); }
194};
195
196
197#define SFX_ITEMPOOL_VER_MAJOR sal_uInt8(2)
198#define SFX_ITEMPOOL_VER_MINOR sal_uInt8(0)
199
200#define SFX_ITEMPOOL_TAG_STARTPOOL_4 sal_uInt16(0x1111)
201#define SFX_ITEMPOOL_TAG_STARTPOOL_5 sal_uInt16(0xBBBB)
202#define SFX_ITEMPOOL_TAG_TRICK4OLD sal_uInt16(0xFFFF)
203
204#define SFX_ITEMPOOL_REC sal_uInt8(0x01)
205#define SFX_ITEMPOOL_REC_HEADER sal_uInt8(0x10)
206#define SFX_ITEMPOOL_REC_VERSIONMAP sal_uInt16(0x0020)
207#define SFX_ITEMPOOL_REC_WHICHIDS sal_uInt16(0x0030)
208#define SFX_ITEMPOOL_REC_ITEMS sal_uInt16(0x0040)
209#define SFX_ITEMPOOL_REC_DEFAULTS sal_uInt16(0x0050)
210
211#endif // INCLUDED_SVL_SOURCE_INC_POOLIO_HXX
212
213/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class for providers of defaults of SfxPoolItems.
Definition: itempool.hxx:51
std::unique_ptr< SfxItemPool_Impl > pImpl
Definition: itempool.hxx:57
virtual bool IsSortable() const
Definition: poolitem.hxx:190
const_iterator begin() const
std::vector< Value >::const_iterator const_iterator
const_iterator find(const Value &x) const
size_type erase(const Value &x)
bool empty() const
const_iterator end() const
size_type size() const
const Value & front() const
std::pair< const_iterator, bool > insert(Value &&x)
#define DBG_ASSERT(sCon, aError)
void * p
MapUnit
const sal_uInt32 SFX_ITEMS_DEFAULT
Definition: poolio.hxx:34
static bool CompareSortablePoolItems(SfxPoolItem const *lhs, SfxPoolItem const *rhs)
Definition: poolio.hxx:36
friend class PoolItemTest
Definition: poolio.hxx:192
void DeleteItems()
Definition: poolio.hxx:184
sal_uInt16 mnEnd
Definition: poolio.hxx:163
std::vector< SfxPoolItemArray_Impl > maPoolItemArrays
Definition: poolio.hxx:155
static SfxItemPool_Impl * GetImpl(SfxItemPool const *pPool)
Definition: poolio.hxx:193
rtl::Reference< SfxItemPool > mpSecondary
Definition: poolio.hxx:160
OUString aName
Definition: poolio.hxx:156
SfxItemPool_Impl(SfxItemPool *pMaster, OUString _aName, sal_uInt16 nStart, sal_uInt16 nEnd)
Definition: poolio.hxx:166
WhichRangesContainer mpPoolRanges
Definition: poolio.hxx:161
std::vector< SfxPoolItem * > * mpStaticDefaults
Definition: poolio.hxx:158
std::vector< SfxPoolItem * > maPoolDefaults
Definition: poolio.hxx:157
sal_uInt16 mnStart
Definition: poolio.hxx:162
SfxBroadcaster aBC
Definition: poolio.hxx:154
MapUnit eDefMetric
Definition: poolio.hxx:164
SfxItemPool * mpMaster
Definition: poolio.hxx:159
This array contains a set of SfxPoolItems, if those items are poolable then each item has a unique se...
Definition: poolio.hxx:47
std::vector< SfxPoolItem * > maSortablePoolItems
Definition: poolio.hxx:54
size_t size() const
Definition: poolio.hxx:61
o3tl::sorted_vector< SfxPoolItem * > maPoolItemSet
Definition: poolio.hxx:49
bool empty() const
Definition: poolio.hxx:62
o3tl::sorted_vector< SfxPoolItem * >::const_iterator find(SfxPoolItem *pItem) const
Definition: poolio.hxx:63
void insert(SfxPoolItem *pItem)
Definition: poolio.hxx:64
o3tl::sorted_vector< SfxPoolItem * >::const_iterator begin() const
Definition: poolio.hxx:56
const SfxPoolItem * findByLessThan(const SfxPoolItem *pNeedle) const
Definition: poolio.hxx:79
o3tl::sorted_vector< SfxPoolItem * >::const_iterator end() const
Definition: poolio.hxx:57
std::vector< const SfxPoolItem * > findSurrogateRange(const SfxPoolItem *pNeedle) const
Definition: poolio.hxx:97
void clear()
clear array of PoolItem variants after all PoolItems are deleted or all ref counts are decreased
Definition: itempool.cxx:91
void erase(o3tl::sorted_vector< SfxPoolItem * >::const_iterator it)
Definition: poolio.hxx:118
Most of the time, the which ranges we point at are a compile-time literal.
Definition: whichranges.hxx:79