update dev300-m58
[ooovba.git] / sc / inc / dpcachetable.hxx
blob0a22fb06e592d15cf40456e60c692b011049027f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dpcachetable.hxx,v $
11 * $Revision: 1.4 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #ifndef SC_DPCACHETABLE_HXX
33 #define SC_DPCACHETABLE_HXX
35 #include "sal/types.h"
36 #include "osl/mutex.hxx"
37 #include "global.hxx"
38 #include "collect.hxx"
40 #include <vector>
41 #include <hash_map>
42 #include <hash_set>
43 #include <boost/shared_ptr.hpp>
44 #include <com/sun/star/uno/Reference.hxx>
46 namespace com { namespace sun { namespace star {
47 namespace sdbc {
48 class XRowSet;
50 namespace sheet {
51 struct DataPilotFieldFilter;
53 }}}
55 class Date;
57 class ScDocument;
58 class ScRange;
59 class ScDPDimension;
60 class ScDPCollection;
61 struct ScDPCacheCell;
62 struct ScDPItemData;
63 struct ScQueryParam;
64 class Date;
66 // ----------------------------------------------------------------------------
68 class ScDPCacheTable
70 public:
72 struct Cell
74 SCROW mnCategoryRef;
75 ScDPCacheCell* mpContent;
77 Cell();
78 ~Cell();
81 /** individual filter item used in SingleFilter and GroupFilter. */
82 struct FilterItem
84 sal_Int32 mnMatchStrId;
85 double mfValue;
86 bool mbHasValue;
88 FilterItem();
91 /** interface class used for filtering of rows. */
92 class FilterBase
94 public:
95 /** returns true if the matching condition is met for a single cell
96 value, or false otherwise. */
97 virtual bool match(const ScDPCacheCell& rCell) const = 0;
100 /** ordinary single-item filter. */
101 class SingleFilter : public FilterBase
103 public:
104 explicit SingleFilter(ScSimpleSharedString& rSharedString,
105 sal_Int32 nMatchStrId, double fValue, bool bHasValue);
106 virtual ~SingleFilter(){}
108 virtual bool match(const ScDPCacheCell& rCell) const;
110 const String getMatchString();
111 double getMatchValue() const;
112 bool hasValue() const;
114 private:
115 explicit SingleFilter();
117 FilterItem maItem;
118 ScSimpleSharedString mrSharedString;
121 /** multi-item (group) filter. */
122 class GroupFilter : public FilterBase
124 public:
125 GroupFilter(ScSimpleSharedString& rSharedString);
126 virtual ~GroupFilter(){}
127 virtual bool match(const ScDPCacheCell& rCell) const;
129 void addMatchItem(const String& rStr, double fVal, bool bHasValue);
130 size_t getMatchItemCount() const;
132 private:
133 GroupFilter();
135 ::std::vector<FilterItem> maItems;
136 ScSimpleSharedString mrSharedString;
139 /** single filtering criterion. */
140 struct Criterion
142 sal_Int32 mnFieldIndex;
143 ::boost::shared_ptr<FilterBase> mpFilter;
145 Criterion();
148 ScDPCacheTable(ScDPCollection* pCollection);
149 ~ScDPCacheTable();
151 sal_Int32 getRowSize() const;
152 sal_Int32 getColSize() const;
154 /** Fill the internal table from the cell range provided. This function
155 assumes that the first row is the column header. */
156 void fillTable(ScDocument* pDoc, const ScRange& rRange, const ScQueryParam& rQuery, BOOL* pSpecial,
157 bool bIgnoreEmptyRows);
159 /** Fill the internal table from database connection object. This function
160 assumes that the first row is the column header. */
161 void fillTable(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >& xRowSet,
162 const Date& rNullDate);
164 /** Check whether a specified row is active or not. When a row is active,
165 it is used in calculation of the results data. A row becomes inactive
166 when it is filtered out by page field. */
167 bool isRowActive(sal_Int32 nRow) const;
169 /** Set filter on/off flag to each row to control visibility. The caller
170 must ensure that the table is filled before calling this function. */
171 void filterByPageDimension(const ::std::vector<Criterion>& rCriteria, const ::std::hash_set<sal_Int32>& rRepeatIfEmptyDims);
173 /** Get the cell instance at specified location within the data grid. Note
174 that the data grid doesn't include the header row. Don't delete the
175 returned object! */
176 const ScDPCacheCell* getCell(SCCOL nCol, SCROW nRow, bool bRepeatIfEmpty) const;
178 const String* getFieldName(sal_Int32 nIndex) const;
180 /** Get the unique entries for a field specified by index. The caller must
181 make sure that the table is filled before calling function, or it will
182 get an empty collection. */
183 const TypedScStrCollection& getFieldEntries(sal_Int32 nIndex) const;
185 /** Filter the table based on the specified criteria, and copy the
186 result to rTabData. This method is used, for example, to generate
187 a drill-down data table. */
188 void filterTable(const ::std::vector<Criterion>& rCriteria,
189 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& rTabData,
190 const ::std::hash_set<sal_Int32>& rRepeatIfEmptyDims);
192 void clear();
193 bool empty() const;
195 private:
196 ScDPCacheTable();
197 ScDPCacheTable(const ScDPCacheTable&);
199 /**
200 * Check if a given row meets all specified criteria.
202 * @param nRow index of row to be tested.
203 * @param rCriteria a list of criteria
205 bool isRowQualified(sal_Int32 nRow, const ::std::vector<Criterion>& rCriteria, const ::std::hash_set<sal_Int32>& rRepeatIfEmptyDims) const;
206 void getValueData(ScDocument* pDoc, const ScAddress& rPos, ScDPCacheCell& rCell);
208 private:
209 typedef ::boost::shared_ptr<TypedScStrCollection> TypedScStrCollectionPtr;
211 /** main data table. */
212 ::std::vector< ::std::vector< ::ScDPCacheTable::Cell > > maTable;
214 /** header string IDs */
215 ::std::vector<sal_Int32> maHeader;
217 /** unique field entires for each field (column). */
218 ::std::vector<TypedScStrCollectionPtr> maFieldEntries;
220 /** used to track visibility of rows. The first row below the header row
221 has the index of 0. */
222 ::std::vector<bool> maRowsVisible;
224 ScSimpleSharedString& mrSharedString;
225 ScDPCollection* mpCollection;
229 #endif