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 {
34
35struct BroadcasterState;
36class ColumnSpanSet;
37
38}
39class ScHint;
40
41namespace sc {
42
44{
48};
49
50}
51
57{
58private:
63
66
67public:
69 const ScBroadcastArea& operator=(const ScBroadcastArea&) = delete;
70
71 ScBroadcastArea( const ScRange& rRange );
72
74 const SvtBroadcaster& GetBroadcaster() const { return aBroadcaster; }
75 void UpdateRange( const ScRange& rNewRange )
76 { aRange = rNewRange; }
77 const ScRange& GetRange() const { return aRange; }
78 void IncRef() { ++nRefCount; }
79 sal_uLong DecRef() { return nRefCount ? --nRefCount : 0; }
80 sal_uLong GetRef() const { return nRefCount; }
83 bool IsInUpdateChain() const { return mbInUpdateChain; }
84 void SetInUpdateChain( bool b ) { mbInUpdateChain = b; }
85
86 bool IsGroupListening() const { return mbGroupListening; }
87 void SetGroupListening( bool b ) { mbGroupListening = b; }
88
90 inline bool operator==( const ScBroadcastArea & rArea ) const;
91};
92
93inline bool ScBroadcastArea::operator==( const ScBroadcastArea & rArea ) const
94{
95 return aRange == rArea.aRange && mbGroupListening == rArea.mbGroupListening;
96}
97
99{
101 mutable bool mbErasure;
102
104};
105
107{
108 size_t operator()( const ScBroadcastAreaEntry& rEntry ) const
109 {
110 return rEntry.mpArea->GetRange().hashArea() + static_cast<size_t>(rEntry.mpArea->IsGroupListening());
111 }
112};
113
115{
116 bool operator()( const ScBroadcastAreaEntry& rEntry1, const ScBroadcastAreaEntry& rEntry2) const
117 {
118 return *rEntry1.mpArea == *rEntry2.mpArea;
119 }
120};
121
122typedef std::unordered_set< ScBroadcastAreaEntry, ScBroadcastAreaHash, ScBroadcastAreaEqual > ScBroadcastAreas;
123
125{
126 size_t operator()( const ScBroadcastArea* p ) const
127 {
128 return reinterpret_cast<size_t>(p);
129 }
130};
131
133{
134 bool operator()( const ScBroadcastArea* p1, const ScBroadcastArea* p2) const
135 {
136 return p1 == p2;
137 }
138};
139
140typedef std::unordered_set< const ScBroadcastArea*, ScBroadcastAreaBulkHash,
142
144
147{
148private:
150 mutable ScBroadcastArea aTmpSeekBroadcastArea; // for FindBroadcastArea()
154
163
164 ScBroadcastAreas::iterator FindBroadcastArea( const ScRange& rRange, bool bGroupListening );
165
175
177 void FinallyEraseAreas();
178
179 static bool isMarkedErased( const ScBroadcastAreas::const_iterator& rIter )
180 {
181 return rIter->mbErasure;
182 }
183
184public:
188
207 const ScRange& rRange, bool bGroupListening, SvtListener* pListener, ScBroadcastArea*& rpArea );
208
214
215 void EndListeningArea(
216 const ScRange& rRange, bool bGroupListening, SvtListener* pListener, ScBroadcastArea*& rpArea );
217
218 bool AreaBroadcast( const ScRange& rRange, SfxHintId nHint );
219 bool AreaBroadcast( const ScHint& rHint );
220 void DelBroadcastAreasInRange( const ScRange& rRange );
221 void UpdateRemove( UpdateRefMode eUpdateRefMode,
222 const ScRange& rRange,
223 SCCOL nDx, SCROW nDy, SCTAB nDz );
224 void UpdateRemoveArea( ScBroadcastArea* pArea );
225 void UpdateInsert( ScBroadcastArea* pArea );
226
228
235 void EraseArea( ScBroadcastAreas::iterator& rIter );
236
237 void GetAllListeners(
238 const ScRange& rRange, std::vector<sc::AreaListener>& rListeners,
240
242};
243
249{
250private:
251 typedef std::map<ScBroadcastArea*, sc::ColumnSpanSet> BulkGroupAreasType;
252
266 {
267 public:
268 TableSlots(SCSIZE nBcaSlots);
269 TableSlots(TableSlots&&) noexcept;
270 ~TableSlots();
271 ScBroadcastAreaSlot** getSlots() const { return ppSlots.get(); }
272
273 private:
275 std::unique_ptr<ScBroadcastAreaSlot*[]> ppSlots;
276
277 TableSlots( const TableSlots& ) = delete;
278 TableSlots& operator=( const TableSlots& ) = delete;
279 };
280
281 typedef ::std::map< SCTAB, TableSlots > TableSlotsMap;
282
283 typedef ::std::vector< ::std::pair< ScBroadcastAreaSlot*, ScBroadcastAreas::iterator > > AreasToBeErased;
284
285private:
287 {
288 SCROW nStartRow; // first row of this segment
289 SCROW nStopRow; // first row of next segment
290 SCSIZE nSliceRow; // row slice size in this segment
291 SCSIZE nCumulatedRow; // cumulated slots of previous segments (previous rows)
292 SCROW nStartCol; // first column of this segment
293 SCROW nStopCol; // first column of next segment
294 SCSIZE nSliceCol; // column slice size in this segment
295 SCSIZE nCumulatedCol; // cumulated slots of previous segments (previous columns)
296
297 ScSlotData( SCROW r1, SCROW r2, SCSIZE sr, SCSIZE cr, SCCOL c1, SCCOL c2, SCSIZE sc, SCSIZE cc )
298 : nStartRow(r1)
299 , nStopRow(r2)
300 , nSliceRow(sr)
301 , nCumulatedRow(cr)
302 , nStartCol(c1)
303 , nStopCol(c2)
304 , nSliceCol(sc)
305 , nCumulatedCol(cc) {}
306 };
307 typedef ::std::vector< ScSlotData > ScSlotDistribution;
315 std::unique_ptr<SvtBroadcaster> pBCAlways; // for the RC_ALWAYS special range
320
321 inline SCSIZE ComputeSlotOffset( const ScAddress& rAddress ) const;
322 void ComputeAreaPoints( const ScRange& rRange,
323 SCSIZE& nStart, SCSIZE& nEnd,
324 SCSIZE& nRowBreak ) const;
325#ifdef DBG_UTIL
326 void DoChecks();
327#endif
328
329public:
333 const ScRange& rRange, bool bGroupListening, SvtListener* pListener );
334
335 void EndListeningArea(
336 const ScRange& rRange, bool bGroupListening, SvtListener* pListener );
337
338 bool AreaBroadcast( const ScRange& rRange, SfxHintId nHint );
339 bool AreaBroadcast( const ScHint& rHint ) const;
340 // return: at least one broadcast occurred
341 void DelBroadcastAreasInRange( const ScRange& rRange );
342 void UpdateBroadcastAreas( UpdateRefMode eUpdateRefMode,
343 const ScRange& rRange,
344 SCCOL nDx, SCROW nDy, SCTAB nDz );
345 void EnterBulkBroadcast();
346 void LeaveBulkBroadcast( SfxHintId nHintId );
347 bool InsertBulkArea( const ScBroadcastArea* p );
348
349 void InsertBulkGroupArea( ScBroadcastArea* pArea, const ScRange& rRange );
351 bool BulkBroadcastGroupAreas( SfxHintId nHintId );
352
354 size_t RemoveBulkArea( const ScBroadcastArea* p );
358 bool IsInBulkBroadcast() const { return nInBulkBroadcast > 0; }
359
360 // only for ScBroadcastAreaSlot
362 ScBroadcastAreas::iterator& rIter );
363 // only for ScBroadcastAreaSlot
365
366 std::vector<sc::AreaListener> GetAllListeners(
367 const ScRange& rRange, sc::AreaOverlapType eType,
369
371};
372
374{
377
382
383public:
385 pBASM(p),
386 mnHintId(nHintId)
387 {
388 if (pBASM)
390 }
391 ~ScBulkBroadcast() COVERITY_NOEXCEPT_FALSE
392 {
393 if (pBASM)
395 }
396};
397
398/* 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:141
std::unordered_set< ScBroadcastAreaEntry, ScBroadcastAreaHash, ScBroadcastAreaEqual > ScBroadcastAreas
Definition: bcaslot.hxx:122
Slot offset arrangement of columns and rows, once per sheet.
Definition: bcaslot.hxx:266
ScBroadcastAreaSlot ** getSlots() const
Definition: bcaslot.hxx:271
std::unique_ptr< ScBroadcastAreaSlot *[]> ppSlots
Definition: bcaslot.hxx:275
TableSlots(const TableSlots &)=delete
TableSlots & operator=(const TableSlots &)=delete
BroadcastAreaSlots and their management, once per document.
Definition: bcaslot.hxx:249
bool BulkBroadcastGroupAreas(SfxHintId nHintId)
Definition: bcaslot.cxx:1175
ScBroadcastAreaSlotMachine(ScDocument *pDoc)
Definition: bcaslot.cxx:555
void ComputeAreaPoints(const ScRange &rRange, SCSIZE &nStart, SCSIZE &nEnd, SCSIZE &nRowBreak) const
Definition: bcaslot.cxx:647
BulkGroupAreasType m_BulkGroupAreas
Definition: bcaslot.hxx:312
AreasToBeErased maAreasToBeErased
Definition: bcaslot.hxx:314
void FinallyEraseAreas(ScBroadcastAreaSlot *pSlot)
Definition: bcaslot.cxx:1222
void LeaveBulkBroadcast(SfxHintId nHintId)
Definition: bcaslot.cxx:1140
ScBroadcastArea * GetEOUpdateChain() const
Definition: bcaslot.hxx:356
std::unique_ptr< SvtBroadcaster > pBCAlways
Definition: bcaslot.hxx:315
void SetEOUpdateChain(ScBroadcastArea *p)
Definition: bcaslot.hxx:357
std::vector< sc::AreaListener > GetAllListeners(const ScRange &rRange, sc::AreaOverlapType eType, sc::ListenerGroupType eGroup=sc::ListenerGroupType::Both)
Definition: bcaslot.cxx:1243
TableSlotsMap aTableSlotsMap
Definition: bcaslot.hxx:313
bool IsInBulkBroadcast() const
Definition: bcaslot.hxx:358
ScSlotDistribution maSlotDistribution
Definition: bcaslot.hxx:308
void StartListeningArea(const ScRange &rRange, bool bGroupListening, SvtListener *pListener)
Definition: bcaslot.cxx:761
ScBroadcastAreasBulk aBulkBroadcastAreas
Definition: bcaslot.hxx:311
void UpdateBroadcastAreas(UpdateRefMode eUpdateRefMode, const ScRange &rRange, SCCOL nDx, SCROW nDy, SCTAB nDz)
Definition: bcaslot.cxx:961
::std::map< SCTAB, TableSlots > TableSlotsMap
Definition: bcaslot.hxx:281
void EndListeningArea(const ScRange &rRange, bool bGroupListening, SvtListener *pListener)
Definition: bcaslot.cxx:812
bool InsertBulkArea(const ScBroadcastArea *p)
Definition: bcaslot.cxx:1157
size_t RemoveBulkArea(const ScBroadcastArea *p)
Definition: bcaslot.cxx:1206
::std::vector< ScSlotData > ScSlotDistribution
Definition: bcaslot.hxx:307
void CollectBroadcasterState(sc::BroadcasterState &rState) const
Definition: bcaslot.cxx:1270
void DelBroadcastAreasInRange(const ScRange &rRange)
Definition: bcaslot.cxx:924
ScBroadcastArea * pEOUpdateChain
Definition: bcaslot.hxx:318
ScBroadcastArea * pUpdateChain
Definition: bcaslot.hxx:317
std::map< ScBroadcastArea *, sc::ColumnSpanSet > BulkGroupAreasType
Definition: bcaslot.hxx:251
bool AreaBroadcast(const ScRange &rRange, SfxHintId nHint)
Definition: bcaslot.cxx:863
::std::vector< ::std::pair< ScBroadcastAreaSlot *, ScBroadcastAreas::iterator > > AreasToBeErased
Definition: bcaslot.hxx:283
void RemoveBulkGroupArea(ScBroadcastArea *pArea)
Definition: bcaslot.cxx:1211
void SetUpdateChain(ScBroadcastArea *p)
Definition: bcaslot.hxx:355
void PushAreaToBeErased(ScBroadcastAreaSlot *pSlot, ScBroadcastAreas::iterator &rIter)
Definition: bcaslot.cxx:1216
void InsertBulkGroupArea(ScBroadcastArea *pArea, const ScRange &rRange)
Definition: bcaslot.cxx:1162
SCSIZE ComputeSlotOffset(const ScAddress &rAddress) const
Definition: bcaslot.cxx:619
Collection of BroadcastAreas.
Definition: bcaslot.hxx:147
ScBroadcastAreas::iterator FindBroadcastArea(const ScRange &rRange, bool bGroupListening)
Definition: bcaslot.cxx:178
bool IsInBroadcastIteration() const
Definition: bcaslot.hxx:227
void CollectBroadcasterState(sc::BroadcasterState &rState) const
Definition: bcaslot.cxx:501
void UpdateRemove(UpdateRefMode eUpdateRefMode, const ScRange &rRange, SCCOL nDx, SCROW nDy, SCTAB nDz)
Definition: bcaslot.cxx:338
bool mbInBroadcastIteration
Definition: bcaslot.hxx:153
ScBroadcastArea aTmpSeekBroadcastArea
Definition: bcaslot.hxx:150
ScBroadcastAreas aBroadcastAreaTbl
Definition: bcaslot.hxx:149
void FinallyEraseAreas()
Finally erase all areas pushed as to-be-erased.
Definition: bcaslot.cxx:528
bool AreaBroadcast(const ScRange &rRange, SfxHintId nHint)
Definition: bcaslot.cxx:208
static bool isMarkedErased(const ScBroadcastAreas::const_iterator &rIter)
Definition: bcaslot.hxx:179
void UpdateRemoveArea(ScBroadcastArea *pArea)
Definition: bcaslot.cxx:382
ScBroadcastAreaSlot(ScDocument *pDoc, ScBroadcastAreaSlotMachine *pBASM)
Definition: bcaslot.cxx:43
void DelBroadcastAreasInRange(const ScRange &rRange)
Definition: bcaslot.cxx:314
ScDocument * pDoc
Definition: bcaslot.hxx:151
bool StartListeningArea(const ScRange &rRange, bool bGroupListening, SvtListener *pListener, ScBroadcastArea *&rpArea)
Only here new ScBroadcastArea objects are created, prevention of dupes.
Definition: bcaslot.cxx:90
void InsertListeningArea(ScBroadcastArea *pArea)
Insert a ScBroadcastArea obtained via StartListeningArea() to subsequent slots.
Definition: bcaslot.cxx:134
ScBroadcastAreaSlotMachine * pBASM
Definition: bcaslot.hxx:152
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:419
ScDocument::HardRecalcState CheckHardRecalcStateCondition() const
More hypothetical (memory would probably be doomed anyway) check whether there would be an overflow w...
Definition: bcaslot.cxx:69
void UpdateInsert(ScBroadcastArea *pArea)
Definition: bcaslot.cxx:396
bool mbHasErasedArea
If true, the slot has at least one area broadcaster marked for removal.
Definition: bcaslot.hxx:162
void EndListeningArea(const ScRange &rRange, bool bGroupListening, SvtListener *pListener, ScBroadcastArea *&rpArea)
Definition: bcaslot.cxx:145
void GetAllListeners(const ScRange &rRange, std::vector< sc::AreaListener > &rListeners, sc::AreaOverlapType eType, sc::ListenerGroupType eGroup)
Definition: bcaslot.cxx:440
Used in a Unique Associative Container.
Definition: bcaslot.hxx:57
ScBroadcastArea * GetUpdateChainNext() const
Definition: bcaslot.hxx:81
bool mbGroupListening
Definition: bcaslot.hxx:65
const ScRange & GetRange() const
Definition: bcaslot.hxx:77
bool IsInUpdateChain() const
Definition: bcaslot.hxx:83
const SvtBroadcaster & GetBroadcaster() const
Definition: bcaslot.hxx:74
bool mbInUpdateChain
Definition: bcaslot.hxx:64
const ScBroadcastArea & operator=(const ScBroadcastArea &)=delete
ScBroadcastArea(const ScBroadcastArea &)=delete
void SetGroupListening(bool b)
Definition: bcaslot.hxx:87
ScBroadcastArea * pUpdateChainNext
Definition: bcaslot.hxx:59
void UpdateRange(const ScRange &rNewRange)
Definition: bcaslot.hxx:75
void SetInUpdateChain(bool b)
Definition: bcaslot.hxx:84
bool operator==(const ScBroadcastArea &rArea) const
Equalness of this or range.
Definition: bcaslot.hxx:93
void SetUpdateChainNext(ScBroadcastArea *p)
Definition: bcaslot.hxx:82
sal_uLong GetRef() const
Definition: bcaslot.hxx:80
SvtBroadcaster aBroadcaster
Definition: bcaslot.hxx:60
bool IsGroupListening() const
Definition: bcaslot.hxx:86
ScRange aRange
Definition: bcaslot.hxx:61
SvtBroadcaster & GetBroadcaster()
Definition: bcaslot.hxx:73
void IncRef()
Definition: bcaslot.hxx:78
sal_uLong nRefCount
Definition: bcaslot.hxx:62
sal_uLong DecRef()
Definition: bcaslot.hxx:79
ScBulkBroadcast & operator=(ScBulkBroadcast const &)=delete
ScBulkBroadcast(ScBulkBroadcast &&)=delete
ScBroadcastAreaSlotMachine * pBASM
Definition: bcaslot.hxx:375
ScBulkBroadcast(ScBroadcastAreaSlotMachine *p, SfxHintId nHintId)
Definition: bcaslot.hxx:384
SfxHintId mnHintId
Definition: bcaslot.hxx:376
ScBulkBroadcast(ScBulkBroadcast const &)=delete
~ScBulkBroadcast() COVERITY_NOEXCEPT_FALSE
Definition: bcaslot.hxx:391
size_t hashArea() const
Hash 2D area ignoring table number.
Definition: address.hxx:742
UpdateRefMode
Definition: global.hxx:301
SfxHintId
void * p
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
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:134
size_t operator()(const ScBroadcastArea *p) const
Definition: bcaslot.hxx:126
ScBroadcastAreaEntry(ScBroadcastArea *p)
Definition: bcaslot.hxx:103
bool mbErasure
TRUE if marked for erasure in this set.
Definition: bcaslot.hxx:101
ScBroadcastArea * mpArea
Definition: bcaslot.hxx:100
bool operator()(const ScBroadcastAreaEntry &rEntry1, const ScBroadcastAreaEntry &rEntry2) const
Definition: bcaslot.hxx:116
size_t operator()(const ScBroadcastAreaEntry &rEntry) const
Definition: bcaslot.hxx:108
ScSlotData(SCROW r1, SCROW r2, SCSIZE sr, SCSIZE cr, SCCOL c1, SCCOL c2, SCSIZE sc, SCSIZE cc)
Definition: bcaslot.hxx:297
bool mbGroupListening
Definition: bcaslot.hxx:46
ScRange maArea
Definition: bcaslot.hxx:45
SvtListener * mpListener
Definition: bcaslot.hxx:47
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17