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 #ifndef INCLUDED_SC_SOURCE_CORE_INC_BCASLOT_HXX
21 #define INCLUDED_SC_SOURCE_CORE_INC_BCASLOT_HXX
22 
23 #include <memory>
24 #include <map>
25 #include <unordered_set>
26 
27 #include <svl/broadcast.hxx>
28 #include <svl/hint.hxx>
29 #include <tools/solar.h>
30 
31 #include <document.hxx>
32 #include <global.hxx>
33 
34 namespace sc { class ColumnSpanSet; }
35 class ScHint;
36 
37 namespace sc {
38 
40 {
44 };
45 
46 }
47 
53 {
54 private:
59 
62 
63 public:
64  ScBroadcastArea(const ScBroadcastArea&) = delete;
65  const ScBroadcastArea& operator=(const ScBroadcastArea&) = delete;
66 
67  ScBroadcastArea( const ScRange& rRange );
68 
70  const SvtBroadcaster& GetBroadcaster() const { return aBroadcaster; }
71  void UpdateRange( const ScRange& rNewRange )
72  { aRange = rNewRange; }
73  const ScRange& GetRange() const { return aRange; }
74  void IncRef() { ++nRefCount; }
75  sal_uLong DecRef() { return nRefCount ? --nRefCount : 0; }
76  sal_uLong GetRef() const { return nRefCount; }
78  void SetUpdateChainNext( ScBroadcastArea* p ) { pUpdateChainNext = p; }
79  bool IsInUpdateChain() const { return mbInUpdateChain; }
80  void SetInUpdateChain( bool b ) { mbInUpdateChain = b; }
81 
82  bool IsGroupListening() const { return mbGroupListening; }
83  void SetGroupListening( bool b ) { mbGroupListening = b; }
84 
86  inline bool operator==( const ScBroadcastArea & rArea ) const;
87 };
88 
89 inline bool ScBroadcastArea::operator==( const ScBroadcastArea & rArea ) const
90 {
91  return aRange == rArea.aRange && mbGroupListening == rArea.mbGroupListening;
92 }
93 
95 {
97  mutable bool mbErasure;
98 
99  ScBroadcastAreaEntry( ScBroadcastArea* p ) : mpArea( p), mbErasure( false) {}
100 };
101 
103 {
104  size_t operator()( const ScBroadcastAreaEntry& rEntry ) const
105  {
106  return rEntry.mpArea->GetRange().hashArea() + static_cast<size_t>(rEntry.mpArea->IsGroupListening());
107  }
108 };
109 
111 {
112  bool operator()( const ScBroadcastAreaEntry& rEntry1, const ScBroadcastAreaEntry& rEntry2) const
113  {
114  return *rEntry1.mpArea == *rEntry2.mpArea;
115  }
116 };
117 
118 typedef std::unordered_set< ScBroadcastAreaEntry, ScBroadcastAreaHash, ScBroadcastAreaEqual > ScBroadcastAreas;
119 
121 {
122  size_t operator()( const ScBroadcastArea* p ) const
123  {
124  return reinterpret_cast<size_t>(p);
125  }
126 };
127 
129 {
130  bool operator()( const ScBroadcastArea* p1, const ScBroadcastArea* p2) const
131  {
132  return p1 == p2;
133  }
134 };
135 
136 typedef std::unordered_set< const ScBroadcastArea*, ScBroadcastAreaBulkHash,
138 
140 
143 {
144 private:
146  mutable ScBroadcastArea aTmpSeekBroadcastArea; // for FindBroadcastArea()
150 
159 
160  ScBroadcastAreas::iterator FindBroadcastArea( const ScRange& rRange, bool bGroupListening );
161 
171 
173  void FinallyEraseAreas();
174 
175  static bool isMarkedErased( const ScBroadcastAreas::const_iterator& rIter )
176  {
177  return rIter->mbErasure;
178  }
179 
180 public:
184 
202  bool StartListeningArea(
203  const ScRange& rRange, bool bGroupListening, SvtListener* pListener, ScBroadcastArea*& rpArea );
204 
209  void InsertListeningArea( ScBroadcastArea* pArea );
210 
211  void EndListeningArea(
212  const ScRange& rRange, bool bGroupListening, SvtListener* pListener, ScBroadcastArea*& rpArea );
213 
214  bool AreaBroadcast( const ScRange& rRange, SfxHintId nHint );
215  bool AreaBroadcast( const ScHint& rHint );
216  void DelBroadcastAreasInRange( const ScRange& rRange );
217  void UpdateRemove( UpdateRefMode eUpdateRefMode,
218  const ScRange& rRange,
219  SCCOL nDx, SCROW nDy, SCTAB nDz );
220  void UpdateRemoveArea( ScBroadcastArea* pArea );
221  void UpdateInsert( ScBroadcastArea* pArea );
222 
224 
231  void EraseArea( ScBroadcastAreas::iterator& rIter );
232 
233  void GetAllListeners(
234  const ScRange& rRange, std::vector<sc::AreaListener>& rListeners,
236 
237 #if DEBUG_AREA_BROADCASTER
238  void Dump() const;
239 #endif
240 };
241 
247 {
248 private:
249  typedef std::map<ScBroadcastArea*, std::unique_ptr<sc::ColumnSpanSet>> BulkGroupAreasType;
250 
264  {
265  public:
266  TableSlots(SCSIZE nBcaSlots);
267  ~TableSlots();
268  ScBroadcastAreaSlot** getSlots() { return ppSlots.get(); }
269 
275  ScBroadcastAreaSlot* getAreaSlot( SCSIZE nOff ) { return ppSlots[nOff]; }
276 
277  private:
279  std::unique_ptr<ScBroadcastAreaSlot*[]> ppSlots;
280 
281  TableSlots( const TableSlots& ) = delete;
282  TableSlots& operator=( const TableSlots& ) = delete;
283  };
284 
285  typedef ::std::map< SCTAB, std::unique_ptr<TableSlots> > TableSlotsMap;
286 
287  typedef ::std::vector< ::std::pair< ScBroadcastAreaSlot*, ScBroadcastAreas::iterator > > AreasToBeErased;
288 
289 private:
290  struct ScSlotData
291  {
292  SCROW nStartRow; // first row of this segment
293  SCROW nStopRow; // first row of next segment
294  SCSIZE nSlice; // slice size in this segment
295  SCSIZE nCumulated; // cumulated slots of previous segments
296 
297  ScSlotData( SCROW r1, SCROW r2, SCSIZE s, SCSIZE c ) : nStartRow(r1), nStopRow(r2), nSlice(s), nCumulated(c) {}
298  };
299  typedef ::std::vector< ScSlotData > ScSlotDistribution;
300  ScSlotDistribution maSlotDistribution;
303  ScBroadcastAreasBulk aBulkBroadcastAreas;
304  BulkGroupAreasType m_BulkGroupAreas;
305  TableSlotsMap aTableSlotsMap;
306  AreasToBeErased maAreasToBeErased;
307  std::unique_ptr<SvtBroadcaster> pBCAlways; // for the RC_ALWAYS special range
311  sal_uInt32 nInBulkBroadcast;
312 
313  inline SCSIZE ComputeSlotOffset( const ScAddress& rAddress ) const;
314  void ComputeAreaPoints( const ScRange& rRange,
315  SCSIZE& nStart, SCSIZE& nEnd,
316  SCSIZE& nRowBreak ) const;
317 
318 public:
321  void StartListeningArea(
322  const ScRange& rRange, bool bGroupListening, SvtListener* pListener );
323 
324  void EndListeningArea(
325  const ScRange& rRange, bool bGroupListening, SvtListener* pListener );
326 
327  bool AreaBroadcast( const ScRange& rRange, SfxHintId nHint );
328  bool AreaBroadcast( const ScHint& rHint ) const;
329  // return: at least one broadcast occurred
330  void DelBroadcastAreasInRange( const ScRange& rRange );
331  void UpdateBroadcastAreas( UpdateRefMode eUpdateRefMode,
332  const ScRange& rRange,
333  SCCOL nDx, SCROW nDy, SCTAB nDz );
334  void EnterBulkBroadcast();
335  void LeaveBulkBroadcast( SfxHintId nHintId );
336  bool InsertBulkArea( const ScBroadcastArea* p );
337 
338  void InsertBulkGroupArea( ScBroadcastArea* pArea, const ScRange& rRange );
339  void RemoveBulkGroupArea( ScBroadcastArea* pArea );
340  bool BulkBroadcastGroupAreas( SfxHintId nHintId );
341 
343  size_t RemoveBulkArea( const ScBroadcastArea* p );
344  void SetUpdateChain( ScBroadcastArea* p ) { pUpdateChain = p; }
346  void SetEOUpdateChain( ScBroadcastArea* p ) { pEOUpdateChain = p; }
347  bool IsInBulkBroadcast() const { return nInBulkBroadcast > 0; }
348 
349  // only for ScBroadcastAreaSlot
351  ScBroadcastAreas::iterator& rIter );
352  // only for ScBroadcastAreaSlot
353  void FinallyEraseAreas( ScBroadcastAreaSlot* pSlot );
354 
355  std::vector<sc::AreaListener> GetAllListeners(
356  const ScRange& rRange, sc::AreaOverlapType eType,
358 
359 #if DEBUG_AREA_BROADCASTER
360  void Dump() const;
361 #endif
362 };
363 
365 {
368 
369  ScBulkBroadcast(ScBulkBroadcast const &) = delete;
370  ScBulkBroadcast(ScBulkBroadcast &&) = delete;
371  ScBulkBroadcast & operator =(ScBulkBroadcast const &) = delete;
373 
374 public:
376  pBASM(p),
377  mnHintId(nHintId)
378  {
379  if (pBASM)
380  pBASM->EnterBulkBroadcast();
381  }
382  ~ScBulkBroadcast() COVERITY_NOEXCEPT_FALSE
383  {
384  if (pBASM)
385  pBASM->LeaveBulkBroadcast( mnHintId );
386  }
387 };
388 
389 #endif
390 
391 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsInBulkBroadcast() const
Definition: bcaslot.hxx:347
SfxHintId mnHintId
Definition: bcaslot.hxx:367
ScBulkBroadcast(ScBroadcastAreaSlotMachine *p, SfxHintId nHintId)
Definition: bcaslot.hxx:375
bool mbErasure
TRUE if marked for erasure in this set.
Definition: bcaslot.hxx:97
SfxHintId
size_t hashArea() const
Hash 2D area ignoring table number.
Definition: address.hxx:749
bool IsInBroadcastIteration() const
Definition: bcaslot.hxx:223
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:382
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:104
ScRange aRange
Definition: bcaslot.hxx:57
size_t operator()(const ScBroadcastArea *p) const
Definition: bcaslot.hxx:122
bool IsGroupListening() const
Definition: bcaslot.hxx:82
size_t RemoveBulkArea(const ScBroadcastArea *p)
Definition: bcaslot.cxx:1121
ScBroadcastAreaSlot ** getSlots()
Definition: bcaslot.hxx:268
bool mbInBroadcastIteration
Definition: bcaslot.hxx:149
ScBroadcastArea(const ScBroadcastArea &)=delete
sal_uIntPtr sal_uLong
ScBroadcastArea * mpArea
Definition: bcaslot.hxx:96
ScBroadcastArea * pUpdateChainNext
Definition: bcaslot.hxx:55
bool mbInUpdateChain
Definition: bcaslot.hxx:60
SvtBroadcaster aBroadcaster
Definition: bcaslot.hxx:56
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:137
ScBroadcastArea * GetEOUpdateChain() const
Definition: bcaslot.hxx:345
const SvtBroadcaster & GetBroadcaster() const
Definition: bcaslot.hxx:70
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:52
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:275
Collection of BroadcastAreas.
Definition: bcaslot.hxx:142
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:45
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:79
ScBroadcastArea aTmpSeekBroadcastArea
Definition: bcaslot.hxx:146
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:305
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:58
bool BulkBroadcastGroupAreas(SfxHintId nHintId)
Definition: bcaslot.cxx:1088
std::unique_ptr< ScBroadcastAreaSlot *[]> ppSlots
Definition: bcaslot.hxx:279
void SetUpdateChain(ScBroadcastArea *p)
Definition: bcaslot.hxx:344
ScBroadcastAreaSlotMachine * pBASM
Definition: bcaslot.hxx:366
void RemoveBulkGroupArea(ScBroadcastArea *pArea)
Definition: bcaslot.cxx:1126
sal_Int16 SCCOL
Definition: types.hxx:22
SvtListener * mpListener
Definition: bcaslot.hxx:43
void UpdateRange(const ScRange &rNewRange)
Definition: bcaslot.hxx:71
BulkGroupAreasType m_BulkGroupAreas
Definition: bcaslot.hxx:304
ScRange maArea
Definition: bcaslot.hxx:41
void SetGroupListening(bool b)
Definition: bcaslot.hxx:83
void DelBroadcastAreasInRange(const ScRange &rRange)
Definition: bcaslot.cxx:340
bool operator==(const ScBroadcastArea &rArea) const
Equalness of this or range.
Definition: bcaslot.hxx:89
ScBulkBroadcast & operator=(ScBulkBroadcast const &)=delete
ScBroadcastAreaSlotMachine * pBASM
Definition: bcaslot.hxx:148
void FinallyEraseAreas(ScBroadcastAreaSlot *pSlot)
Definition: bcaslot.cxx:1137
ScBroadcastArea * GetUpdateChainNext() const
Definition: bcaslot.hxx:77
SvtBroadcaster & GetBroadcaster()
Definition: bcaslot.hxx:69
ScBroadcastAreaEntry(ScBroadcastArea *p)
Definition: bcaslot.hxx:99
BroadcastAreaSlots and their management, once per document.
Definition: bcaslot.hxx:246
SCSIZE ComputeSlotOffset(const ScAddress &rAddress) const
Definition: bcaslot.cxx:635
void SetUpdateChainNext(ScBroadcastArea *p)
Definition: bcaslot.hxx:78
const ScBroadcastArea & operator=(const ScBroadcastArea &)=delete
sal_uLong DecRef()
Definition: bcaslot.hxx:75
bool mbGroupListening
Definition: bcaslot.hxx:61
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:287
void GetAllListeners(const ScRange &rRange, std::vector< sc::AreaListener > &rListeners, sc::AreaOverlapType eType, sc::ListenerGroupType eGroup)
Definition: bcaslot.cxx:466
AreaOverlapType
Definition: types.hxx:110
UpdateRefMode
Definition: global.hxx:311
ScBroadcastAreasBulk aBulkBroadcastAreas
Definition: bcaslot.hxx:303
sal_Int32 SCROW
Definition: types.hxx:18
std::unordered_set< ScBroadcastAreaEntry, ScBroadcastAreaHash, ScBroadcastAreaEqual > ScBroadcastAreas
Definition: bcaslot.hxx:118
ScBroadcastAreaSlotMachine(ScDocument *pDoc)
Definition: bcaslot.cxx:588
ScBulkBroadcast(ScBulkBroadcast const &)=delete
ScDocument * pDoc
Definition: bcaslot.hxx:147
void FinallyEraseAreas()
Finally erase all areas pushed as to-be-erased.
Definition: bcaslot.cxx:568
void SetEOUpdateChain(ScBroadcastArea *p)
Definition: bcaslot.hxx:346
bool InsertBulkArea(const ScBroadcastArea *p)
Definition: bcaslot.cxx:1069
ScBroadcastAreas aBroadcastAreaTbl
Definition: bcaslot.hxx:145
std::map< ScBroadcastArea *, std::unique_ptr< sc::ColumnSpanSet > > BulkGroupAreasType
Definition: bcaslot.hxx:249
::std::vector< ScSlotData > ScSlotDistribution
Definition: bcaslot.hxx:299
ScBroadcastArea * pEOUpdateChain
Definition: bcaslot.hxx:310
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:285
bool mbHasErasedArea
If true, the slot has at least one area broadcaster marked for removal.
Definition: bcaslot.hxx:158
bool mbGroupListening
Definition: bcaslot.hxx:42
TableSlots & operator=(const TableSlots &)=delete
ScSlotDistribution maSlotDistribution
Definition: bcaslot.hxx:300
AreasToBeErased maAreasToBeErased
Definition: bcaslot.hxx:306
void IncRef()
Definition: bcaslot.hxx:74
bool operator()(const ScBroadcastAreaEntry &rEntry1, const ScBroadcastAreaEntry &rEntry2) const
Definition: bcaslot.hxx:112
sal_uLong GetRef() const
Definition: bcaslot.hxx:76
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:263
bool operator()(const ScBroadcastArea *p1, const ScBroadcastArea *p2) const
Definition: bcaslot.hxx:130
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:297
void SetInUpdateChain(bool b)
Definition: bcaslot.hxx:80
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:73
std::unique_ptr< SvtBroadcaster > pBCAlways
Definition: bcaslot.hxx:307
ScBroadcastArea * pUpdateChain
Definition: bcaslot.hxx:309
sal_Int16 SCTAB
Definition: types.hxx:23
void InsertBulkGroupArea(ScBroadcastArea *pArea, const ScRange &rRange)
Definition: bcaslot.cxx:1074
static bool isMarkedErased(const ScBroadcastAreas::const_iterator &rIter)
Definition: bcaslot.hxx:175
ListenerGroupType
Definition: types.hxx:118