LibreOffice Module svl (master) 1
itempool.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#pragma once
21
22#include <rtl/ref.hxx>
23#include <svl/poolitem.hxx>
24#include <svl/svldllapi.h>
25#include <svl/typedwhich.hxx>
26#include <svl/whichranges.hxx>
27#include <memory>
28#include <vector>
31
32class SfxBroadcaster;
33struct SfxItemPool_Impl;
34
36{
37 sal_uInt16 _nSID;
39};
40
41class SfxItemPool;
42
51{
52 friend struct SfxItemPool_Impl;
53 friend class SfxItemSet;
54 friend class SfxAllItemSet;
55
57 std::unique_ptr<SfxItemPool_Impl> pImpl;
58
59private:
60 sal_uInt16 GetIndex_Impl(sal_uInt16 nWhich) const;
61 sal_uInt16 GetSize_Impl() const;
62
63 SVL_DLLPRIVATE bool IsItemPoolable_Impl( sal_uInt16 nWhich ) const;
64
65public:
66 // for default SfxItemSet::CTOR, set default WhichRanges
67 void FillItemIdRanges_Impl( WhichRangesContainer& pWhichRanges ) const;
68 const WhichRangesContainer & GetFrozenIdRanges() const;
69
70protected:
71 static inline void ClearRefCount(SfxPoolItem& rItem);
72 static inline void AddRef(const SfxPoolItem& rItem);
73 static inline sal_uInt32 ReleaseRef(const SfxPoolItem& rItem, sal_uInt32 n = 1);
74
75public:
76 SfxItemPool( const SfxItemPool &rPool,
77 bool bCloneStaticDefaults = false );
78 SfxItemPool( const OUString &rName,
79 sal_uInt16 nStart, sal_uInt16 nEnd,
80 const SfxItemInfo *pItemInfos,
81 std::vector<SfxPoolItem*> *pDefaults = nullptr );
82
83public:
84 virtual ~SfxItemPool();
85
86 SfxBroadcaster& BC();
87
88 void SetPoolDefaultItem( const SfxPoolItem& );
89
90 const SfxPoolItem* GetPoolDefaultItem( sal_uInt16 nWhich ) const;
91 template<class T> const T* GetPoolDefaultItem( TypedWhichId<T> nWhich ) const
92 { return static_cast<const T*>(GetPoolDefaultItem(sal_uInt16(nWhich))); }
93
94 void ResetPoolDefaultItem( sal_uInt16 nWhich );
95
96 void SetDefaults(std::vector<SfxPoolItem*>* pDefaults);
97 void ClearDefaults();
98 void ReleaseDefaults( bool bDelete = false );
99 static void ReleaseDefaults( std::vector<SfxPoolItem*> *pDefaults, bool bDelete = false );
100
101 virtual MapUnit GetMetric( sal_uInt16 nWhich ) const;
102 void SetDefaultMetric( MapUnit eNewMetric );
103 MapUnit GetDefaultMetric() const;
104
131 virtual bool GetPresentation( const SfxPoolItem& rItem,
132 MapUnit ePresentationMetric,
133 OUString& rText,
134 const IntlWrapper& rIntlWrapper ) const;
135 virtual rtl::Reference<SfxItemPool> Clone() const;
136 const OUString& GetName() const;
137
138 template<class T> const T& Put( std::unique_ptr<T> xItem, sal_uInt16 nWhich = 0 )
139 { return static_cast<const T&>(PutImpl( *xItem.release(), nWhich, /*bPassingOwnership*/true)); }
140 template<class T> const T& Put( const T& rItem, sal_uInt16 nWhich = 0 )
141 { return static_cast<const T&>(PutImpl( rItem, nWhich, /*bPassingOwnership*/false)); }
142 void Remove( const SfxPoolItem& );
143
144 const SfxPoolItem& GetDefaultItem( sal_uInt16 nWhich ) const;
145 template<class T> const T& GetDefaultItem( TypedWhichId<T> nWhich ) const
146 { return static_cast<const T&>(GetDefaultItem(sal_uInt16(nWhich))); }
147
148 bool CheckItemInPool(const SfxPoolItem *) const;
149
151 {
156 };
157 const SfxPoolItem * GetItem2Default(sal_uInt16 nWhich) const;
158 template<class T> const T* GetItem2Default( TypedWhichId<T> nWhich ) const
159 { return static_cast<const T*>(GetItem2Default(sal_uInt16(nWhich))); }
160
161 sal_uInt32 GetItemCount2(sal_uInt16 nWhich) const;
162 Item2Range GetItemSurrogates(sal_uInt16 nWhich) const;
163 /*
164 This is only valid for SfxPoolItem that override IsSortable and operator<.
165 Returns a range of items defined by using operator<.
166 @param rNeedle must be the same type or a supertype of the pool items for nWhich.
167 */
168 std::vector<const SfxPoolItem*> FindItemSurrogate(sal_uInt16 nWhich, SfxPoolItem const & rNeedle) const;
169
170 sal_uInt16 GetFirstWhich() const;
171 sal_uInt16 GetLastWhich() const;
172 bool IsInRange( sal_uInt16 nWhich ) const;
173 void SetSecondaryPool( SfxItemPool *pPool );
174 SfxItemPool* GetSecondaryPool() const;
175 /* get the last pool by following the GetSecondaryPool chain */
176 SfxItemPool* GetLastPoolInChain();
177 SfxItemPool* GetMasterPool() const;
178 void FreezeIdRanges();
179
180 void Delete();
181
182 bool IsItemPoolable( sal_uInt16 nWhich ) const;
183 bool IsItemPoolable( const SfxPoolItem &rItem ) const
184 { return IsItemPoolable( rItem.Which() ); }
185 void SetItemInfos( const SfxItemInfo *pInfos );
186 sal_uInt16 GetWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
187 template<class T>
188 TypedWhichId<T> GetWhich( TypedWhichId<T> nSlot, bool bDeep = true ) const
189 { return TypedWhichId<T>(GetWhich(sal_uInt16(nSlot), bDeep)); }
190 sal_uInt16 GetSlotId( sal_uInt16 nWhich ) const;
191 sal_uInt16 GetTrueWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
192 sal_uInt16 GetTrueSlotId( sal_uInt16 nWhich ) const;
193
194 static bool IsWhich(sal_uInt16 nId) {
195 return nId && nId <= SFX_WHICH_MAX; }
196 static bool IsSlot(sal_uInt16 nId) {
197 return nId && nId > SFX_WHICH_MAX; }
198
199 void dumpAsXml(xmlTextWriterPtr pWriter) const;
200
201protected:
202 virtual const SfxPoolItem& PutImpl( const SfxPoolItem&, sal_uInt16 nWhich = 0, bool bPassingOwnership = false );
203private:
204 const SfxItemPool& operator=(const SfxItemPool &) = delete;
205
206 //IDs below or equal are Which IDs, IDs above slot IDs
207 static const sal_uInt16 SFX_WHICH_MAX = 4999;
208};
209
210// only the pool may manipulate the reference counts
212{
213 rItem.SetRefCount(0);
214}
215
216// only the pool may manipulate the reference counts
217inline void SfxItemPool::AddRef(const SfxPoolItem& rItem)
218{
219 rItem.AddRef();
220}
221
222// only the pool may manipulate the reference counts
223inline sal_uInt32 SfxItemPool::ReleaseRef(const SfxPoolItem& rItem, sal_uInt32 n)
224{
225 return rItem.ReleaseRef(n);
226}
227
228/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define GetWhich(nSlot)
virtual const SfxPoolItem * PutImpl(const SfxPoolItem &, sal_uInt16 nWhich, bool bPassingOwnership) override
Putting with automatic extension of the WhichId with the ID of the Item.
Definition: itemset.cxx:1411
virtual std::unique_ptr< SfxItemSet > Clone(bool bItems=true, SfxItemPool *pToPool=nullptr) const override
Definition: itemset.cxx:1426
Base class for providers of defaults of SfxPoolItems.
Definition: itempool.hxx:51
const SfxItemPool & operator=(const SfxItemPool &)=delete
TypedWhichId< T > GetWhich(TypedWhichId< T > nSlot, bool bDeep=true) const
Definition: itempool.hxx:188
const SfxItemInfo * pItemInfos
Definition: itempool.hxx:56
static void ClearRefCount(SfxPoolItem &rItem)
Definition: itempool.hxx:211
const T & Put(const T &rItem, sal_uInt16 nWhich=0)
Definition: itempool.hxx:140
const T & Put(std::unique_ptr< T > xItem, sal_uInt16 nWhich=0)
Definition: itempool.hxx:138
static void AddRef(const SfxPoolItem &rItem)
Definition: itempool.hxx:217
const T * GetPoolDefaultItem(TypedWhichId< T > nWhich) const
Definition: itempool.hxx:91
static bool IsWhich(sal_uInt16 nId)
Definition: itempool.hxx:194
const T * GetItem2Default(TypedWhichId< T > nWhich) const
Definition: itempool.hxx:158
std::unique_ptr< SfxItemPool_Impl > pImpl
Definition: itempool.hxx:57
static bool IsSlot(sal_uInt16 nId)
Definition: itempool.hxx:196
bool IsItemPoolable(const SfxPoolItem &rItem) const
Definition: itempool.hxx:183
const T & GetDefaultItem(TypedWhichId< T > nWhich) const
Definition: itempool.hxx:145
static sal_uInt32 ReleaseRef(const SfxPoolItem &rItem, sal_uInt32 n=1)
Definition: itempool.hxx:223
void AddRef(sal_uInt32 n=1) const
Definition: poolitem.hxx:254
void SetRefCount(sal_uInt32 n)
Definition: poolitem.hxx:242
sal_uInt16 Which() const
Definition: poolitem.hxx:149
sal_uInt32 ReleaseRef(sal_uInt32 n=1) const
Definition: poolitem.hxx:261
A very thin wrapper around the sal_uInt16 WhichId whose purpose is mostly to carry type information,...
Definition: typedwhich.hxx:21
std::vector< Value >::const_iterator const_iterator
virtual OUString GetName() const override
struct _xmlTextWriter * xmlTextWriterPtr
bool IsInRange(const WhichRangesContainer &pRange, const sal_uInt16 nId)
sal_Int64 n
MapUnit
sal_Int16 nId
bool _bPoolable
Definition: itempool.hxx:38
sal_uInt16 _nSID
Definition: itempool.hxx:37
o3tl::sorted_vector< SfxPoolItem * >::const_iterator m_begin
Definition: itempool.hxx:152
o3tl::sorted_vector< SfxPoolItem * >::const_iterator m_end
Definition: itempool.hxx:153
o3tl::sorted_vector< SfxPoolItem * >::const_iterator const & begin() const
Definition: itempool.hxx:154
o3tl::sorted_vector< SfxPoolItem * >::const_iterator const & end() const
Definition: itempool.hxx:155
Most of the time, the which ranges we point at are a compile-time literal.
Definition: whichranges.hxx:79
#define SVL_DLLPRIVATE
Definition: svldllapi.h:30
#define SVL_DLLPUBLIC
Definition: svldllapi.h:28