LibreOffice Module sc (master) 1
bcaslot.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 <memory>
23#include <map>
24#include <unordered_set>
25
26#include <svl/broadcast.hxx>
27#include <svl/hint.hxx>
28#include <tools/solar.h>
29
30#include <document.hxx>
31#include <global.hxx>
32
33namespace sc { class ColumnSpanSet; }
34class ScHint;
35
36namespace sc {
37
39{
43};
44
45}
46
52{
53private:
58
61
62public:
64 const ScBroadcastArea& operator=(const ScBroadcastArea&) = delete;
65
66 ScBroadcastArea( const ScRange& rRange );
67
69 const SvtBroadcaster& GetBroadcaster() const { return aBroadcaster; }
70 void UpdateRange( const ScRange& rNewRange )
71 { aRange = rNewRange; }
72 const ScRange& GetRange() const { return aRange; }
73 void IncRef() { ++nRefCount; }
74 sal_uLong DecRef() { return nRefCount ? --nRefCount : 0; }
75 sal_uLong GetRef() const { return nRefCount; }
78 bool IsInUpdateChain() const { return mbInUpdateChain; }
79 void SetInUpdateChain( bool b ) { mbInUpdateChain = b; }
80
81 bool IsGroupListening() const { return mbGroupListening; }
82 void SetGroupListening( bool b ) { mbGroupListening = b; }
83
85 inline bool operator==( const ScBroadcastArea & rArea ) const;
86};
87
88inline bool ScBroadcastArea::operator==( const ScBroadcastArea & rArea ) const
89{
90 return aRange == rArea.aRange && mbGroupListening == rArea.mbGroupListening;
91}
92
94{
96 mutable bool mbErasure;
97
99};
100
102{
103 size_t operator()( const ScBroadcastAreaEntry& rEntry ) const
104 {
105 return rEntry.mpArea->GetRange().hashArea() + static_cast<size_t>(rEntry.mpArea->IsGroupListening());
106 }
107};
108
110{
111 bool operator()( const ScBroadcastAreaEntry& rEntry1, const ScBroadcastAreaEntry& rEntry2) const
112 {
113 return *rEntry1.mpArea == *rEntry2.mpArea;
114 }
115};
116
117typedef std::unordered_set< ScBroadcastAreaEntry, ScBroadcastAreaHash, ScBroadcastAreaEqual > ScBroadcastAreas;
118
120{
121 size_t operator()( const ScBroadcastArea* p ) const
122 {
123 return reinterpret_cast<size_t>(p);
124 }
125};
126
128{
129 bool operator()( const ScBroadcastArea* p1, const ScBroadcastArea* p2) const
130 {
131 return p1 == p2;
132 }
133};
134
135typedef std::unordered_set< const ScBroadcastArea*, ScBroadcastAreaBulkHash,
137
139
142{
143private:
145 mutable ScBroadcastArea aTmpSeekBroadcastArea; // for FindBroadcastArea()
149
158
159 ScBroadcastAreas::iterator FindBroadcastArea( const ScRange& rRange, bool bGroupListening );
160
170
172 void FinallyEraseAreas();
173
174 static bool isMarkedErased( const ScBroadcastAreas::const_iterator& rIter )
175 {
176 return rIter->mbErasure;
177 }
178
179public:
183
202 const ScRange& rRange, bool bGroupListening, SvtListener* pListener, ScBroadcastArea*& rpArea );
203
209
210 void EndListeningArea(
211 const ScRange& rRange, bool bGroupListening, SvtListener* pListener, ScBroadcastArea*& rpArea );
212
213 bool AreaBroadcast( const ScRange& rRange, SfxHintId nHint );
214 bool AreaBroadcast( const ScHint& rHint );
215 void DelBroadcastAreasInRange( const ScRange& rRange );
216 void UpdateRemove( UpdateRefMode eUpdateRefMode,
217 const ScRange& rRange,
218 SCCOL nDx, SCROW nDy, SCTAB nDz );
219 void UpdateRemoveArea( ScBroadcastArea* pArea );
220 void UpdateInsert( ScBroadcastArea* pArea );
221
223
230 void EraseArea( ScBroadcastAreas::iterator& rIter );
231
232 void GetAllListeners(
233 const ScRange& rRange, std::vector<sc::AreaListener>& rListeners,
235
236#if DEBUG_AREA_BROADCASTER
237 void Dump() const;
238#endif
239};
240
246{
247private:
248 typedef std::map<ScBroadcastArea*, sc::ColumnSpanSet> BulkGroupAreasType;
249
263 {
264 public:
265 TableSlots(SCSIZE nBcaSlots);
266 TableSlots(TableSlots&&) noexcept;
267 ~TableSlots();
268 ScBroadcastAreaSlot** getSlots() const { return ppSlots.get(); }
269
270 private:
272 std::unique_ptr<ScBroadcastAreaSlot*[]> ppSlots;
273
274 TableSlots( const TableSlots& ) = delete;
275 TableSlots& operator=( const TableSlots& ) = delete;
276 };
277
278 typedef ::std::map< SCTAB, TableSlots > TableSlotsMap;
279
280 typedef ::std::vector< ::std::pair< ScBroadcastAreaSlot*, ScBroadcastAreas::iterator > > AreasToBeErased;
281
282private:
284 {
285 SCROW nStartRow; // first row of this segment
286 SCROW nStopRow; // first row of next segment
287 SCSIZE nSliceRow; // row slice size in this segment
288 SCSIZE nCumulatedRow; // cumulated slots of previous segments (previous rows)
289 SCROW nStartCol; // first column of this segment
290 SCROW nStopCol; // first column of next segment
291 SCSIZE nSliceCol; // column slice size in this segment
292 SCSIZE nCumulatedCol; // cumulated slots of previous segments (previous columns)
293
294 ScSlotData( SCROW r1, SCROW r2, SCSIZE sr, SCSIZE cr, SCCOL c1, SCCOL c2, SCSIZE sc, SCSIZE cc )
295 : nStartRow(r1)
296 , nStopRow(r2)
297 , nSliceRow(sr)
298 , nCumulatedRow(cr)
299 , nStartCol(c1)
300 , nStopCol(c2)
301 , nSliceCol(sc)
302 , nCumulatedCol(cc) {}
303 };
304 typedef ::std::vector< ScSlotData > ScSlotDistribution;
312 std::unique_ptr<SvtBroadcaster> pBCAlways; // for the RC_ALWAYS special range
317
318 inline SCSIZE ComputeSlotOffset( const ScAddress& rAddress ) const;
319 void ComputeAreaPoints( const ScRange& rRange,
320 SCSIZE& nStart, SCSIZE& nEnd,
321 SCSIZE& nRowBreak ) const;
322#ifdef DBG_UTIL
323 void DoChecks();
324#endif
325
326public:
330 const ScRange& rRange, bool bGroupListening, SvtListener* pListener );
331
332 void EndListeningArea(
333 const ScRange& rRange, bool bGroupListening, SvtListener* pListener );
334
335 bool AreaBroadcast( const ScRange& rRange, SfxHintId nHint );
336 bool AreaBroadcast( const ScHint& rHint ) const;
337 // return: at least one broadcast occurred
338 void DelBroadcastAreasInRange( const ScRange& rRange );
339 void UpdateBroadcastAreas( UpdateRefMode eUpdateRefMode,
340 const ScRange& rRange,
341 SCCOL nDx, SCROW nDy, SCTAB nDz );
342 void EnterBulkBroadcast();
343 void LeaveBulkBroadcast( SfxHintId nHintId );
344 bool InsertBulkArea( const ScBroadcastArea* p );
345
346 void InsertBulkGroupArea( ScBroadcastArea* pArea, const ScRange& rRange );
348 bool BulkBroadcastGroupAreas( SfxHintId nHintId );
349
351 size_t RemoveBulkArea( const ScBroadcastArea* p );
355 bool IsInBulkBroadcast() const { return nInBulkBroadcast > 0; }
356
357 // only for ScBroadcastAreaSlot
359 ScBroadcastAreas::iterator& rIter );
360 // only for ScBroadcastAreaSlot
362
363 std::vector<sc::AreaListener> GetAllListeners(
364 const ScRange& rRange, sc::AreaOverlapType eType,
366
367#if DEBUG_AREA_BROADCASTER
368 void Dump() const;
369#endif
370};
371
373{
376
381
382public:
384 pBASM(p),
385 mnHintId(nHintId)
386 {
387 if (pBASM)
389 }
390 ~ScBulkBroadcast() COVERITY_NOEXCEPT_FALSE
391 {
392 if (pBASM)
394 }
395};
396
397/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:44
std::unordered_set< const ScBroadcastArea *, ScBroadcastAreaBulkHash, ScBroadcastAreaBulkEqual > ScBroadcastAreasBulk
Definition: bcaslot.hxx:136
std::unordered_set< ScBroadcastAreaEntry, ScBroadcastAreaHash, ScBroadcastAreaEqual > ScBroadcastAreas
Definition: bcaslot.hxx:117
Slot offset arrangement of columns and rows, once per sheet.
Definition: bcaslot.hxx:263
ScBroadcastAreaSlot ** getSlots() const
Definition: bcaslot.hxx:268
std::unique_ptr< ScBroadcastAreaSlot *[]> ppSlots
Definition: bcaslot.hxx:272
TableSlots(const TableSlots &)=delete
TableSlots & operator=(const TableSlots &)=delete
BroadcastAreaSlots and their management, once per document.
Definition: bcaslot.hxx:246
bool BulkBroadcastGroupAreas(SfxHintId nHintId)
Definition: bcaslot.cxx:1191
ScBroadcastAreaSlotMachine(ScDocument *pDoc)
Definition: bcaslot.cxx:571
void ComputeAreaPoints(const ScRange &rRange, SCSIZE &nStart, SCSIZE &nEnd, SCSIZE &nRowBreak) const
Definition: bcaslot.cxx:663
BulkGroupAreasType m_BulkGroupAreas
Definition: bcaslot.hxx:309
AreasToBeErased maAreasToBeErased
Definition: bcaslot.hxx:311
void FinallyEraseAreas(ScBroadcastAreaSlot *pSlot)
Definition: bcaslot.cxx:1238
void LeaveBulkBroadcast(SfxHintId nHintId)
Definition: bcaslot.cxx:1156
ScBroadcastArea * GetEOUpdateChain() const
Definition: bcaslot.hxx:353
std::unique_ptr< SvtBroadcaster > pBCAlways
Definition: bcaslot.hxx:312
void SetEOUpdateChain(ScBroadcastArea *p)
Definition: bcaslot.hxx:354
std::vector< sc::AreaListener > GetAllListeners(const ScRange &rRange, sc::AreaOverlapType eType, sc::ListenerGroupType eGroup=sc::ListenerGroupType::Both)
Definition: bcaslot.cxx:1259
TableSlotsMap aTableSlotsMap
Definition: bcaslot.hxx:310
bool IsInBulkBroadcast() const
Definition: bcaslot.hxx:355
ScSlotDistribution maSlotDistribution
Definition: bcaslot.hxx:305
void StartListeningArea(const ScRange &rRange, bool bGroupListening, SvtListener *pListener)
Definition: bcaslot.cxx:777
ScBroadcastAreasBulk aBulkBroadcastAreas
Definition: bcaslot.hxx:308
void UpdateBroadcastAreas(UpdateRefMode eUpdateRefMode, const ScRange &rRange, SCCOL nDx, SCROW nDy, SCTAB nDz)
Definition: bcaslot.cxx:977
::std::map< SCTAB, TableSlots > TableSlotsMap
Definition: bcaslot.hxx:278
void EndListeningArea(const ScRange &rRange, bool bGroupListening, SvtListener *pListener)
Definition: bcaslot.cxx:828
bool InsertBulkArea(const ScBroadcastArea *p)
Definition: bcaslot.cxx:1173
size_t RemoveBulkArea(const ScBroadcastArea *p)
Definition: bcaslot.cxx:1222
::std::vector< ScSlotData > ScSlotDistribution
Definition: bcaslot.hxx:304
void DelBroadcastAreasInRange(const ScRange &rRange)
Definition: bcaslot.cxx:940
ScBroadcastArea * pEOUpdateChain
Definition: bcaslot.hxx:315
ScBroadcastArea * pUpdateChain
Definition: bcaslot.hxx:314
std::map< ScBroadcastArea *, sc::ColumnSpanSet > BulkGroupAreasType
Definition: bcaslot.hxx:248
bool AreaBroadcast(const ScRange &rRange, SfxHintId nHint)
Definition: bcaslot.cxx:879
::std::vector< ::std::pair< ScBroadcastAreaSlot *, ScBroadcastAreas::iterator > > AreasToBeErased
Definition: bcaslot.hxx:280
void RemoveBulkGroupArea(ScBroadcastArea *pArea)
Definition: bcaslot.cxx:1227
void SetUpdateChain(ScBroadcastArea *p)
Definition: bcaslot.hxx:352
void PushAreaToBeErased(ScBroadcastAreaSlot *pSlot, ScBroadcastAreas::iterator &rIter)
Definition: bcaslot.cxx:1232
void InsertBulkGroupArea(ScBroadcastArea *pArea, const ScRange &rRange)
Definition: bcaslot.cxx:1178
SCSIZE ComputeSlotOffset(const ScAddress &rAddress) const
Definition: bcaslot.cxx:635
Collection of BroadcastAreas.
Definition: bcaslot.hxx:142
ScBroadcastAreas::iterator FindBroadcastArea(const ScRange &rRange, bool bGroupListening)
Definition: bcaslot.cxx:180
bool IsInBroadcastIteration() const
Definition: bcaslot.hxx:222
void UpdateRemove(UpdateRefMode eUpdateRefMode, const ScRange &rRange, SCCOL nDx, SCROW nDy, SCTAB nDz)
Definition: bcaslot.cxx:340
bool mbInBroadcastIteration
Definition: bcaslot.hxx:148
ScBroadcastArea aTmpSeekBroadcastArea
Definition: bcaslot.hxx:145
ScBroadcastAreas aBroadcastAreaTbl
Definition: bcaslot.hxx:144
void FinallyEraseAreas()
Finally erase all areas pushed as to-be-erased.
Definition: bcaslot.cxx:544
bool AreaBroadcast(const ScRange &rRange, SfxHintId nHint)
Definition: bcaslot.cxx:210
static bool isMarkedErased(const ScBroadcastAreas::const_iterator &rIter)
Definition: bcaslot.hxx:174
void UpdateRemoveArea(ScBroadcastArea *pArea)
Definition: bcaslot.cxx:384
ScBroadcastAreaSlot(ScDocument *pDoc, ScBroadcastAreaSlotMachine *pBASM)
Definition: bcaslot.cxx:45
void DelBroadcastAreasInRange(const ScRange &rRange)
Definition: bcaslot.cxx:316
ScDocument * pDoc
Definition: bcaslot.hxx:146
bool StartListeningArea(const ScRange &rRange, bool bGroupListening, SvtListener *pListener, ScBroadcastArea *&rpArea)
Only here new ScBroadcastArea objects are created, prevention of dupes.
Definition: bcaslot.cxx:92
void InsertListeningArea(ScBroadcastArea *pArea)
Insert a ScBroadcastArea obtained via StartListeningArea() to subsequent slots.
Definition: bcaslot.cxx:136
ScBroadcastAreaSlotMachine * pBASM
Definition: bcaslot.hxx:147
void EraseArea(ScBroadcastAreas::iterator &rIter)
Erase an area from set and delete it if last reference, or if mbInBroadcastIteration is set push it t...
Definition: bcaslot.cxx:421
ScDocument::HardRecalcState CheckHardRecalcStateCondition() const
More hypothetical (memory would probably be doomed anyway) check whether there would be an overflow w...
Definition: bcaslot.cxx:71
void UpdateInsert(ScBroadcastArea *pArea)
Definition: bcaslot.cxx:398
bool mbHasErasedArea
If true, the slot has at least one area broadcaster marked for removal.
Definition: bcaslot.hxx:157
void EndListeningArea(const ScRange &rRange, bool bGroupListening, SvtListener *pListener, ScBroadcastArea *&rpArea)
Definition: bcaslot.cxx:147
void GetAllListeners(const ScRange &rRange, std::vector< sc::AreaListener > &rListeners, sc::AreaOverlapType eType, sc::ListenerGroupType eGroup)
Definition: bcaslot.cxx:442
Used in a Unique Associative Container.
Definition: bcaslot.hxx:52
ScBroadcastArea * GetUpdateChainNext() const
Definition: bcaslot.hxx:76
bool mbGroupListening
Definition: bcaslot.hxx:60
const ScRange & GetRange() const
Definition: bcaslot.hxx:72
bool IsInUpdateChain() const
Definition: bcaslot.hxx:78
const SvtBroadcaster & GetBroadcaster() const
Definition: bcaslot.hxx:69
bool mbInUpdateChain
Definition: bcaslot.hxx:59
const ScBroadcastArea & operator=(const ScBroadcastArea &)=delete
ScBroadcastArea(const ScBroadcastArea &)=delete
void SetGroupListening(bool b)
Definition: bcaslot.hxx:82
ScBroadcastArea * pUpdateChainNext
Definition: bcaslot.hxx:54
void UpdateRange(const ScRange &rNewRange)
Definition: bcaslot.hxx:70
void SetInUpdateChain(bool b)
Definition: bcaslot.hxx:79
bool operator==(const ScBroadcastArea &rArea) const
Equalness of this or range.
Definition: bcaslot.hxx:88
void SetUpdateChainNext(ScBroadcastArea *p)
Definition: bcaslot.hxx:77
sal_uLong GetRef() const
Definition: bcaslot.hxx:75
SvtBroadcaster aBroadcaster
Definition: bcaslot.hxx:55
bool IsGroupListening() const
Definition: bcaslot.hxx:81
ScRange aRange
Definition: bcaslot.hxx:56
SvtBroadcaster & GetBroadcaster()
Definition: bcaslot.hxx:68
void IncRef()
Definition: bcaslot.hxx:73
sal_uLong nRefCount
Definition: bcaslot.hxx:57
sal_uLong DecRef()
Definition: bcaslot.hxx:74
ScBulkBroadcast & operator=(ScBulkBroadcast const &)=delete
ScBulkBroadcast(ScBulkBroadcast &&)=delete
ScBroadcastAreaSlotMachine * pBASM
Definition: bcaslot.hxx:374
ScBulkBroadcast(ScBroadcastAreaSlotMachine *p, SfxHintId nHintId)
Definition: bcaslot.hxx:383
SfxHintId mnHintId
Definition: bcaslot.hxx:375
ScBulkBroadcast(ScBulkBroadcast const &)=delete
~ScBulkBroadcast() COVERITY_NOEXCEPT_FALSE
Definition: bcaslot.hxx:390
size_t hashArea() const
Hash 2D area ignoring table number.
Definition: address.hxx:742
UpdateRefMode
Definition: global.hxx:300
SfxHintId
void * p
CAUTION! The following defines must be in the same namespace as the respective type.
AreaOverlapType
Definition: types.hxx:110
ListenerGroupType
Definition: types.hxx:118
sal_uIntPtr sal_uLong
bool operator()(const ScBroadcastArea *p1, const ScBroadcastArea *p2) const
Definition: bcaslot.hxx:129
size_t operator()(const ScBroadcastArea *p) const
Definition: bcaslot.hxx:121
ScBroadcastAreaEntry(ScBroadcastArea *p)
Definition: bcaslot.hxx:98
bool mbErasure
TRUE if marked for erasure in this set.
Definition: bcaslot.hxx:96
ScBroadcastArea * mpArea
Definition: bcaslot.hxx:95
bool operator()(const ScBroadcastAreaEntry &rEntry1, const ScBroadcastAreaEntry &rEntry2) const
Definition: bcaslot.hxx:111
size_t operator()(const ScBroadcastAreaEntry &rEntry) const
Definition: bcaslot.hxx:103
ScSlotData(SCROW r1, SCROW r2, SCSIZE sr, SCSIZE cr, SCCOL c1, SCCOL c2, SCSIZE sc, SCSIZE cc)
Definition: bcaslot.hxx:294
bool mbGroupListening
Definition: bcaslot.hxx:41
ScRange maArea
Definition: bcaslot.hxx:40
SvtListener * mpListener
Definition: bcaslot.hxx:42
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17