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*, std::unique_ptr<sc::ColumnSpanSet>> BulkGroupAreasType;
249 
263  {
264  public:
265  TableSlots(SCSIZE nBcaSlots);
266  ~TableSlots();
267  ScBroadcastAreaSlot** getSlots() { return ppSlots.get(); }
268 
274  ScBroadcastAreaSlot* getAreaSlot( SCSIZE nOff ) { return ppSlots[nOff]; }
275 
276  private:
278  std::unique_ptr<ScBroadcastAreaSlot*[]> ppSlots;
279 
280  TableSlots( const TableSlots& ) = delete;
281  TableSlots& operator=( const TableSlots& ) = delete;
282  };
283 
284  typedef ::std::map< SCTAB, std::unique_ptr<TableSlots> > TableSlotsMap;
285 
286  typedef ::std::vector< ::std::pair< ScBroadcastAreaSlot*, ScBroadcastAreas::iterator > > AreasToBeErased;
287 
288 private:
289  struct ScSlotData
290  {
291  SCROW nStartRow; // first row of this segment
292  SCROW nStopRow; // first row of next segment
293  SCSIZE nSlice; // slice size in this segment
294  SCSIZE nCumulated; // cumulated slots of previous segments
295 
296  ScSlotData( SCROW r1, SCROW r2, SCSIZE s, SCSIZE c ) : nStartRow(r1), nStopRow(r2), nSlice(s), nCumulated(c) {}
297  };
298  typedef ::std::vector< ScSlotData > ScSlotDistribution;
299  ScSlotDistribution maSlotDistribution;
302  ScBroadcastAreasBulk aBulkBroadcastAreas;
303  BulkGroupAreasType m_BulkGroupAreas;
304  TableSlotsMap aTableSlotsMap;
305  AreasToBeErased maAreasToBeErased;
306  std::unique_ptr<SvtBroadcaster> pBCAlways; // for the RC_ALWAYS special range
310  sal_uInt32 nInBulkBroadcast;
311 
312  inline SCSIZE ComputeSlotOffset( const ScAddress& rAddress ) const;
313  void ComputeAreaPoints( const ScRange& rRange,
314  SCSIZE& nStart, SCSIZE& nEnd,
315  SCSIZE& nRowBreak ) const;
316 
317 public:
320  void StartListeningArea(
321  const ScRange& rRange, bool bGroupListening, SvtListener* pListener );
322 
323  void EndListeningArea(
324  const ScRange& rRange, bool bGroupListening, SvtListener* pListener );
325 
326  bool AreaBroadcast( const ScRange& rRange, SfxHintId nHint );
327  bool AreaBroadcast( const ScHint& rHint ) const;
328  // return: at least one broadcast occurred
329  void DelBroadcastAreasInRange( const ScRange& rRange );
330  void UpdateBroadcastAreas( UpdateRefMode eUpdateRefMode,
331  const ScRange& rRange,
332  SCCOL nDx, SCROW nDy, SCTAB nDz );
333  void EnterBulkBroadcast();
334  void LeaveBulkBroadcast( SfxHintId nHintId );
335  bool InsertBulkArea( const ScBroadcastArea* p );
336 
337  void InsertBulkGroupArea( ScBroadcastArea* pArea, const ScRange& rRange );
338  void RemoveBulkGroupArea( ScBroadcastArea* pArea );
339  bool BulkBroadcastGroupAreas( SfxHintId nHintId );
340 
342  size_t RemoveBulkArea( const ScBroadcastArea* p );
343  void SetUpdateChain( ScBroadcastArea* p ) { pUpdateChain = p; }
345  void SetEOUpdateChain( ScBroadcastArea* p ) { pEOUpdateChain = p; }
346  bool IsInBulkBroadcast() const { return nInBulkBroadcast > 0; }
347 
348  // only for ScBroadcastAreaSlot
350  ScBroadcastAreas::iterator& rIter );
351  // only for ScBroadcastAreaSlot
352  void FinallyEraseAreas( ScBroadcastAreaSlot* pSlot );
353 
354  std::vector<sc::AreaListener> GetAllListeners(
355  const ScRange& rRange, sc::AreaOverlapType eType,
357 
358 #if DEBUG_AREA_BROADCASTER
359  void Dump() const;
360 #endif
361 };
362 
364 {
367 
368  ScBulkBroadcast(ScBulkBroadcast const &) = delete;
369  ScBulkBroadcast(ScBulkBroadcast &&) = delete;
370  ScBulkBroadcast & operator =(ScBulkBroadcast const &) = delete;
372 
373 public:
375  pBASM(p),
376  mnHintId(nHintId)
377  {
378  if (pBASM)
379  pBASM->EnterBulkBroadcast();
380  }
381  ~ScBulkBroadcast() COVERITY_NOEXCEPT_FALSE
382  {
383  if (pBASM)
384  pBASM->LeaveBulkBroadcast( mnHintId );
385  }
386 };
387 
388 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsInBulkBroadcast() const
Definition: bcaslot.hxx:346
SfxHintId mnHintId
Definition: bcaslot.hxx:366
ScBulkBroadcast(ScBroadcastAreaSlotMachine *p, SfxHintId nHintId)
Definition: bcaslot.hxx:374
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:748
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:445
~ScBulkBroadcast() COVERITY_NOEXCEPT_FALSE
Definition: bcaslot.hxx:381
void InsertListeningArea(ScBroadcastArea *pArea)
Insert a ScBroadcastArea obtained via StartListeningArea() to subsequent slots.
Definition: bcaslot.cxx:159
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:1121
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:170
void UpdateRemove(UpdateRefMode eUpdateRefMode, const ScRange &rRange, SCCOL nDx, SCROW nDy, SCTAB nDz)
Definition: bcaslot.cxx:364
std::unordered_set< const ScBroadcastArea *, ScBroadcastAreaBulkHash, ScBroadcastAreaBulkEqual > ScBroadcastAreasBulk
Definition: bcaslot.hxx:136
ScBroadcastArea * GetEOUpdateChain() const
Definition: bcaslot.hxx:344
const SvtBroadcaster & GetBroadcaster() const
Definition: bcaslot.hxx:69
void LeaveBulkBroadcast(SfxHintId nHintId)
Definition: bcaslot.cxx:1052
void StartListeningArea(const ScRange &rRange, bool bGroupListening, SvtListener *pListener)
Definition: bcaslot.cxx:686
ScBroadcastAreaSlot(ScDocument *pDoc, ScBroadcastAreaSlotMachine *pBASM)
Definition: bcaslot.cxx:68
void DelBroadcastAreasInRange(const ScRange &rRange)
Definition: bcaslot.cxx:837
Used in a Unique Associative Container.
Definition: bcaslot.hxx:51
ScBroadcastAreaSlot * getAreaSlot(SCSIZE nOff)
Obtain slot pointer, no check on validity! It is assumed that all calls are made with the results of ...
Definition: bcaslot.hxx:274
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:94
bool IsInUpdateChain() const
Definition: bcaslot.hxx:78
ScBroadcastArea aTmpSeekBroadcastArea
Definition: bcaslot.hxx:145
bool AreaBroadcast(const ScRange &rRange, SfxHintId nHint)
Definition: bcaslot.cxx:234
void EndListeningArea(const ScRange &rRange, bool bGroupListening, SvtListener *pListener)
Definition: bcaslot.cxx:736
TableSlotsMap aTableSlotsMap
Definition: bcaslot.hxx:304
void UpdateInsert(ScBroadcastArea *pArea)
Definition: bcaslot.cxx:422
void PushAreaToBeErased(ScBroadcastAreaSlot *pSlot, ScBroadcastAreas::iterator &rIter)
Definition: bcaslot.cxx:1131
sal_uLong nRefCount
Definition: bcaslot.hxx:57
bool BulkBroadcastGroupAreas(SfxHintId nHintId)
Definition: bcaslot.cxx:1088
std::unique_ptr< ScBroadcastAreaSlot *[]> ppSlots
Definition: bcaslot.hxx:278
void SetUpdateChain(ScBroadcastArea *p)
Definition: bcaslot.hxx:343
ScBroadcastAreaSlotMachine * pBASM
Definition: bcaslot.hxx:365
void RemoveBulkGroupArea(ScBroadcastArea *pArea)
Definition: bcaslot.cxx:1126
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:303
ScRange maArea
Definition: bcaslot.hxx:40
void SetGroupListening(bool b)
Definition: bcaslot.hxx:82
void DelBroadcastAreasInRange(const ScRange &rRange)
Definition: bcaslot.cxx:340
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:1137
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:635
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:203
void UpdateBroadcastAreas(UpdateRefMode eUpdateRefMode, const ScRange &rRange, SCCOL nDx, SCROW nDy, SCTAB nDz)
Definition: bcaslot.cxx:874
::std::vector< ::std::pair< ScBroadcastAreaSlot *, ScBroadcastAreas::iterator > > AreasToBeErased
Definition: bcaslot.hxx:286
void GetAllListeners(const ScRange &rRange, std::vector< sc::AreaListener > &rListeners, sc::AreaOverlapType eType, sc::ListenerGroupType eGroup)
Definition: bcaslot.cxx:466
AreaOverlapType
Definition: types.hxx:109
UpdateRefMode
Definition: global.hxx:309
ScBroadcastAreasBulk aBulkBroadcastAreas
Definition: bcaslot.hxx:302
sal_Int32 SCROW
Definition: types.hxx:17
std::unordered_set< ScBroadcastAreaEntry, ScBroadcastAreaHash, ScBroadcastAreaEqual > ScBroadcastAreas
Definition: bcaslot.hxx:117
ScBroadcastAreaSlotMachine(ScDocument *pDoc)
Definition: bcaslot.cxx:588
ScBulkBroadcast(ScBulkBroadcast const &)=delete
ScDocument * pDoc
Definition: bcaslot.hxx:146
void FinallyEraseAreas()
Finally erase all areas pushed as to-be-erased.
Definition: bcaslot.cxx:568
void SetEOUpdateChain(ScBroadcastArea *p)
Definition: bcaslot.hxx:345
bool InsertBulkArea(const ScBroadcastArea *p)
Definition: bcaslot.cxx:1069
ScBroadcastAreas aBroadcastAreaTbl
Definition: bcaslot.hxx:144
std::map< ScBroadcastArea *, std::unique_ptr< sc::ColumnSpanSet > > BulkGroupAreasType
Definition: bcaslot.hxx:248
::std::vector< ScSlotData > ScSlotDistribution
Definition: bcaslot.hxx:298
ScBroadcastArea * pEOUpdateChain
Definition: bcaslot.hxx:309
bool StartListeningArea(const ScRange &rRange, bool bGroupListening, SvtListener *pListener, ScBroadcastArea *&rpArea)
Only here new ScBroadcastArea objects are created, prevention of dupes.
Definition: bcaslot.cxx:115
::std::map< SCTAB, std::unique_ptr< TableSlots > > TableSlotsMap
Definition: bcaslot.hxx:284
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:299
AreasToBeErased maAreasToBeErased
Definition: bcaslot.hxx:305
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:1158
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:659
ScSlotData(SCROW r1, SCROW r2, SCSIZE s, SCSIZE c)
Definition: bcaslot.hxx:296
void SetInUpdateChain(bool b)
Definition: bcaslot.hxx:79
bool AreaBroadcast(const ScRange &rRange, SfxHintId nHint)
Definition: bcaslot.cxx:787
void UpdateRemoveArea(ScBroadcastArea *pArea)
Definition: bcaslot.cxx:408
const ScRange & GetRange() const
Definition: bcaslot.hxx:72
std::unique_ptr< SvtBroadcaster > pBCAlways
Definition: bcaslot.hxx:306
ScBroadcastArea * pUpdateChain
Definition: bcaslot.hxx:308
sal_Int16 SCTAB
Definition: types.hxx:22
void InsertBulkGroupArea(ScBroadcastArea *pArea, const ScRange &rRange)
Definition: bcaslot.cxx:1074
static bool isMarkedErased(const ScBroadcastAreas::const_iterator &rIter)
Definition: bcaslot.hxx:174
ListenerGroupType
Definition: types.hxx:117