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

Generated by: LCOV version 1.10