merged tag ooo/OOO330_m14
[LibreOffice.git] / sc / inc / dpcachetable.hxx
blobeab01d078081295fda8259b5976f8140fb741422
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"
33 #include "global.hxx"
34 #include "collect.hxx"
36 #include <vector>
37 #include <hash_map>
38 #include <hash_set>
39 #include <boost/shared_ptr.hpp>
40 #include <com/sun/star/uno/Reference.hxx>
42 namespace com { namespace sun { namespace star {
43 namespace sdbc {
44 class XRowSet;
46 namespace sheet {
47 struct DataPilotFieldFilter;
49 }}}
51 class Date;
53 class ScDocument;
54 class ScRange;
55 class ScDPDimension;
56 class ScDPCollection;
57 struct ScDPCacheCell;
58 struct ScQueryParam;
59 // Wang Xu Ming -- 2009-8-17
60 // DataPilot Migration - Cache&&Performance
61 class ScDPItemData;
62 // End Comments
63 class Date;
65 // Wang Xu Ming -- 2009-8-17
66 // DataPilot Migration - Cache&&Performance
67 class ScDPTableDataCache;
68 struct ScDPValueData;
69 // End Comments
70 // ----------------------------------------------------------------------------
72 class SC_DLLPUBLIC ScDPCacheTable
74 public:
75 /** individual filter item used in SingleFilter and GroupFilter. */
76 struct FilterItem
78 // Wang Xu Ming -- 2009-8-17
79 // DataPilot Migration - Cache&&Performance
80 String maString;
81 // End Comments
82 double mfValue;
83 bool mbHasValue;
85 FilterItem();
86 // Wang Xu Ming -- 2009-8-17
87 // DataPilot Migration - Cache&&Performance
88 bool match( const ScDPItemData& rCellData ) const;
89 // End Comments
92 /** interface class used for filtering of rows. */
93 class FilterBase
95 public:
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;
101 // End Comments
104 /** ordinary single-item filter. */
105 class SingleFilter : public FilterBase
107 public:
108 // Wang Xu Ming -- 2009-8-17
109 // DataPilot Migration - Cache&&Performance
110 explicit SingleFilter(String aString, double fValue, bool bHasValue);
111 // End Comments
112 virtual ~SingleFilter(){}
114 // Wang Xu Ming -- 2009-8-17
115 // DataPilot Migration - Cache&&Performance
116 virtual bool match(const ScDPItemData& rCellData) const;
117 // End Comments
118 const String getMatchString();
119 double getMatchValue() const;
120 bool hasValue() const;
122 private:
123 explicit SingleFilter();
125 FilterItem maItem;
128 /** multi-item (group) filter. */
129 class GroupFilter : public FilterBase
131 public:
132 // Wang Xu Ming -- 2009-8-17
133 // DataPilot Migration - Cache&&Performance
134 GroupFilter();
135 // End Comments
136 virtual ~GroupFilter(){}
137 // Wang Xu Ming -- 2009-8-17
138 // DataPilot Migration - Cache&&Performance
139 virtual bool match( const ScDPItemData& rCellData ) const;
140 // End Comments
141 void addMatchItem(const String& rStr, double fVal, bool bHasValue);
142 size_t getMatchItemCount() const;
144 private:
146 ::std::vector<FilterItem> maItems;
149 /** single filtering criterion. */
150 struct Criterion
152 sal_Int32 mnFieldIndex;
153 ::boost::shared_ptr<FilterBase> mpFilter;
155 Criterion();
157 // Wang Xu Ming -- 2009-8-17
158 // DataPilot Migration - Cache&&Performance
159 ScDPCacheTable( ScDocument* pDoc,long nId );
160 // End Comments
161 ~ScDPCacheTable();
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. */
175 void fillTable();
176 // End Comments
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
189 returned object! */
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;
193 //End Comments
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;
206 // End Comments
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);
214 void clear();
215 void swap(ScDPCacheTable& rOther);
216 bool empty() const;
218 private:
219 ScDPCacheTable();
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 );
233 // End Comments
234 private:
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;
239 // End Comments
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;
247 // End Comments
249 #endif