1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #ifndef SC_DPCACHETABLE_HXX
29 #define SC_DPCACHETABLE_HXX
31 #include "sal/types.h"
32 #include "osl/mutex.hxx"
34 #include "collect.hxx"
39 #include <boost/shared_ptr.hpp>
40 #include <com/sun/star/uno/Reference.hxx>
42 namespace com
{ namespace sun
{ namespace star
{
47 struct DataPilotFieldFilter
;
59 // Wang Xu Ming -- 2009-8-17
60 // DataPilot Migration - Cache&&Performance
65 // Wang Xu Ming -- 2009-8-17
66 // DataPilot Migration - Cache&&Performance
67 class ScDPTableDataCache
;
70 // ----------------------------------------------------------------------------
72 class SC_DLLPUBLIC ScDPCacheTable
75 /** individual filter item used in SingleFilter and GroupFilter. */
78 // Wang Xu Ming -- 2009-8-17
79 // DataPilot Migration - Cache&&Performance
86 // Wang Xu Ming -- 2009-8-17
87 // DataPilot Migration - Cache&&Performance
88 bool match( const ScDPItemData
& rCellData
) const;
92 /** interface class used for filtering of rows. */
96 /** returns true if the matching condition is met for a single cell
97 value, or false otherwise. */
98 // Wang Xu Ming -- 2009-8-17
99 // DataPilot Migration - Cache&&Performance
100 virtual bool match( const ScDPItemData
& rCellData
) const = 0;
104 /** ordinary single-item filter. */
105 class SingleFilter
: public FilterBase
108 // Wang Xu Ming -- 2009-8-17
109 // DataPilot Migration - Cache&&Performance
110 explicit SingleFilter(String aString
, double fValue
, bool bHasValue
);
112 virtual ~SingleFilter(){}
114 // Wang Xu Ming -- 2009-8-17
115 // DataPilot Migration - Cache&&Performance
116 virtual bool match(const ScDPItemData
& rCellData
) const;
118 const String
getMatchString();
119 double getMatchValue() const;
120 bool hasValue() const;
123 explicit SingleFilter();
128 /** multi-item (group) filter. */
129 class GroupFilter
: public FilterBase
132 // Wang Xu Ming -- 2009-8-17
133 // DataPilot Migration - Cache&&Performance
136 virtual ~GroupFilter(){}
137 // Wang Xu Ming -- 2009-8-17
138 // DataPilot Migration - Cache&&Performance
139 virtual bool match( const ScDPItemData
& rCellData
) const;
141 void addMatchItem(const String
& rStr
, double fVal
, bool bHasValue
);
142 size_t getMatchItemCount() const;
146 ::std::vector
<FilterItem
> maItems
;
149 /** single filtering criterion. */
152 sal_Int32 mnFieldIndex
;
153 ::boost::shared_ptr
<FilterBase
> mpFilter
;
157 // Wang Xu Ming -- 2009-8-17
158 // DataPilot Migration - Cache&&Performance
159 ScDPCacheTable( ScDocument
* pDoc
,long nId
);
163 sal_Int32
getRowSize() const;
164 sal_Int32
getColSize() const;
166 // Wang Xu Ming -- 2009-8-17
167 // DataPilot Migration - Cache&&Performance
168 ScDPTableDataCache
* GetCache() const;
169 /** Fill the internal table from the cell range provided. This function
170 assumes that the first row is the column header. */
171 void fillTable( const ScQueryParam
& rQuery
, BOOL
* pSpecial
,
172 bool bIgnoreEmptyRows
, bool bRepeatIfEmpty
);
173 /** Fill the internal table from database connection object. This function
174 assumes that the first row is the column header. */
178 /** Check whether a specified row is active or not. When a row is active,
179 it is used in calculation of the results data. A row becomes inactive
180 when it is filtered out by page field. */
181 bool isRowActive(sal_Int32 nRow
) const;
183 /** Set filter on/off flag to each row to control visibility. The caller
184 must ensure that the table is filled before calling this function. */
185 void filterByPageDimension(const ::std::vector
<Criterion
>& rCriteria
, const ::std::hash_set
<sal_Int32
>& rRepeatIfEmptyDims
);
187 /** Get the cell instance at specified location within the data grid. Note
188 that the data grid doesn't include the header row. Don't delete the
190 const ScDPItemData
* getCell(SCCOL nCol
, SCROW nRow
, bool bRepeatIfEmpty
) const;
191 void getValue( ScDPValueData
& rVal
, SCCOL nCol
, SCROW nRow
, bool bRepeatIfEmpty
) const;
192 String
getFieldName( SCCOL nIndex
) const;
195 /** Get the field index (i.e. column ID in the original data source) based
196 on the string value that corresponds with the column title. It returns
197 -1 if no field matching the string value exists. */
198 sal_Int32
getFieldIndex(const String
& rStr
) const;
200 // Wang Xu Ming -- 2009-8-17
201 // DataPilot Migration - Cache&&Performance
202 /** Get the unique entries for a field specified by index. The caller must
203 make sure that the table is filled before calling function, or it will
204 get an empty collection. */
205 const ::std::vector
<SCROW
>& getFieldEntries( sal_Int32 nColumn
) const;
207 /** Filter the table based on the specified criteria, and copy the
208 result to rTabData. This method is used, for example, to generate
209 a drill-down data table. */
210 void filterTable(const ::std::vector
<Criterion
>& rCriteria
,
211 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
> >& rTabData
,
212 const ::std::hash_set
<sal_Int32
>& rRepeatIfEmptyDims
);
215 void swap(ScDPCacheTable
& rOther
);
220 ScDPCacheTable(const ScDPCacheTable
&);
223 * Check if a given row meets all specified criteria.
225 * @param nRow index of row to be tested.
226 * @param rCriteria a list of criteria
228 bool isRowQualified(sal_Int32 nRow
, const ::std::vector
<Criterion
>& rCriteria
, const ::std::hash_set
<sal_Int32
>& rRepeatIfEmptyDims
) const;
229 void getValueData(ScDocument
* pDoc
, const ScAddress
& rPos
, ScDPCacheCell
& rCell
);
230 // Wang Xu Ming -- 2009-8-17
231 // DataPilot Migration - Cache&&Performance
232 void InitNoneCache( ScDocument
* pDoc
);
235 // Wang Xu Ming -- 2009-8-17
236 // DataPilot Migration - Cache&&Performance
237 /** unique field entires for each field (column). */
238 ::std::vector
< ::std::vector
<SCROW
> > maFieldEntries
;
240 /** used to track visibility of rows. The first row below the header row
241 has the index of 0. */
242 ::std::vector
<bool> maRowsVisible
;
243 // Wang Xu Ming -- 2009-8-17
244 // DataPilot Migration - Cache&&Performance
245 ScDPTableDataCache
* mpCache
;
246 ScDPTableDataCache
* mpNoneCache
;