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