1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dptabdat.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_DPTABDAT_HXX
32 #define SC_DPTABDAT_HXX
34 #include "address.hxx"
35 #include "dpoutput.hxx"
36 #include "dpcachetable.hxx"
38 #include <tools/string.hxx>
45 namespace com
{ namespace sun
{ namespace star
{ namespace sheet
{
46 struct DataPilotFieldFilter
;
49 class TypedScStrCollection
;
50 class ScSimpleSharedString
;
52 // -----------------------------------------------------------------------
54 #define SC_DAPI_DATE_HIERARCHIES 3
56 #define SC_DAPI_HIERARCHY_FLAT 0
57 #define SC_DAPI_HIERARCHY_QUARTER 1
58 #define SC_DAPI_HIERARCHY_WEEK 2
60 #define SC_DAPI_FLAT_LEVELS 1 // single level for flat dates
61 #define SC_DAPI_QUARTER_LEVELS 4 // levels in year/quarter/month/day hierarchy
62 #define SC_DAPI_WEEK_LEVELS 3 // levels in year/week/day hierarchy
64 #define SC_DAPI_LEVEL_YEAR 0
65 #define SC_DAPI_LEVEL_QUARTER 1
66 #define SC_DAPI_LEVEL_MONTH 2
67 #define SC_DAPI_LEVEL_DAY 3
68 #define SC_DAPI_LEVEL_WEEK 1
69 #define SC_DAPI_LEVEL_WEEKDAY 2
72 // --------------------------------------------------------------------
74 // base class ScDPTableData to allow implementation with tabular data
75 // by deriving only of this
84 ScDPItemData() : fValue(0.0), bHasValue(FALSE
) {}
85 ScDPItemData( const String
& rS
, double fV
= 0.0, BOOL bHV
= FALSE
) :
86 aString(rS
), fValue(fV
), bHasValue( bHV
) {}
88 void SetString( const String
& rS
) { aString
= rS
; bHasValue
= FALSE
; }
89 BOOL
IsCaseInsEqual( const ScDPItemData
& r
) const;
94 BOOL
operator==( const ScDPItemData
& r
) const;
95 // case insensitive equality
96 static sal_Int32
Compare( const ScDPItemData
& rA
, const ScDPItemData
& rB
);
99 #define SC_VALTYPE_EMPTY 0
100 #define SC_VALTYPE_VALUE 1
101 #define SC_VALTYPE_STRING 2
102 #define SC_VALTYPE_ERROR 3
109 void Set( double fV
, BYTE nT
) { fValue
= fV
; nType
= nT
; }
112 class ScDPResultMember
;
116 class ScDPResultMember
;
121 // cached data for GetDatePart
126 ScSimpleSharedString
& mrSharedString
;
130 /** This structure stores dimension information used when calculating
131 results. These data are read only during result calculation, so it
132 should be passed as a const instance. */
135 ::std::vector
<long> aColLevelDims
;
136 ::std::vector
<ScDPDimension
*> aColDims
;
137 ::std::vector
<ScDPLevel
*> aColLevels
;
138 ::std::vector
<long> aRowLevelDims
;
139 ::std::vector
<ScDPDimension
*> aRowDims
;
140 ::std::vector
<ScDPLevel
*> aRowLevels
;
141 ::std::vector
<long> aPageDims
;
142 ::std::vector
<long> aDataSrcCols
;
144 ScDPInitState
* pInitState
;
145 ScDPResultMember
* pColRoot
;
146 ScDPResultMember
* pRowRoot
;
153 ScDPTableData(ScDocument
* pDoc
);
154 virtual ~ScDPTableData();
156 long GetDatePart( long nDateVal
, long nHierarchy
, long nLevel
);
158 //! use (new) typed collection instead of ScStrCollection
159 //! or separate Str and ValueCollection
161 virtual long GetColumnCount() = 0;
162 virtual const TypedScStrCollection
& GetColumnEntries(long nColumn
) = 0;
163 virtual String
getDimensionName(long nColumn
) = 0;
164 virtual BOOL
getIsDataLayoutDimension(long nColumn
) = 0;
165 virtual BOOL
IsDateDimension(long nDim
) = 0;
166 virtual UINT32
GetNumberFormat(long nDim
);
167 virtual void DisposeData() = 0;
168 virtual void SetEmptyFlags( BOOL bIgnoreEmptyRows
, BOOL bRepeatIfEmpty
) = 0;
170 virtual bool IsRepeatIfEmpty();
172 virtual void CreateCacheTable() = 0;
173 virtual void FilterCacheTable(const ::std::vector
<ScDPCacheTable::Criterion
>& rCriteria
, const ::std::hash_set
<sal_Int32
>& rDataDims
) = 0;
174 virtual void GetDrillDownData(const ::std::vector
<ScDPCacheTable::Criterion
>& rCriteria
,
175 const ::std::hash_set
<sal_Int32
>& rCatDims
,
176 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
> >& rData
) = 0;
177 virtual void CalcResults(CalcInfo
& rInfo
, bool bAutoShow
) = 0;
178 virtual const ScDPCacheTable
& GetCacheTable() const = 0;
180 // overloaded in ScDPGroupTableData:
181 virtual BOOL
IsBaseForGroup(long nDim
) const;
182 virtual long GetGroupBase(long nGroupDim
) const;
183 virtual BOOL
IsNumOrDateGroup(long nDim
) const;
184 virtual BOOL
IsInGroup( const ScDPItemData
& rGroupData
, long nGroupIndex
,
185 const ScDPItemData
& rBaseData
, long nBaseIndex
) const;
186 virtual BOOL
HasCommonElement( const ScDPItemData
& rFirstData
, long nFirstIndex
,
187 const ScDPItemData
& rSecondData
, long nSecondIndex
) const;
189 ScSimpleSharedString
& GetSharedString();
192 /** This structure stores vector arrays that hold intermediate data for
193 each row during cache table iteration. */
196 ::std::vector
<ScDPItemData
> aColData
;
197 ::std::vector
<ScDPItemData
> aRowData
;
198 ::std::vector
<ScDPItemData
> aPageData
;
199 ::std::vector
<ScDPValueData
> aValues
;
202 void FillRowDataFromCacheTable(sal_Int32 nRow
, const ScDPCacheTable
& rCacheTable
, const CalcInfo
& rInfo
, CalcRowData
& rData
);
203 void ProcessRowData(CalcInfo
& rInfo
, CalcRowData
& rData
, bool bAutoShow
);
204 void CalcResultsFromCacheTable(const ScDPCacheTable
& rCacheTable
, CalcInfo
& rInfo
, bool bAutoShow
);
207 void GetItemData(const ScDPCacheTable
& rCacheTable
, sal_Int32 nRow
,
208 const ::std::vector
<long>& rDims
, ::std::vector
<ScDPItemData
>& rItemData
);