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_DPCACHETABLE_HXX 25 #define SC_DPCACHETABLE_HXX 26 27 #include "sal/types.h" 28 #include "osl/mutex.hxx" 29 #include "global.hxx" 30 #include "collect.hxx" 31 32 #include <vector> 33 #include <hash_map> 34 #include <hash_set> 35 #include <boost/shared_ptr.hpp> 36 #include <com/sun/star/uno/Reference.hxx> 37 38 namespace com { namespace sun { namespace star { 39 namespace sdbc { 40 class XRowSet; 41 } 42 namespace sheet { 43 struct DataPilotFieldFilter; 44 } 45 }}} 46 47 class Date; 48 49 class ScDocument; 50 class ScRange; 51 class ScDPDimension; 52 class ScDPCollection; 53 struct ScDPCacheCell; 54 struct ScQueryParam; 55 // Wang Xu Ming -- 2009-8-17 56 // DataPilot Migration - Cache&&Performance 57 class ScDPItemData; 58 // End Comments 59 class Date; 60 61 // Wang Xu Ming -- 2009-8-17 62 // DataPilot Migration - Cache&&Performance 63 class ScDPTableDataCache; 64 struct ScDPValueData; 65 // End Comments 66 // ---------------------------------------------------------------------------- 67 68 class SC_DLLPUBLIC ScDPCacheTable 69 { 70 public: 71 /** individual filter item used in SingleFilter and GroupFilter. */ 72 struct FilterItem 73 { 74 // Wang Xu Ming -- 2009-8-17 75 // DataPilot Migration - Cache&&Performance 76 String maString; 77 // End Comments 78 double mfValue; 79 bool mbHasValue; 80 81 FilterItem(); 82 // Wang Xu Ming -- 2009-8-17 83 // DataPilot Migration - Cache&&Performance 84 bool match( const ScDPItemData& rCellData ) const; 85 // End Comments 86 }; 87 88 /** interface class used for filtering of rows. */ 89 class FilterBase 90 { 91 public: 92 /** returns true if the matching condition is met for a single cell 93 value, or false otherwise. */ 94 // Wang Xu Ming -- 2009-8-17 95 // DataPilot Migration - Cache&&Performance 96 virtual bool match( const ScDPItemData& rCellData ) const = 0; 97 // End Comments 98 }; 99 100 /** ordinary single-item filter. */ 101 class SingleFilter : public FilterBase 102 { 103 public: 104 // Wang Xu Ming -- 2009-8-17 105 // DataPilot Migration - Cache&&Performance 106 explicit SingleFilter(String aString, double fValue, bool bHasValue); 107 // End Comments ~SingleFilter()108 virtual ~SingleFilter(){} 109 110 // Wang Xu Ming -- 2009-8-17 111 // DataPilot Migration - Cache&&Performance 112 virtual bool match(const ScDPItemData& rCellData) const; 113 // End Comments 114 const String getMatchString(); 115 double getMatchValue() const; 116 bool hasValue() const; 117 118 private: 119 explicit SingleFilter(); 120 121 FilterItem maItem; 122 }; 123 124 /** multi-item (group) filter. */ 125 class GroupFilter : public FilterBase 126 { 127 public: 128 // Wang Xu Ming -- 2009-8-17 129 // DataPilot Migration - Cache&&Performance 130 GroupFilter(); 131 // End Comments ~GroupFilter()132 virtual ~GroupFilter(){} 133 // Wang Xu Ming -- 2009-8-17 134 // DataPilot Migration - Cache&&Performance 135 virtual bool match( const ScDPItemData& rCellData ) const; 136 // End Comments 137 void addMatchItem(const String& rStr, double fVal, bool bHasValue); 138 size_t getMatchItemCount() const; 139 140 private: 141 142 ::std::vector<FilterItem> maItems; 143 }; 144 145 /** single filtering criterion. */ 146 struct Criterion 147 { 148 sal_Int32 mnFieldIndex; 149 ::boost::shared_ptr<FilterBase> mpFilter; 150 151 Criterion(); 152 }; 153 // Wang Xu Ming -- 2009-8-17 154 // DataPilot Migration - Cache&&Performance 155 ScDPCacheTable( ScDocument* pDoc,long nId ); 156 // End Comments 157 ~ScDPCacheTable(); 158 159 sal_Int32 getRowSize() const; 160 sal_Int32 getColSize() const; 161 162 // Wang Xu Ming -- 2009-8-17 163 // DataPilot Migration - Cache&&Performance 164 ScDPTableDataCache* GetCache() const; 165 /** Fill the internal table from the cell range provided. This function 166 assumes that the first row is the column header. */ 167 void fillTable( const ScQueryParam& rQuery, sal_Bool* pSpecial, 168 bool bIgnoreEmptyRows, bool bRepeatIfEmpty ); 169 /** Fill the internal table from database connection object. This function 170 assumes that the first row is the column header. */ 171 void fillTable(); 172 // End Comments 173 174 /** Check whether a specified row is active or not. When a row is active, 175 it is used in calculation of the results data. A row becomes inactive 176 when it is filtered out by page field. */ 177 bool isRowActive(sal_Int32 nRow) const; 178 179 /** Set filter on/off flag to each row to control visibility. The caller 180 must ensure that the table is filled before calling this function. */ 181 void filterByPageDimension(const ::std::vector<Criterion>& rCriteria, const ::std::hash_set<sal_Int32>& rRepeatIfEmptyDims); 182 183 /** Get the cell instance at specified location within the data grid. Note 184 that the data grid doesn't include the header row. Don't delete the 185 returned object! */ 186 const ScDPItemData* getCell(SCCOL nCol, SCROW nRow, bool bRepeatIfEmpty) const; 187 void getValue( ScDPValueData& rVal, SCCOL nCol, SCROW nRow, bool bRepeatIfEmpty) const; 188 String getFieldName( SCCOL nIndex) const; 189 //End Comments 190 191 /** Get the field index (i.e. column ID in the original data source) based 192 on the string value that corresponds with the column title. It returns 193 -1 if no field matching the string value exists. */ 194 sal_Int32 getFieldIndex(const String& rStr) const; 195 196 // Wang Xu Ming -- 2009-8-17 197 // DataPilot Migration - Cache&&Performance 198 /** Get the unique entries for a field specified by index. The caller must 199 make sure that the table is filled before calling function, or it will 200 get an empty collection. */ 201 const ::std::vector<SCROW>& getFieldEntries( sal_Int32 nColumn ) const; 202 // End Comments 203 /** Filter the table based on the specified criteria, and copy the 204 result to rTabData. This method is used, for example, to generate 205 a drill-down data table. */ 206 void filterTable(const ::std::vector<Criterion>& rCriteria, 207 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& rTabData, 208 const ::std::hash_set<sal_Int32>& rRepeatIfEmptyDims); 209 210 void clear(); 211 void swap(ScDPCacheTable& rOther); 212 bool empty() const; 213 214 private: 215 ScDPCacheTable(); 216 ScDPCacheTable(const ScDPCacheTable&); 217 218 /** 219 * Check if a given row meets all specified criteria. 220 * 221 * @param nRow index of row to be tested. 222 * @param rCriteria a list of criteria 223 */ 224 bool isRowQualified(sal_Int32 nRow, const ::std::vector<Criterion>& rCriteria, const ::std::hash_set<sal_Int32>& rRepeatIfEmptyDims) const; 225 void getValueData(ScDocument* pDoc, const ScAddress& rPos, ScDPCacheCell& rCell); 226 // Wang Xu Ming -- 2009-8-17 227 // DataPilot Migration - Cache&&Performance 228 void InitNoneCache( ScDocument* pDoc ); 229 // End Comments 230 private: 231 // Wang Xu Ming -- 2009-8-17 232 // DataPilot Migration - Cache&&Performance 233 /** unique field entires for each field (column). */ 234 ::std::vector< ::std::vector<SCROW> > maFieldEntries; 235 // End Comments 236 /** used to track visibility of rows. The first row below the header row 237 has the index of 0. */ 238 ::std::vector<bool> maRowsVisible; 239 // Wang Xu Ming -- 2009-8-17 240 // DataPilot Migration - Cache&&Performance 241 ScDPTableDataCache* mpCache; 242 ScDPTableDataCache* mpNoneCache; 243 // End Comments 244 }; 245 #endif 246