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 
33 namespace sc { class ColumnSpanSet; }
34 class ScHint;
35 
36 namespace sc {
37 
39 {
43 };
44 
45 }
46 
52 {
53 private:
58 
61 
62 public:
63  ScBroadcastArea(const ScBroadcastArea&) = delete;
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; }
77  void SetUpdateChainNext( ScBroadcastArea* p ) { pUpdateChainNext = p; }
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 
88 inline bool ScBroadcastArea::operator==( const ScBroadcastArea & rArea ) const
89 {
90  return aRange == rArea.aRange && mbGroupListening == rArea.mbGroupListening;
91 }
92 
94 {
96  mutable bool mbErasure;
97 
98  ScBroadcastAreaEntry( ScBroadcastArea* p ) : mpArea( p), mbErasure( false) {}
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 
117 typedef 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 
135 typedef std::unordered_set< const ScBroadcastArea*, ScBroadcastAreaBulkHash,
137 
139 
142 {
143 private:
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 
179 public:
183 
201  bool StartListeningArea(
202  const ScRange& rRange, bool bGroupListening, SvtListener* pListener, ScBroadcastArea*& rpArea );
203 
208  void InsertListeningArea( ScBroadcastArea* pArea );
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 {
247 private:
248  typedef std::map<ScBroadcastArea*, sc::ColumnSpanSet> BulkGroupAreasType;
249 
263  {
264  public:
265  TableSlots(SCSIZE nBcaSlots);
266  ~TableSlots();
267  ScBroadcastAreaSlot** getSlots() { return ppSlots.get(); }
268 
269  private:
271  std::unique_ptr<ScBroadcastAreaSlot*[]> ppSlots;
272 
273  TableSlots( const TableSlots& ) = delete;
274  TableSlots& operator=( const TableSlots& ) = delete;
275  };
276 
277  typedef ::std::map< SCTAB, std::unique_ptr<TableSlots> > TableSlotsMap;
278 
279  typedef ::std::vector< ::std::pair< ScBroadcastAreaSlot*, ScBroadcastAreas::iterator > > AreasToBeErased;
280 
281 private:
282  struct ScSlotData
283  {
284  SCROW nStartRow; // first row of this segment
285  SCROW nStopRow; // first row of next segment
286  SCSIZE nSliceRow; // row slice size in this segment
287  SCSIZE nCumulatedRow; // cumulated slots of previous segments (previous rows)
288  SCROW nStartCol; // first column of this segment
289  SCROW nStopCol; // first column of next segment
290  SCSIZE nSliceCol; // column slice size in this segment
291  SCSIZE nCumulatedCol; // cumulated slots of previous segments (previous columns)
292 
293  ScSlotData( SCROW r1, SCROW r2, SCSIZE sr, SCSIZE cr, SCCOL c1, SCCOL c2, SCSIZE sc, SCSIZE cc )
294  : nStartRow(r1)
295  , nStopRow(r2)
296  , nSliceRow(sr)
297  , nCumulatedRow(cr)
298  , nStartCol(c1)
299  , nStopCol(c2)
300  , nSliceCol(sc)
301  , nCumulatedCol(cc) {}
302  };
303  typedef ::std::vector< ScSlotData > ScSlotDistribution;
304  ScSlotDistribution maSlotDistribution;
307  ScBroadcastAreasBulk aBulkBroadcastAreas;
308  BulkGroupAreasType m_BulkGroupAreas;
309  TableSlotsMap aTableSlotsMap;
310  AreasToBeErased maAreasToBeErased;
311  std::unique_ptr<SvtBroadcaster> pBCAlways; // for the RC_ALWAYS special range
315  sal_uInt32 nInBulkBroadcast;
316 
317  inline SCSIZE ComputeSlotOffset( const ScAddress& rAddress ) const;
318  void ComputeAreaPoints( const ScRange& rRange,
319  SCSIZE& nStart, SCSIZE& nEnd,
320  SCSIZE& nRowBreak ) const;
321 #ifdef DBG_UTIL
322  void DoChecks();
323 #endif
324 
325 public:
328  void StartListeningArea(
329  const ScRange& rRange, bool bGroupListening, SvtListener* pListener );
330 
331  void EndListeningArea(
332  const ScRange& rRange, bool bGroupListening, SvtListener* pListener );
333 
334  bool AreaBroadcast( const ScRange& rRange, SfxHintId nHint );
335  bool AreaBroadcast( const ScHint& rHint ) const;
336  // return: at least one broadcast occurred
337  void DelBroadcastAreasInRange( const ScRange& rRange );
338  void UpdateBroadcastAreas( UpdateRefMode eUpdateRefMode,
339  const ScRange& rRange,
340  SCCOL nDx, SCROW nDy, SCTAB nDz );
341  void EnterBulkBroadcast();
342  void LeaveBulkBroadcast( SfxHintId nHintId );
343  bool InsertBulkArea( const ScBroadcastArea* p );
344 
345  void InsertBulkGroupArea( ScBroadcastArea* pArea, const ScRange& rRange );
346  void RemoveBulkGroupArea( ScBroadcastArea* pArea );
347  bool BulkBroadcastGroupAreas( SfxHintId nHintId );
348 
350  size_t RemoveBulkArea( const ScBroadcastArea* p );
351  void SetUpdateChain( ScBroadcastArea* p ) { pUpdateChain = p; }
353  void SetEOUpdateChain( ScBroadcastArea* p ) { pEOUpdateChain = p; }
354  bool IsInBulkBroadcast() const { return nInBulkBroadcast > 0; }
355 
356  // only for ScBroadcastAreaSlot
358  ScBroadcastAreas::iterator& rIter );
359  // only for ScBroadcastAreaSlot
360  void FinallyEraseAreas( ScBroadcastAreaSlot* pSlot );
361 
362  std::vector<sc::AreaListener> GetAllListeners(
363  const ScRange& rRange, sc::AreaOverlapType eType,
365 
366 #if DEBUG_AREA_BROADCASTER
367  void Dump() const;
368 #endif
369 };
370 
372 {
375 
376  ScBulkBroadcast(ScBulkBroadcast const &) = delete;
377  ScBulkBroadcast(ScBulkBroadcast &&) = delete;
378  ScBulkBroadcast & operator =(ScBulkBroadcast const &) = delete;
380 
381 public:
383  pBASM(p),
384  mnHintId(nHintId)
385  {
386  if (pBASM)
387  pBASM->EnterBulkBroadcast();
388  }
389  ~ScBulkBroadcast() COVERITY_NOEXCEPT_FALSE
390  {
391  if (pBASM)
392  pBASM->LeaveBulkBroadcast( mnHintId );
393  }
394 };
395 
396 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsInBulkBroadcast() const
Definition: bcaslot.hxx:354
SfxHintId mnHintId
Definition: bcaslot.hxx:374
ScBulkBroadcast(ScBroadcastAreaSlotMachine *p, SfxHintId nHintId)
Definition: bcaslot.hxx:382
bool mbErasure
TRUE if marked for erasure in this set.
Definition: bcaslot.hxx:96
SfxHintId
size_t hashArea() const
Hash 2D area ignoring table number.
Definition: address.hxx:742
bool IsInBroadcastIteration() const
Definition: bcaslot.hxx:222
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
~ScBulkBroadcast() COVERITY_NOEXCEPT_FALSE
Definition: bcaslot.hxx:389
void InsertListeningArea(ScBroadcastArea *pArea)
Insert a ScBroadcastArea obtained via StartListeningArea() to subsequent slots.
Definition: bcaslot.cxx:136
size_t operator()(const ScBroadcastAreaEntry &rEntry) const
Definition: bcaslot.hxx:103
ScRange aRange
Definition: bcaslot.hxx:56
size_t operator()(const ScBroadcastArea *p) const
Definition: bcaslot.hxx:121
bool IsGroupListening() const
Definition: bcaslot.hxx:81
size_t RemoveBulkArea(const ScBroadcastArea *p)
Definition: bcaslot.cxx:1213
ScBroadcastAreaSlot ** getSlots()
Definition: bcaslot.hxx:267
bool mbInBroadcastIteration
Definition: bcaslot.hxx:148
ScBroadcastArea(const ScBroadcastArea &)=delete
sal_uIntPtr sal_uLong
ScBroadcastArea * mpArea
Definition: bcaslot.hxx:95
ScBroadcastArea * pUpdateChainNext
Definition: bcaslot.hxx:54
bool mbInUpdateChain
Definition: bcaslot.hxx:59
SvtBroadcaster aBroadcaster
Definition: bcaslot.hxx:55
void EndListeningArea(const ScRange &rRange, bool bGroupListening, SvtListener *pListener, ScBroadcastArea *&rpArea)
Definition: bcaslot.cxx:147
void UpdateRemove(UpdateRefMode eUpdateRefMode, const ScRange &rRange, SCCOL nDx, SCROW nDy, SCTAB nDz)
Definition: bcaslot.cxx:340
std::unordered_set< const ScBroadcastArea *, ScBroadcastAreaBulkHash, ScBroadcastAreaBulkEqual > ScBroadcastAreasBulk
Definition: bcaslot.hxx:136
ScBroadcastArea * GetEOUpdateChain() const
Definition: bcaslot.hxx:352
const SvtBroadcaster & GetBroadcaster() const
Definition: bcaslot.hxx:69
void LeaveBulkBroadcast(SfxHintId nHintId)
Definition: bcaslot.cxx:1147
void StartListeningArea(const ScRange &rRange, bool bGroupListening, SvtListener *pListener)
Definition: bcaslot.cxx:770
ScBroadcastAreaSlot(ScDocument *pDoc, ScBroadcastAreaSlotMachine *pBASM)
Definition: bcaslot.cxx:45
void DelBroadcastAreasInRange(const ScRange &rRange)
Definition: bcaslot.cxx:932
Used in a Unique Associative Container.
Definition: bcaslot.hxx:51
Collection of BroadcastAreas.
Definition: bcaslot.hxx:141
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
ScDocument::HardRecalcState CheckHardRecalcStateCondition() const
More hypothetical (memory would probably be doomed anyway) check whether there would be an overflow w...
Definition: bcaslot.cxx:71
bool IsInUpdateChain() const
Definition: bcaslot.hxx:78
ScBroadcastArea aTmpSeekBroadcastArea
Definition: bcaslot.hxx:145
std::map< ScBroadcastArea *, sc::ColumnSpanSet > BulkGroupAreasType
Definition: bcaslot.hxx:248
bool AreaBroadcast(const ScRange &rRange, SfxHintId nHint)
Definition: bcaslot.cxx:210
void EndListeningArea(const ScRange &rRange, bool bGroupListening, SvtListener *pListener)
Definition: bcaslot.cxx:820
TableSlotsMap aTableSlotsMap
Definition: bcaslot.hxx:309
void UpdateInsert(ScBroadcastArea *pArea)
Definition: bcaslot.cxx:398
void PushAreaToBeErased(ScBroadcastAreaSlot *pSlot, ScBroadcastAreas::iterator &rIter)
Definition: bcaslot.cxx:1223
sal_uLong nRefCount
Definition: bcaslot.hxx:57
bool BulkBroadcastGroupAreas(SfxHintId nHintId)
Definition: bcaslot.cxx:1182
std::unique_ptr< ScBroadcastAreaSlot *[]> ppSlots
Definition: bcaslot.hxx:271
void SetUpdateChain(ScBroadcastArea *p)
Definition: bcaslot.hxx:351
ScBroadcastAreaSlotMachine * pBASM
Definition: bcaslot.hxx:373
void RemoveBulkGroupArea(ScBroadcastArea *pArea)
Definition: bcaslot.cxx:1218
sal_Int16 SCCOL
Definition: types.hxx:21
SvtListener * mpListener
Definition: bcaslot.hxx:42
void UpdateRange(const ScRange &rNewRange)
Definition: bcaslot.hxx:70
BulkGroupAreasType m_BulkGroupAreas
Definition: bcaslot.hxx:308
ScRange maArea
Definition: bcaslot.hxx:40
void SetGroupListening(bool b)
Definition: bcaslot.hxx:82
CAUTION! The following defines must be in the same namespace as the respective type.
void DelBroadcastAreasInRange(const ScRange &rRange)
Definition: bcaslot.cxx:316
bool operator==(const ScBroadcastArea &rArea) const
Equalness of this or range.
Definition: bcaslot.hxx:88
ScBulkBroadcast & operator=(ScBulkBroadcast const &)=delete
ScBroadcastAreaSlotMachine * pBASM
Definition: bcaslot.hxx:147
void FinallyEraseAreas(ScBroadcastAreaSlot *pSlot)
Definition: bcaslot.cxx:1229
ScBroadcastArea * GetUpdateChainNext() const
Definition: bcaslot.hxx:76
SvtBroadcaster & GetBroadcaster()
Definition: bcaslot.hxx:68
ScBroadcastAreaEntry(ScBroadcastArea *p)
Definition: bcaslot.hxx:98
BroadcastAreaSlots and their management, once per document.
Definition: bcaslot.hxx:245
SCSIZE ComputeSlotOffset(const ScAddress &rAddress) const
Definition: bcaslot.cxx:628
void SetUpdateChainNext(ScBroadcastArea *p)
Definition: bcaslot.hxx:77
const ScBroadcastArea & operator=(const ScBroadcastArea &)=delete
sal_uLong DecRef()
Definition: bcaslot.hxx:74
bool mbGroupListening
Definition: bcaslot.hxx:60
ScBroadcastAreas::iterator FindBroadcastArea(const ScRange &rRange, bool bGroupListening)
Definition: bcaslot.cxx:180
void UpdateBroadcastAreas(UpdateRefMode eUpdateRefMode, const ScRange &rRange, SCCOL nDx, SCROW nDy, SCTAB nDz)
Definition: bcaslot.cxx:969
::std::vector< ::std::pair< ScBroadcastAreaSlot *, ScBroadcastAreas::iterator > > AreasToBeErased
Definition: bcaslot.hxx:279
void GetAllListeners(const ScRange &rRange, std::vector< sc::AreaListener > &rListeners, sc::AreaOverlapType eType, sc::ListenerGroupType eGroup)
Definition: bcaslot.cxx:442
AreaOverlapType
Definition: types.hxx:109
UpdateRefMode
Definition: global.hxx:298
ScBroadcastAreasBulk aBulkBroadcastAreas
Definition: bcaslot.hxx:307
sal_Int32 SCROW
Definition: types.hxx:17
std::unordered_set< ScBroadcastAreaEntry, ScBroadcastAreaHash, ScBroadcastAreaEqual > ScBroadcastAreas
Definition: bcaslot.hxx:117
ScBroadcastAreaSlotMachine(ScDocument *pDoc)
Definition: bcaslot.cxx:564
ScBulkBroadcast(ScBulkBroadcast const &)=delete
ScDocument * pDoc
Definition: bcaslot.hxx:146
void FinallyEraseAreas()
Finally erase all areas pushed as to-be-erased.
Definition: bcaslot.cxx:544
void SetEOUpdateChain(ScBroadcastArea *p)
Definition: bcaslot.hxx:353
bool InsertBulkArea(const ScBroadcastArea *p)
Definition: bcaslot.cxx:1164
ScBroadcastAreas aBroadcastAreaTbl
Definition: bcaslot.hxx:144
::std::vector< ScSlotData > ScSlotDistribution
Definition: bcaslot.hxx:303
ScBroadcastArea * pEOUpdateChain
Definition: bcaslot.hxx:314
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
::std::map< SCTAB, std::unique_ptr< TableSlots > > TableSlotsMap
Definition: bcaslot.hxx:277
bool mbHasErasedArea
If true, the slot has at least one area broadcaster marked for removal.
Definition: bcaslot.hxx:157
bool mbGroupListening
Definition: bcaslot.hxx:41
TableSlots & operator=(const TableSlots &)=delete
ScSlotDistribution maSlotDistribution
Definition: bcaslot.hxx:304
AreasToBeErased maAreasToBeErased
Definition: bcaslot.hxx:310
void IncRef()
Definition: bcaslot.hxx:73
bool operator()(const ScBroadcastAreaEntry &rEntry1, const ScBroadcastAreaEntry &rEntry2) const
Definition: bcaslot.hxx:111
sal_uLong GetRef() const
Definition: bcaslot.hxx:75
std::vector< sc::AreaListener > GetAllListeners(const ScRange &rRange, sc::AreaOverlapType eType, sc::ListenerGroupType eGroup=sc::ListenerGroupType::Both)
Definition: bcaslot.cxx:1250
Slot offset arrangement of columns and rows, once per sheet.
Definition: bcaslot.hxx:262
bool operator()(const ScBroadcastArea *p1, const ScBroadcastArea *p2) const
Definition: bcaslot.hxx:129
void ComputeAreaPoints(const ScRange &rRange, SCSIZE &nStart, SCSIZE &nEnd, SCSIZE &nRowBreak) const
Definition: bcaslot.cxx:656
void SetInUpdateChain(bool b)
Definition: bcaslot.hxx:79
bool AreaBroadcast(const ScRange &rRange, SfxHintId nHint)
Definition: bcaslot.cxx:871
ScSlotData(SCROW r1, SCROW r2, SCSIZE sr, SCSIZE cr, SCCOL c1, SCCOL c2, SCSIZE sc, SCSIZE cc)
Definition: bcaslot.hxx:293
void UpdateRemoveArea(ScBroadcastArea *pArea)
Definition: bcaslot.cxx:384
const ScRange & GetRange() const
Definition: bcaslot.hxx:72
std::unique_ptr< SvtBroadcaster > pBCAlways
Definition: bcaslot.hxx:311
ScBroadcastArea * pUpdateChain
Definition: bcaslot.hxx:313
sal_Int16 SCTAB
Definition: types.hxx:22
void InsertBulkGroupArea(ScBroadcastArea *pArea, const ScRange &rRange)
Definition: bcaslot.cxx:1169
static bool isMarkedErased(const ScBroadcastAreas::const_iterator &rIter)
Definition: bcaslot.hxx:174
ListenerGroupType
Definition: types.hxx:117
bool m_bDetectedRangeSegmentation false