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