xref: /aoo42x/main/sc/inc/dptabres.hxx (revision 38d50f7b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_DPTABRES_HXX
25 #define SC_DPTABRES_HXX
26 
27 #include <svl/svarray.hxx>
28 #include <tools/string.hxx>
29 #include <com/sun/star/sheet/MemberResult.hpp>
30 #include <com/sun/star/sheet/DataResult.hpp>
31 #include <com/sun/star/uno/Sequence.hxx>
32 #include "global.hxx"		// enum ScSubTotalFunc
33 #include "dpcachetable.hxx"
34 #include <hash_map>
35 #include <hash_set>
36 #include <vector>
37 #include <memory>
38 
39 namespace com { namespace sun { namespace star { namespace sheet {
40     struct DataPilotFieldReference;
41 } } } }
42 
43 
44 class ScAddress;
45 class ScDocument;
46 class ScDPSource;
47 class ScDPDimension;
48 class ScDPDimensions;
49 class ScDPLevel;
50 class ScDPMember;
51 class ScDPAggData;
52 class ScDPResultMember;
53 class ScDPResultVisibilityData;
54 
55 struct ScDPValueData;
56 // Wang Xu Ming -- 2009-8-17
57 // DataPilot Migration - Cache&&Performance
58 class ScDPItemData;
59 // End Comments
60 //
61 //  Member names that are being processed for InitFrom/LateInitFrom
62 //  (needed for initialization of grouped items)
63 //
64 
65 class ScDPInitState
66 {
67     long*           pIndex;     // array
68 // Wang Xu Ming -- 2009-8-17
69 // DataPilot Migration - Cache&&Performance
70     SCROW*     pData; // array
71  // End Comments
72     long            nCount;
73 
74 public:
75             ScDPInitState();
76             ~ScDPInitState();
77 
78     void    AddMember( long nSourceIndex,SCROW nMember);
79     void    RemoveMember();
80 
GetCount() const81     long                GetCount() const    { return nCount; }
GetSource() const82     const long*         GetSource() const   { return pIndex; }
83 // Wang Xu Ming -- 2009-8-17
84 // DataPilot Migration - Cache&&Performance
GetNameIds() const85     const SCROW* GetNameIds() const    { return pData; }
86     SCROW   GetNameIdForIndex( long nIndexValue ) const;
87 // End Comments
88 };
89 
90 typedef ::std::vector<sal_Int32> ScMemberSortOrder;
91 
92 //
93 //	selected subtotal information, passed down the dimensions
94 //
95 
96 struct ScDPSubTotalState
97 {
98 	ScSubTotalFunc eColForce;
99 	ScSubTotalFunc eRowForce;
100 	long nColSubTotalFunc;
101 	long nRowSubTotalFunc;
102 
ScDPSubTotalStateScDPSubTotalState103 	ScDPSubTotalState() :
104 		eColForce( SUBTOTAL_FUNC_NONE ),
105 		eRowForce( SUBTOTAL_FUNC_NONE ),
106 		nColSubTotalFunc( -1 ),
107 		nRowSubTotalFunc( -1 )
108 	{}
109 };
110 
111 //
112 //  indexes when calculating running totals
113 //  Col/RowVisible: simple counts from 0 - without sort order applied - visible index
114 //                  (only used for running total / relative index)
115 //  Col/RowIndexes: with sort order applied - member index
116 //                  (used otherwise - so other members' children can be accessed)
117 //
118 
119 class ScDPRunningTotalState
120 {
121     ScDPResultMember*   pColResRoot;
122     ScDPResultMember*   pRowResRoot;
123     long*               pColVisible;
124     long*               pColIndexes;
125     long*               pRowVisible;
126     long*               pRowIndexes;
127     long                nColIndexPos;
128     long                nRowIndexPos;
129 
130 public:
131             ScDPRunningTotalState( ScDPResultMember* pColRoot, ScDPResultMember* pRowRoot );
132             ~ScDPRunningTotalState();
133 
GetColResRoot() const134     ScDPResultMember*   GetColResRoot() const   { return pColResRoot; }
GetRowResRoot() const135     ScDPResultMember*   GetRowResRoot() const   { return pRowResRoot; }
136 
GetColVisible() const137     const long*         GetColVisible() const   { return pColVisible; }
GetColIndexes() const138     const long*         GetColIndexes() const   { return pColIndexes; }
GetRowVisible() const139     const long*         GetRowVisible() const   { return pRowVisible; }
GetRowIndexes() const140     const long*         GetRowIndexes() const   { return pRowIndexes; }
141 
142     void    AddColIndex( long nVisible, long nSorted );
143     void    AddRowIndex( long nVisible, long nSorted );
144     void    RemoveColIndex();
145     void    RemoveRowIndex();
146 };
147 
148 struct ScDPRelativePos
149 {
150     long    nBasePos;       // simple count, without sort order applied
151     long    nDirection;
152 
153     ScDPRelativePos( long nBase, long nDir );
154 };
155 
156 //
157 //	aggregated data
158 //!	separate header file?
159 //
160 
161 //  Possible values for the nCount member:
162 //  (greater than 0 counts the collected values)
163 const long SC_DPAGG_EMPTY        =  0;  // empty during data collection
164 const long SC_DPAGG_DATA_ERROR   = -1;  // error during data collection
165 const long SC_DPAGG_RESULT_EMPTY = -2;  // empty result calculated
166 const long SC_DPAGG_RESULT_VALID = -3;  // valid result calculated
167 const long SC_DPAGG_RESULT_ERROR = -4;  // error in calculated result
168 
169 class ScDPAggData
170 {
171 private:
172 	double			fVal;
173 	double			fAux;
174 	long			nCount;
175 	ScDPAggData*	pChild;
176 
177 public:
ScDPAggData()178 			ScDPAggData() : fVal(0.0), fAux(0.0), nCount(SC_DPAGG_EMPTY), pChild(NULL) {}
~ScDPAggData()179 			~ScDPAggData() { delete pChild; }
180 
181 	void	Update( const ScDPValueData& rNext, ScSubTotalFunc eFunc, const ScDPSubTotalState& rSubState );
182 	void	Calculate( ScSubTotalFunc eFunc, const ScDPSubTotalState& rSubState );
183 	sal_Bool	IsCalculated() const;
184 
185 	double	GetResult() const;
186 	sal_Bool	HasError() const;
187 	sal_Bool	HasData() const;
188 
189 	void	SetResult( double fNew );
190 	void	SetEmpty( sal_Bool bSet );
191 	void	SetError();
192 
193 	double	GetAuxiliary() const;
194 	void	SetAuxiliary( double fNew );
195 
196 	void    Reset();        // also deletes children
197 
GetExistingChild() const198 	const ScDPAggData*	GetExistingChild() const	{ return pChild; }
199 	ScDPAggData*		GetChild();
200 };
201 
202 //
203 //  Row and grand total state, passed down (column total is at result member)
204 //
205 
206 class ScDPRowTotals
207 {
208     ScDPAggData aRowTotal;
209     ScDPAggData aGrandTotal;
210     sal_Bool        bIsInColRoot;
211 
212 public:
213             ScDPRowTotals();
214             ~ScDPRowTotals();
215 
216     ScDPAggData*    GetRowTotal( long nMeasure );
217     ScDPAggData*    GetGrandTotal( long nMeasure );
218 
IsInColRoot() const219     sal_Bool            IsInColRoot() const     { return bIsInColRoot; }
SetInColRoot(sal_Bool bSet)220     void            SetInColRoot(sal_Bool bSet) { bIsInColRoot = bSet; }
221 };
222 
223 // --------------------------------------------------------------------
224 //
225 //	results for a hierarchy dimension
226 //
227 
228 #define SC_DP_RES_GROW	16
229 
230 class ScDPResultDimension;
231 class ScDPDataDimension;
232 class ScDPDataMember;
233 
234 #define SC_DPMEASURE_ALL	-1
235 #define SC_DPMEASURE_ANY	-2
236 // Wang Xu Ming -- 2009-8-17
237 // DataPilot Migration - Cache&&Performance
238 
239 struct MemberHashIndexFunc : public std::unary_function< const SCROW &, size_t >
240 {
operator ()MemberHashIndexFunc241 	size_t operator() (const SCROW &rDataIndex) const { return rDataIndex; }
242 };
243 
244 class ScDPParentDimData
245 {
246 public:
247 	const SCROW						mnOrder;						//! Ref
248 	const ScDPDimension*			mpParentDim;			//! Ref
249 	const ScDPLevel*				mpParentLevel;			//! Ref
250 	const ScDPMember*				mpMemberDesc;			//! Ref
251 
ScDPParentDimData()252 	ScDPParentDimData():mnOrder(-1), mpParentDim( NULL), mpParentLevel( NULL ), mpMemberDesc( NULL ){}
ScDPParentDimData(const SCROW nIndex,ScDPDimension * pDim,const ScDPLevel * pLev,const ScDPMember * pMember)253 	ScDPParentDimData( const SCROW nIndex, ScDPDimension* pDim, const ScDPLevel* pLev, const ScDPMember* pMember ): mnOrder( nIndex ), mpParentDim( pDim), mpParentLevel( pLev ), mpMemberDesc( pMember ){}
254 };
255 
256 typedef std::vector <ScDPParentDimData *>                 DimMemberArray;
257 typedef std::hash_map < SCROW, ScDPParentDimData *, MemberHashIndexFunc>  DimMemberHash;
258 
259 class ResultMembers
260 {
261     DimMemberHash      maMemberHash;
262     sal_Bool 				mbHasHideDetailsMember;
263 public:
264     ScDPParentDimData* FindMember( const SCROW& nIndex ) const;
265     void                             InsertMember(  ScDPParentDimData* pNew );
IsHasHideDetailsMembers() const266     sal_Bool			IsHasHideDetailsMembers() const { return mbHasHideDetailsMember; }
SetHasHideDetailsMembers(sal_Bool b)267     void			SetHasHideDetailsMembers( sal_Bool b ) { mbHasHideDetailsMember=b; }
268     ResultMembers();
269     virtual ~ResultMembers();
270 };
271 
272 class LateInitParams
273 {
274 private:
275     const ::std::vector<ScDPDimension*>& mppDim;
276     const ::std::vector<ScDPLevel*>& mppLev;
277 
278     sal_Bool      mbRow;
279     sal_Bool      mbInitChild;
280     sal_Bool      mbAllChildren;
281 public:
282     LateInitParams( const ::std::vector<ScDPDimension*>& ppDim, const ::std::vector<ScDPLevel*>& ppLev,
283         sal_Bool bRow, sal_Bool bInitChild = sal_True , sal_Bool bAllChildren = sal_False);
284     ~LateInitParams();
285 
SetInitChild(sal_Bool b)286     void  SetInitChild( sal_Bool b ) { mbInitChild = b; }
SetInitAllChildren(sal_Bool b)287     void  SetInitAllChildren( sal_Bool b ) { mbAllChildren = b; }
288 
GetDim(size_t nPos) const289     inline ScDPDimension* GetDim( size_t nPos ) const { return mppDim[nPos];}
GetLevel(size_t nPos) const290     inline ScDPLevel*         GetLevel( size_t nPos ) const { return mppLev[nPos];}
291 
GetInitChild() const292     inline sal_Bool  GetInitChild() const {return mbInitChild; }
GetInitAllChild() const293     inline sal_Bool  GetInitAllChild() const { return mbAllChildren; }
IsRow() const294     inline sal_Bool  IsRow() const { return mbRow; }
295     sal_Bool  IsEnd( size_t nPos ) const ;
296 };
297 // End Comments
298 
299 class ScDPResultData
300 {
301 private:
302 	ScDPSource*				pSource;				//! Ref
303 	//!	keep things like measure lists here
304 
305 	long					nMeasCount;
306 	ScSubTotalFunc*			pMeasFuncs;
307 	::com::sun::star::sheet::DataPilotFieldReference* pMeasRefs;
308 	sal_uInt16*					pMeasRefOrient;
309 	String*					pMeasNames;
310 	sal_Bool					bLateInit;
311 	sal_Bool					bDataAtCol;
312 	sal_Bool					bDataAtRow;
313 
314 	//! add "displayed values" settings
315     	mutable std::vector< ResultMembers* > mpDimMembers;
316 public:
317 						ScDPResultData( ScDPSource* pSrc );		//! Ref
318 						~ScDPResultData();
319 
320 	void				SetMeasureData( long nCount, const ScSubTotalFunc* pFunctions,
321 										const ::com::sun::star::sheet::DataPilotFieldReference* pRefs,
322 										const sal_uInt16* pRefOrient, const String* pNames );
323 	void				SetDataLayoutOrientation( sal_uInt16 nOrient );
324 	void				SetLateInit( sal_Bool bSet );
325 
GetMeasureCount() const326 	long				GetMeasureCount() const		{ return nMeasCount; }
327 	ScSubTotalFunc		GetMeasureFunction(long nMeasure) const;
328     String              GetMeasureString(long nMeasure, sal_Bool bForce, ScSubTotalFunc eForceFunc, bool& rbTotalResult) const;
329 	String				GetMeasureDimensionName(long nMeasure) const;
330 	const ::com::sun::star::sheet::DataPilotFieldReference& GetMeasureRefVal(long nMeasure) const;
331 	sal_uInt16				GetMeasureRefOrient(long nMeasure) const;
332 
IsDataAtCol() const333 	sal_Bool				IsDataAtCol() const				{ return bDataAtCol; }
IsDataAtRow() const334 	sal_Bool				IsDataAtRow() const				{ return bDataAtRow; }
IsLateInit() const335 	sal_Bool				IsLateInit() const				{ return bLateInit; }
336 
337 	long				GetColStartMeasure() const;
338 	long				GetRowStartMeasure() const;
339 
GetCountForMeasure(long nMeas) const340 	long				GetCountForMeasure( long nMeas ) const
341 								{ return ( nMeas == SC_DPMEASURE_ALL ) ? nMeasCount : 1; }
342 
343     sal_Bool                IsBaseForGroup( long nDim ) const;              // any group
344     long                GetGroupBase( long nGroupDim ) const;
345     sal_Bool                IsNumOrDateGroup( long nDim ) const;
346  // Wang Xu Ming -- 2009-8-17
347 // DataPilot Migration - Cache&&Performance
348     sal_Bool                IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
349                                                long nBaseDataId, long nBaseIndex ) const;
350     sal_Bool                IsInGroup( SCROW nGroupDataId, long nGroupIndex,
351                                               const ScDPItemData& rBaseData, long nBaseIndex ) const;
352     sal_Bool                HasCommonElement( SCROW nFirstDataId, long nFirstIndex,
353                                           const ScDPItemData& rSecondData, long nSecondIndex ) const;
354 
355     ResultMembers* GetDimResultMembers( long nDim , ScDPDimension* pDim , ScDPLevel*   pLevel) const ;
356 
357 // End Comments
358     const ScDPSource*   GetSource() const;
359 };
360 
361 
362 class ScDPResultMember
363 {
364 private:
365     const ScDPResultData*   pResultData;
366     // Wang Xu Ming -- 2009-8-17
367     // DataPilot Migration - Cache&&Performance
368     ScDPParentDimData        aParentDimData;
369     // End Comments
370 	ScDPResultDimension*	pChildDimension;
371 	ScDPDataMember*			pDataRoot;
372 	sal_Bool					bHasElements;
373 	sal_Bool					bForceSubTotal;
374 	sal_Bool					bHasHiddenDetails;
375 	sal_Bool					bInitialized;
376 	sal_Bool                    bAutoHidden;
377 	ScDPAggData				aColTotal;				// to store column totals
378 
379 	sal_uInt16					nMemberStep;			// step to show details
380 public:
381     // Wang Xu Ming -- 2009-8-17
382     // DataPilot Migration - Cache&&Performance
383     ScDPResultMember(  const ScDPResultData* pData,  const ScDPParentDimData& rParentDimData,
384         sal_Bool bForceSub );  //! Ref
385     ScDPResultMember(  const ScDPResultData* pData, sal_Bool bForceSub );
386     // End Comments
387     ~ScDPResultMember();
388 
389     // Wang Xu Ming -- 2009-8-17
390     // DataPilot Migration - Cache&&Performance
391     void                InitFrom( const ::std::vector<ScDPDimension*>& ppDim,
392                                         const ::std::vector<ScDPLevel*>& ppLev,
393                                         size_t nPos,
394                                         ScDPInitState& rInitState,
395                                         sal_Bool bInitChild = sal_True );
396     void               LateInitFrom(
397                                         LateInitParams& rParams,
398                                         const ::std::vector< SCROW >& pItemData,
399                                         size_t nPos,
400                                         ScDPInitState& rInitState);
401     void              CheckShowEmpty( sal_Bool bShow = sal_False );
402     // End Comments
403 	String				GetName() const;
404     void                FillItemData( ScDPItemData& rData ) const;
405 	sal_Bool				IsValid() const;
406 	sal_Bool				IsVisible() const;
407 	long				GetSize(long nMeasure) const;
408 	sal_Bool				HasHiddenDetails() const;
409 	sal_Bool                IsSubTotalInTitle(long nMeasure) const;
410 
411 //	sal_Bool				SubTotalEnabled() const;
412 	long				GetSubTotalCount( long* pUserSubStart = NULL ) const;
413 
414     // Wang Xu Ming -- 2009-8-17
415     // DataPilot Migration - Cache&&Performance
416     sal_Bool              IsNamedItem( SCROW nIndex ) const;
417     bool IsValidEntry( const ::std::vector< SCROW >& aMembers ) const;
418     // End Comments
419 
SetHasElements()420 	void				SetHasElements()	{ bHasElements = sal_True; }
SetAutoHidden()421 	void                SetAutoHidden()     { bAutoHidden = sal_True; }
422 
423     // Wang Xu Ming -- 2009-8-17
424     // DataPilot Migration - Cache&&Performance
425     void                ProcessData( const ::std::vector<SCROW>& aChildMembers,
426                                         const ScDPResultDimension* pDataDim,
427                                         const ::std::vector<SCROW>& aDataMembers,
428                                         const ::std::vector<ScDPValueData>& aValues );
429     // End Comments
430 	void				FillMemberResults( com::sun::star::uno::Sequence<
431 												com::sun::star::sheet::MemberResult>* pSequences,
432 											long& rPos, long nMeasure, sal_Bool bRoot,
433 											const String* pMemberName,
434 											const String* pMemberCaption );
435 
436 	void				FillDataResults( const ScDPResultMember* pRefMember,
437 									com::sun::star::uno::Sequence<
438 										com::sun::star::uno::Sequence<
439 											com::sun::star::sheet::DataResult> >& rSequence,
440 									long& rRow, long nMeasure ) const;
441 
442 	void				UpdateDataResults( const ScDPResultMember* pRefMember, long nMeasure ) const;
443 	void				UpdateRunningTotals( const ScDPResultMember* pRefMember, long nMeasure,
444 												ScDPRunningTotalState& rRunning, ScDPRowTotals& rTotals ) const;
445 
446     void                SortMembers( ScDPResultMember* pRefMember );
447     void                DoAutoShow( ScDPResultMember* pRefMember );
448 
449     void                ResetResults( sal_Bool bRoot );
450 
451 	void				DumpState( const ScDPResultMember* pRefMember, ScDocument* pDoc, ScAddress& rPos ) const;
452 
453 						//!	this will be removed!
GetChildDimension() const454 	const ScDPResultDimension*	GetChildDimension() const	{ return pChildDimension; }
GetChildDimension()455 	ScDPResultDimension*		GetChildDimension()			{ return pChildDimension; }
456 
GetDataRoot() const457 	ScDPDataMember*			GetDataRoot() const				{ return pDataRoot; }
458 
459     // Wang Xu Ming -- 2009-8-17
460     // DataPilot Migration - Cache&&Performance
GetParentDim() const461     const ScDPDimension*  GetParentDim() const               { return aParentDimData.mpParentDim; }     //! Ref
GetParentLevel() const462     const ScDPLevel*         GetParentLevel() const         { return aParentDimData.mpParentLevel; }   //! Ref
GetDPMember() const463     const ScDPMember*     GetDPMember()const              { return aParentDimData.mpMemberDesc; }    //! Ref
GetOrder() const464     inline SCROW               GetOrder() const                           { return aParentDimData.mnOrder; }         //! Ref
IsRoot() const465     inline sal_Bool                  IsRoot() const                       { return GetParentLevel() == NULL; }
466     SCROW                       GetDataId( ) const ;
467     // End Comments
468 	ScDPAggData*		GetColTotal( long nMeasure ) const;
469 
470     void                FillVisibilityData(ScDPResultVisibilityData& rData) const;
471 };
472 
473 class ScDPDataMember
474 {
475 private:
476     const ScDPResultData*       pResultData;
477 	const ScDPResultMember*		pResultMember;			//! Ref?
478 	ScDPDataDimension*		pChildDimension;
479 	ScDPAggData				aAggregate;
480 
481     void                UpdateValues( const ::std::vector<ScDPValueData>& aValues, const ScDPSubTotalState& rSubState );
482 
483 public:
484                         ScDPDataMember( const ScDPResultData* pData, const ScDPResultMember* pRes );
485 						~ScDPDataMember();
486 
487 	void				InitFrom( const ScDPResultDimension* pDim );
488 
489 	String				GetName() const;
490 	sal_Bool				IsVisible() const;
491 	sal_Bool				HasData( long nMeasure, const ScDPSubTotalState& rSubState ) const;
492 
493     // Wang Xu Ming -- 2009-8-17
494     // DataPilot Migration - Cache&&Performance
495     sal_Bool              IsNamedItem(   SCROW r ) const;
496     // End Comments
497 	sal_Bool				HasHiddenDetails() const;
498 
499     // Wang Xu Ming -- 2009-8-17
500     // DataPilot Migration - Cache&&Performance
501     void                ProcessData( const ::std::vector< SCROW >& aChildMembers, const ::std::vector<ScDPValueData>& aValues,
502                                        const ScDPSubTotalState& rSubState );
503     // End Comments
504 	sal_Bool				HasError( long nMeasure, const ScDPSubTotalState& rSubState ) const;
505 	double				GetAggregate( long nMeasure, const ScDPSubTotalState& rSubState ) const;
506 	const ScDPAggData*	GetConstAggData( long nMeasure, const ScDPSubTotalState& rSubState ) const;
507 	ScDPAggData*		GetAggData( long nMeasure, const ScDPSubTotalState& rSubState );
508 
509 	void				FillDataRow( const ScDPResultMember* pRefMember,
510 									com::sun::star::uno::Sequence<com::sun::star::sheet::DataResult>& rSequence,
511 									long& rCol, long nMeasure, sal_Bool bIsSubTotalRow,
512 									const ScDPSubTotalState& rSubState ) const;
513 
514 	void				UpdateDataRow( const ScDPResultMember* pRefMember, long nMeasure, sal_Bool bIsSubTotalRow,
515 									const ScDPSubTotalState& rSubState );
516 	void				UpdateRunningTotals( const ScDPResultMember* pRefMember, long nMeasure, sal_Bool bIsSubTotalRow,
517 									const ScDPSubTotalState& rSubState, ScDPRunningTotalState& rRunning,
518 									ScDPRowTotals& rTotals, const ScDPResultMember& rRowParent );
519 
520     void                SortMembers( ScDPResultMember* pRefMember );
521     void                DoAutoShow( ScDPResultMember* pRefMember );
522 
523     void                ResetResults();
524 
525 	void				DumpState( const ScDPResultMember* pRefMember, ScDocument* pDoc, ScAddress& rPos ) const;
526 
527 						//!	this will be removed!
GetChildDimension() const528 	const ScDPDataDimension*	GetChildDimension() const	{ return pChildDimension; }
GetChildDimension()529 	ScDPDataDimension*			GetChildDimension()			{ return pChildDimension; }
530 };
531 
532 //!	replace PtrArr with 32-bit array ????
533 
534 typedef ScDPDataMember* ScDPDataMemberPtr;
535 SV_DECL_PTRARR_DEL(ScDPDataMembers, ScDPDataMemberPtr, SC_DP_RES_GROW, SC_DP_RES_GROW)
536 
537 
538 //	result dimension contains only members
539 
540 class ScDPResultDimension
541 {
542 public :
543     // Wang Xu Ming -- 2009-8-17
544     // DataPilot Migration - Cache&&Performance
545     typedef std::vector <ScDPResultMember *>                           MemberArray;
546     typedef std::map < SCROW , ScDPResultMember *> MemberHash;
547     // End Comments
548 private:
549     	const ScDPResultData*   pResultData;
550 	MemberArray				maMemberArray;
551 	MemberHash				maMemberHash;
552 	sal_Bool                    bInitialized;
553 	String					aDimensionName;		//! or ptr to IntDimension?
554 	sal_Bool					bIsDataLayout;		//! or ptr to IntDimension?
555 	sal_Bool                    bSortByData;
556 	sal_Bool                    bSortAscending;
557 	long                    nSortMeasure;
558 	ScMemberSortOrder       aMemberOrder;       // used when sorted by measure
559 	sal_Bool                    bAutoShow;
560 	sal_Bool                    bAutoTopItems;
561 	long                    nAutoMeasure;
562 	long                    nAutoCount;
563 
564     // Wang Xu Ming -- 2009-8-17
565     // DataPilot Migration - Cache&&Performance
566     ScDPResultMember*        FindMember(   SCROW  iData ) const;
567     ScDPResultMember*        AddMember( const ScDPParentDimData& aData );
568     ScDPResultMember*        InsertMember( ScDPParentDimData* pMemberData );
569     ResultMembers*               GetResultMember( ScDPDimension* pDim, ScDPLevel* pLevel );
570     void                                  InitWithMembers( LateInitParams& rParams,
571                                                             const ::std::vector< SCROW >& pItemData,
572                                                             size_t  nPos,
573                                                             ScDPInitState& rInitState  );
574     // End Comments
575 public:
576        ScDPResultDimension( const ScDPResultData* pData );
577 	~ScDPResultDimension();
578 
579                         //	allocates new members
580     // Wang Xu Ming -- 2009-8-17
581     // DataPilot Migration - Cache&&Performance
582     void                InitFrom( const ::std::vector<ScDPDimension*>& ppDim,
583                                         const ::std::vector<ScDPLevel*>& ppLev,
584                                         size_t nPos,
585                                         ScDPInitState& rInitState ,  sal_Bool bInitChild = sal_True );
586     void                LateInitFrom(  LateInitParams& rParams,
587                                         const ::std::vector< SCROW >& pItemData,
588                                         size_t nPos,
589                                         ScDPInitState& rInitState );
590     void               CheckShowEmpty( sal_Bool bShow = sal_False );
591 
592     // End Comments
593     long				GetSize(long nMeasure) const;
594 
595     // Wang Xu Ming -- 2009-8-17
596     // DataPilot Migration - Cache&&Performance
597     bool                IsValidEntry( const ::std::vector<SCROW>& aMembers ) const;
598 
599     //	modifies existing members, allocates data dimensions
600 	void				ProcessData( const ::std::vector<SCROW>& aMembers,
601                                      const ScDPResultDimension* pDataDim,
602                                      const ::std::vector<SCROW>& aDataMembers,
603                                      const ::std::vector<ScDPValueData>& aValues ) const;	//! Test
604  // End Comments
605 	void				FillMemberResults( com::sun::star::uno::Sequence<
606 												com::sun::star::sheet::MemberResult>* pSequences,
607 											long nStart, long nMeasure );
608 
609 	void				FillDataResults( const ScDPResultMember* pRefMember,
610 									com::sun::star::uno::Sequence<
611 										com::sun::star::uno::Sequence<
612 											com::sun::star::sheet::DataResult> >& rSequence,
613 									long nRow, long nMeasure ) const;
614 
615 	void				UpdateDataResults( const ScDPResultMember* pRefMember, long nMeasure ) const;
616 	void				UpdateRunningTotals( const ScDPResultMember* pRefMember, long nMeasure,
617 											ScDPRunningTotalState& rRunning, ScDPRowTotals& rTotals ) const;
618 
619     void                SortMembers( ScDPResultMember* pRefMember );
620     long                GetSortedIndex( long nUnsorted ) const;
621 
622     void                DoAutoShow( ScDPResultMember* pRefMember );
623 
624     void                ResetResults();
625 
626 						//	called for the reference dimension
627 	ScDPDataMember*		GetRowReferenceMember( const ScDPRelativePos* pMemberPos, const String* pName,
628 									const long* pRowIndexes, const long* pColIndexes ) const;
629 
630 						//	uses row root member from ScDPRunningTotalState
631 	static ScDPDataMember* GetColReferenceMember( const ScDPRelativePos* pMemberPos, const String* pName,
632 									long nRefDimPos, const ScDPRunningTotalState& rRunning );
633 
634 	void				DumpState( const ScDPResultMember* pRefMember, ScDocument* pDoc, ScAddress& rPos ) const;
635 
636 						//	for ScDPDataDimension::InitFrom
637 	long				GetMemberCount() const;
638 	const ScDPResultMember*	GetMember(long n) const;
639 	ScDPResultMember*		GetMember(long n);
640 
GetMemberOrder() const641 	const ScMemberSortOrder& GetMemberOrder() const     { return aMemberOrder; }
GetMemberOrder()642 	ScMemberSortOrder&  GetMemberOrder()                { return aMemberOrder; }
643 
IsDataLayout() const644 	sal_Bool				IsDataLayout() const	{ return bIsDataLayout; }
GetName() const645 	String				GetName() const			{ return aDimensionName; }
646 
IsSortByData() const647 	sal_Bool                IsSortByData() const    { return bSortByData; }
IsSortAscending() const648 	sal_Bool                IsSortAscending() const { return bSortAscending; }
GetSortMeasure() const649 	long                GetSortMeasure() const  { return nSortMeasure; }
650 
IsAutoShow() const651 	sal_Bool                IsAutoShow() const      { return bAutoShow; }
IsAutoTopItems() const652 	sal_Bool                IsAutoTopItems() const  { return bAutoTopItems; }
GetAutoMeasure() const653 	long                GetAutoMeasure() const  { return nAutoMeasure; }
GetAutoCount() const654 	long                GetAutoCount() const    { return nAutoCount; }
655 
656 	ScDPResultDimension* GetFirstChildDimension() const;
657 
658     void                FillVisibilityData(ScDPResultVisibilityData& rData) const;
659 };
660 
661 class ScDPDataDimension
662 {
663 private:
664     const ScDPResultData*		pResultData;
665 	const ScDPResultDimension* pResultDimension;  // column
666 	ScDPDataMembers		aMembers;
667 	sal_Bool				bIsDataLayout;		//! or ptr to IntDimension?
668 
669 public:
670                         ScDPDataDimension( const ScDPResultData* pData );
671 						~ScDPDataDimension();
672 
673 	void				InitFrom( const ScDPResultDimension* pDim );		// recursive
674     // Wang Xu Ming -- 2009-8-17
675     // DataPilot Migration - Cache&&Performance
676     void                ProcessData( const ::std::vector< SCROW >& aDataMembers, const ::std::vector<ScDPValueData>& aValues,
677                                        const ScDPSubTotalState& rSubState );
678     // End Comments
679 	void				FillDataRow( const ScDPResultDimension* pRefDim,
680 									com::sun::star::uno::Sequence<com::sun::star::sheet::DataResult>& rSequence,
681 									long nCol, long nMeasure, sal_Bool bIsSubTotalRow,
682 									const ScDPSubTotalState& rSubState ) const;
683 
684 	void				UpdateDataRow( const ScDPResultDimension* pRefDim, long nMeasure, sal_Bool bIsSubTotalRow,
685 									const ScDPSubTotalState& rSubState ) const;
686 	void				UpdateRunningTotals( const ScDPResultDimension* pRefDim, long nMeasure, sal_Bool bIsSubTotalRow,
687 									const ScDPSubTotalState& rSubState, ScDPRunningTotalState& rRunning,
688 									ScDPRowTotals& rTotals, const ScDPResultMember& rRowParent ) const;
689 
690     void                SortMembers( ScDPResultDimension* pRefDim );
691     long                GetSortedIndex( long nUnsorted ) const;
692 
693     void                DoAutoShow( ScDPResultDimension* pRefDim );
694 
695     void                ResetResults();
696 
697 	void				DumpState( const ScDPResultDimension* pRefDim, ScDocument* pDoc, ScAddress& rPos ) const;
698 
699 	long				GetMemberCount() const;
700 	ScDPDataMember*		GetMember(long n) const;
701 };
702 
703 // ----------------------------------------------------------------------------
704 
705 /**
706  * This class collects visible members of each dimension and uses that
707  * information to create filtering criteria (e.g. for drill-down data).
708  */
709 class ScDPResultVisibilityData
710 {
711 public:
712     // Wang Xu Ming -- 2009-8-17
713     // DataPilot Migration - Cache&&Performance
714     ScDPResultVisibilityData( ScDPSource* pSource);
715     // End Comments
716     ~ScDPResultVisibilityData();
717 
718     void addVisibleMember(const String& rDimName, const ScDPItemData& rMemberItem);
719     void fillFieldFilters(::std::vector<ScDPCacheTable::Criterion>& rFilters) const;
720 
721 private:
722     struct MemberHash
723     {
724         size_t operator()(const ScDPItemData& r) const;
725     };
726     typedef ::std::hash_set<ScDPItemData, MemberHash> VisibleMemberType;
727     typedef ::std::hash_map<String, VisibleMemberType, ScStringHashCode> DimMemberType;
728     DimMemberType maDimensions;
729 
730     ScDPSource* mpSource;
731 };
732 
733 #endif
734 
735