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