1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef SC_DPTABDAT_HXX 29*cdf0e10cSrcweir #define SC_DPTABDAT_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "address.hxx" 32*cdf0e10cSrcweir #include "dpoutput.hxx" 33*cdf0e10cSrcweir #include "dpcachetable.hxx" 34*cdf0e10cSrcweir // Wang Xu Ming -- 2009-8-17 35*cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance 36*cdf0e10cSrcweir #include "dptablecache.hxx" 37*cdf0e10cSrcweir // End Comments 38*cdf0e10cSrcweir #include <tools/string.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <vector> 41*cdf0e10cSrcweir #include <set> 42*cdf0e10cSrcweir #include <hash_map> 43*cdf0e10cSrcweir #include <hash_set> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace sheet { 46*cdf0e10cSrcweir struct DataPilotFieldFilter; 47*cdf0e10cSrcweir }}}} 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir // ----------------------------------------------------------------------- 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #define SC_DAPI_DATE_HIERARCHIES 3 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir #define SC_DAPI_HIERARCHY_FLAT 0 55*cdf0e10cSrcweir #define SC_DAPI_HIERARCHY_QUARTER 1 56*cdf0e10cSrcweir #define SC_DAPI_HIERARCHY_WEEK 2 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #define SC_DAPI_FLAT_LEVELS 1 // single level for flat dates 59*cdf0e10cSrcweir #define SC_DAPI_QUARTER_LEVELS 4 // levels in year/quarter/month/day hierarchy 60*cdf0e10cSrcweir #define SC_DAPI_WEEK_LEVELS 3 // levels in year/week/day hierarchy 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir #define SC_DAPI_LEVEL_YEAR 0 63*cdf0e10cSrcweir #define SC_DAPI_LEVEL_QUARTER 1 64*cdf0e10cSrcweir #define SC_DAPI_LEVEL_MONTH 2 65*cdf0e10cSrcweir #define SC_DAPI_LEVEL_DAY 3 66*cdf0e10cSrcweir #define SC_DAPI_LEVEL_WEEK 1 67*cdf0e10cSrcweir #define SC_DAPI_LEVEL_WEEKDAY 2 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir // -------------------------------------------------------------------- 71*cdf0e10cSrcweir // 72*cdf0e10cSrcweir // base class ScDPTableData to allow implementation with tabular data 73*cdf0e10cSrcweir // by deriving only of this 74*cdf0e10cSrcweir // 75*cdf0e10cSrcweir #define SC_VALTYPE_EMPTY 0 76*cdf0e10cSrcweir #define SC_VALTYPE_VALUE 1 77*cdf0e10cSrcweir #define SC_VALTYPE_STRING 2 78*cdf0e10cSrcweir #define SC_VALTYPE_ERROR 3 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir struct ScDPValueData 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir double fValue; 83*cdf0e10cSrcweir sal_uInt8 nType; 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir void Set( double fV, sal_uInt8 nT ) { fValue = fV; nType = nT; } 86*cdf0e10cSrcweir }; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir class ScDPResultMember; 89*cdf0e10cSrcweir class ScDPDimension; 90*cdf0e10cSrcweir class ScDPLevel; 91*cdf0e10cSrcweir class ScDPInitState; 92*cdf0e10cSrcweir class ScDPResultMember; 93*cdf0e10cSrcweir class ScDocument; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir class SC_DLLPUBLIC ScDPTableData 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir // cached data for GetDatePart 98*cdf0e10cSrcweir long nLastDateVal; 99*cdf0e10cSrcweir long nLastHier; 100*cdf0e10cSrcweir long nLastLevel; 101*cdf0e10cSrcweir long nLastRet; 102*cdf0e10cSrcweir // Wang Xu Ming -- 2009-8-17 103*cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance 104*cdf0e10cSrcweir long mnCacheId; 105*cdf0e10cSrcweir const ScDocument* mpDoc; 106*cdf0e10cSrcweir // End Comments 107*cdf0e10cSrcweir public: 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir /** This structure stores dimension information used when calculating 110*cdf0e10cSrcweir results. These data are read only during result calculation, so it 111*cdf0e10cSrcweir should be passed as a const instance. */ 112*cdf0e10cSrcweir struct CalcInfo 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir ::std::vector<long> aColLevelDims; 115*cdf0e10cSrcweir ::std::vector<ScDPDimension*> aColDims; 116*cdf0e10cSrcweir ::std::vector<ScDPLevel*> aColLevels; 117*cdf0e10cSrcweir ::std::vector<long> aRowLevelDims; 118*cdf0e10cSrcweir ::std::vector<ScDPDimension*> aRowDims; 119*cdf0e10cSrcweir ::std::vector<ScDPLevel*> aRowLevels; 120*cdf0e10cSrcweir ::std::vector<long> aPageDims; 121*cdf0e10cSrcweir ::std::vector<long> aDataSrcCols; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir ScDPInitState* pInitState; 124*cdf0e10cSrcweir ScDPResultMember* pColRoot; 125*cdf0e10cSrcweir ScDPResultMember* pRowRoot; 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir bool bRepeatIfEmpty; 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir CalcInfo(); 130*cdf0e10cSrcweir }; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir // Wang Xu Ming -- 2009-8-17 133*cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance 134*cdf0e10cSrcweir ScDPTableData(ScDocument* pDoc, long nCacheId ); 135*cdf0e10cSrcweir // End Comments 136*cdf0e10cSrcweir virtual ~ScDPTableData(); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir long GetDatePart( long nDateVal, long nHierarchy, long nLevel ); 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir //! use (new) typed collection instead of ScStrCollection 141*cdf0e10cSrcweir //! or separate Str and ValueCollection 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir virtual long GetColumnCount() = 0; 144*cdf0e10cSrcweir // Wang Xu Ming -- 2009-8-17 145*cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance 146*cdf0e10cSrcweir virtual const std::vector< SCROW >& GetColumnEntries( long nColumn ) ; 147*cdf0e10cSrcweir long GetCacheId() const; 148*cdf0e10cSrcweir // End Comments 149*cdf0e10cSrcweir virtual String getDimensionName(long nColumn) = 0; 150*cdf0e10cSrcweir virtual sal_Bool getIsDataLayoutDimension(long nColumn) = 0; 151*cdf0e10cSrcweir virtual sal_Bool IsDateDimension(long nDim) = 0; 152*cdf0e10cSrcweir virtual sal_uLong GetNumberFormat(long nDim); 153*cdf0e10cSrcweir virtual sal_uInt32 GetNumberFormatByIdx( NfIndexTableOffset ); 154*cdf0e10cSrcweir virtual void DisposeData() = 0; 155*cdf0e10cSrcweir virtual void SetEmptyFlags( sal_Bool bIgnoreEmptyRows, sal_Bool bRepeatIfEmpty ) = 0; 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir virtual bool IsRepeatIfEmpty(); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir virtual void CreateCacheTable() = 0; 160*cdf0e10cSrcweir virtual void FilterCacheTable(const ::std::vector<ScDPCacheTable::Criterion>& rCriteria, const ::std::hash_set<sal_Int32>& rDataDims) = 0; 161*cdf0e10cSrcweir virtual void GetDrillDownData(const ::std::vector<ScDPCacheTable::Criterion>& rCriteria, 162*cdf0e10cSrcweir const ::std::hash_set<sal_Int32>& rCatDims, 163*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& rData) = 0; 164*cdf0e10cSrcweir virtual void CalcResults(CalcInfo& rInfo, bool bAutoShow) = 0; 165*cdf0e10cSrcweir virtual const ScDPCacheTable& GetCacheTable() const = 0; 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir // overloaded in ScDPGroupTableData: 168*cdf0e10cSrcweir virtual sal_Bool IsBaseForGroup(long nDim) const; 169*cdf0e10cSrcweir virtual long GetGroupBase(long nGroupDim) const; 170*cdf0e10cSrcweir virtual sal_Bool IsNumOrDateGroup(long nDim) const; 171*cdf0e10cSrcweir virtual sal_Bool IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex, 172*cdf0e10cSrcweir const ScDPItemData& rBaseData, long nBaseIndex ) const; 173*cdf0e10cSrcweir virtual sal_Bool HasCommonElement( const ScDPItemData& rFirstData, long nFirstIndex, 174*cdf0e10cSrcweir const ScDPItemData& rSecondData, long nSecondIndex ) const; 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir // Wang Xu Ming -- 2009-8-17 177*cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance 178*cdf0e10cSrcweir virtual long GetMembersCount( long nDim ); 179*cdf0e10cSrcweir virtual const ScDPItemData* GetMemberByIndex( long nDim, long nIndex ); 180*cdf0e10cSrcweir virtual const ScDPItemData* GetMemberById( long nDim, long nId); 181*cdf0e10cSrcweir virtual SCROW GetIdOfItemData( long nDim, const ScDPItemData& rData ); 182*cdf0e10cSrcweir virtual long GetSourceDim( long nDim ); 183*cdf0e10cSrcweir virtual long Compare( long nDim, long nDataId1, long nDataId2); 184*cdf0e10cSrcweir // End Comments 185*cdf0e10cSrcweir protected: 186*cdf0e10cSrcweir /** This structure stores vector arrays that hold intermediate data for 187*cdf0e10cSrcweir each row during cache table iteration. */ 188*cdf0e10cSrcweir struct CalcRowData 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir // Wang Xu Ming -- 2009-8-17 191*cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance 192*cdf0e10cSrcweir ::std::vector< SCROW > aColData; 193*cdf0e10cSrcweir ::std::vector< SCROW > aRowData; 194*cdf0e10cSrcweir ::std::vector< SCROW > aPageData; 195*cdf0e10cSrcweir // End Comments 196*cdf0e10cSrcweir ::std::vector<ScDPValueData> aValues; 197*cdf0e10cSrcweir }; 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir void FillRowDataFromCacheTable(sal_Int32 nRow, const ScDPCacheTable& rCacheTable, const CalcInfo& rInfo, CalcRowData& rData); 200*cdf0e10cSrcweir void ProcessRowData(CalcInfo& rInfo, CalcRowData& rData, bool bAutoShow); 201*cdf0e10cSrcweir void CalcResultsFromCacheTable(const ScDPCacheTable& rCacheTable, CalcInfo& rInfo, bool bAutoShow); 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir private: 204*cdf0e10cSrcweir // Wang Xu Ming -- 2009-8-17 205*cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance 206*cdf0e10cSrcweir void GetItemData(const ScDPCacheTable& rCacheTable, sal_Int32 nRow, 207*cdf0e10cSrcweir const ::std::vector<long>& rDims, ::std::vector< SCROW >& rItemData); 208*cdf0e10cSrcweir // End Comments 209*cdf0e10cSrcweir }; 210*cdf0e10cSrcweir #endif 211*cdf0e10cSrcweir 212