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

Generated by: LCOV version 1.10