LCOV - code coverage report
Current view: top level - sc/inc - dptabres.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 49 0.0 %
Date: 2014-04-14 Functions: 0 48 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10