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