Update ooo320-m1
[ooovba.git] / sc / source / core / inc / bcaslot.hxx
blob5c2487382e07155fac19b7e24f76ff0442c1b63c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bcaslot.hxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_BCASLOT_HXX
32 #define SC_BCASLOT_HXX
34 #include <set>
35 #include <hash_set>
36 #include <functional>
37 #include <svtools/broadcast.hxx>
38 #include <svtools/svarray.hxx>
40 #include "global.hxx"
41 #include "brdcst.hxx"
43 /**
44 Used in a Unique Associative Container.
47 class ScBroadcastArea
49 private:
50 ScBroadcastArea* pUpdateChainNext;
51 SvtBroadcaster aBroadcaster;
52 ScRange aRange;
53 ULONG nRefCount;
54 BOOL bInUpdateChain;
56 public:
57 ScBroadcastArea( const ScRange& rRange )
58 : pUpdateChainNext( NULL ), aRange( rRange ),
59 nRefCount( 0 ), bInUpdateChain( FALSE ) {}
60 inline SvtBroadcaster& GetBroadcaster() { return aBroadcaster; }
61 inline const SvtBroadcaster& GetBroadcaster() const { return aBroadcaster; }
62 inline void UpdateRange( const ScRange& rNewRange )
63 { aRange = rNewRange; }
64 inline const ScRange& GetRange() const { return aRange; }
65 inline const ScAddress& GetStart() const { return aRange.aStart; }
66 inline const ScAddress& GetEnd() const { return aRange.aEnd; }
67 inline void IncRef() { ++nRefCount; }
68 inline ULONG DecRef() { return nRefCount ? --nRefCount : 0; }
69 inline ULONG GetRef() { return nRefCount; }
70 inline ScBroadcastArea* GetUpdateChainNext() const { return pUpdateChainNext; }
71 inline void SetUpdateChainNext( ScBroadcastArea* p ) { pUpdateChainNext = p; }
72 inline BOOL IsInUpdateChain() const { return bInUpdateChain; }
73 inline void SetInUpdateChain( BOOL b ) { bInUpdateChain = b; }
75 /** Equalness of this or range. */
76 inline bool operator==( const ScBroadcastArea & rArea ) const;
79 inline bool ScBroadcastArea::operator==( const ScBroadcastArea & rArea ) const
81 return aRange == rArea.aRange;
84 //=============================================================================
86 struct ScBroadcastAreaHash
88 size_t operator()( const ScBroadcastArea* p ) const
90 return p->GetRange().hashArea();
94 struct ScBroadcastAreaEqual
96 bool operator()( const ScBroadcastArea* p1, const ScBroadcastArea* p2) const
98 return *p1 == *p2;
102 typedef ::std::hash_set< ScBroadcastArea*, ScBroadcastAreaHash, ScBroadcastAreaEqual > ScBroadcastAreas;
104 //=============================================================================
106 struct ScBroadcastAreaBulkHash
108 size_t operator()( const ScBroadcastArea* p ) const
110 return reinterpret_cast<size_t>(p);
114 struct ScBroadcastAreaBulkEqual
116 bool operator()( const ScBroadcastArea* p1, const ScBroadcastArea* p2) const
118 return p1 == p2;
122 typedef ::std::hash_set< const ScBroadcastArea*, ScBroadcastAreaBulkHash,
123 ScBroadcastAreaBulkEqual > ScBroadcastAreasBulk;
125 //=============================================================================
127 class ScBroadcastAreaSlotMachine;
129 /// Collection of BroadcastAreas
130 class ScBroadcastAreaSlot
132 private:
133 ScBroadcastAreas aBroadcastAreaTbl;
134 mutable ScBroadcastArea aTmpSeekBroadcastArea; // for FindBroadcastArea()
135 ScDocument* pDoc;
136 ScBroadcastAreaSlotMachine* pBASM;
138 ScBroadcastAreas::iterator FindBroadcastArea( const ScRange& rRange ) const;
141 More hypothetical (memory would probably be doomed anyway) check
142 whether there would be an overflow when adding an area, setting the
143 proper state if so.
145 @return TRUE if a HardRecalcState is effective and area is not to be
146 added.
148 bool CheckHardRecalcStateCondition() const;
150 public:
151 ScBroadcastAreaSlot( ScDocument* pDoc,
152 ScBroadcastAreaSlotMachine* pBASM );
153 ~ScBroadcastAreaSlot();
154 const ScBroadcastAreas& GetBroadcastAreas() const
155 { return aBroadcastAreaTbl; }
158 Only here new ScBroadcastArea objects are created, prevention of dupes.
160 @param rpArea
161 If NULL, a new ScBroadcastArea is created and assigned ton the
162 reference if a matching area wasn't found. If a matching area was
163 found, that is assigned. In any case, the SvtListener is added to
164 the broadcaster.
166 If not NULL then no listeners are startet, only the area is
167 inserted and the reference count incremented. Effectively the same
168 as InsertListeningArea(), so use that instead.
170 @return
171 TRUE if rpArea passed was NULL and ScBroadcastArea is newly
172 created.
174 bool StartListeningArea( const ScRange& rRange,
175 SvtListener* pListener,
176 ScBroadcastArea*& rpArea );
179 Insert a ScBroadcastArea obtained via StartListeningArea() to
180 subsequent slots.
182 void InsertListeningArea( ScBroadcastArea* pArea );
184 void EndListeningArea( const ScRange& rRange,
185 SvtListener* pListener,
186 ScBroadcastArea*& rpArea );
187 BOOL AreaBroadcast( const ScHint& rHint ) const;
188 /// @return TRUE if at least one broadcast occurred.
189 BOOL AreaBroadcastInRange( const ScRange& rRange,
190 const ScHint& rHint ) const;
191 void DelBroadcastAreasInRange( const ScRange& rRange );
192 void UpdateRemove( UpdateRefMode eUpdateRefMode,
193 const ScRange& rRange,
194 SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
195 void UpdateInsert( ScBroadcastArea* pArea );
200 BroadcastAreaSlots and their management, once per document.
203 class ScBroadcastAreaSlotMachine
205 private:
208 Slot offset arrangement of columns and rows, once per sheet.
210 +---+---+
211 | 0 | 3 |
212 +---+---+
213 | 1 | 4 |
214 +---+---+
215 | 2 | 5 |
216 +---+---+
219 /* TODO: When going for 1M rows this will definitely need some change, or
220 * with lots of referred sheets even the reservation of NULL pointers would
221 * be a memory hog. */
223 class TableSlots
225 public:
226 TableSlots();
227 ~TableSlots();
228 inline ScBroadcastAreaSlot** getSlots() { return ppSlots; }
231 Obtain slot pointer, no check on validity! It is assumed that
232 all calls are made with the result of ComputeSlotOfsset()
234 inline ScBroadcastAreaSlot* getAreaSlot( SCSIZE nOff ) { return *(ppSlots + nOff); }
236 private:
237 ScBroadcastAreaSlot** ppSlots;
239 // prevent usage
240 TableSlots( const TableSlots& );
241 TableSlots& operator=( const TableSlots& );
244 typedef ::std::map< SCTAB, TableSlots* > TableSlotsMap;
246 private:
247 ScBroadcastAreasBulk aBulkBroadcastAreas;
248 TableSlotsMap aTableSlotsMap;
249 SvtBroadcaster *pBCAlways; // for the RC_ALWAYS special range
250 ScDocument *pDoc;
251 ScBroadcastArea *pUpdateChain;
252 ScBroadcastArea *pEOUpdateChain;
253 ULONG nInBulkBroadcast;
255 inline SCSIZE ComputeSlotOffset( const ScAddress& rAddress ) const;
256 void ComputeAreaPoints( const ScRange& rRange,
257 SCSIZE& nStart, SCSIZE& nEnd,
258 SCSIZE& nRowBreak ) const;
260 public:
261 ScBroadcastAreaSlotMachine( ScDocument* pDoc );
262 ~ScBroadcastAreaSlotMachine();
263 void StartListeningArea( const ScRange& rRange,
264 SvtListener* pListener );
265 void EndListeningArea( const ScRange& rRange,
266 SvtListener* pListener );
267 BOOL AreaBroadcast( const ScHint& rHint ) const;
268 // return: at least one broadcast occurred
269 BOOL AreaBroadcastInRange( const ScRange& rRange, const ScHint& rHint ) const;
270 void DelBroadcastAreasInRange( const ScRange& rRange );
271 void UpdateBroadcastAreas( UpdateRefMode eUpdateRefMode,
272 const ScRange& rRange,
273 SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
274 void EnterBulkBroadcast();
275 void LeaveBulkBroadcast();
276 bool InsertBulkArea( const ScBroadcastArea* p );
277 /// @return: how many removed
278 size_t RemoveBulkArea( const ScBroadcastArea* p );
279 inline ScBroadcastArea* GetUpdateChain() const { return pUpdateChain; }
280 inline void SetUpdateChain( ScBroadcastArea* p ) { pUpdateChain = p; }
281 inline ScBroadcastArea* GetEOUpdateChain() const { return pEOUpdateChain; }
282 inline void SetEOUpdateChain( ScBroadcastArea* p ) { pEOUpdateChain = p; }
283 inline bool IsInBulkBroadcast() const { return nInBulkBroadcast > 0; }
287 class ScBulkBroadcast
289 ScBroadcastAreaSlotMachine* pBASM;
290 public:
291 explicit ScBulkBroadcast( ScBroadcastAreaSlotMachine* p ) : pBASM(p)
293 if (pBASM)
294 pBASM->EnterBulkBroadcast();
296 ~ScBulkBroadcast()
298 if (pBASM)
299 pBASM->LeaveBulkBroadcast();
301 void LeaveBulkBroadcast()
303 if (pBASM)
305 pBASM->LeaveBulkBroadcast();
306 pBASM = NULL;
311 #endif