LibreOffice Module sc (master)  1
dpcache.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #ifndef INCLUDED_SC_INC_DPCACHE_HXX
20 #define INCLUDED_SC_INC_DPCACHE_HXX
21 
22 #include "address.hxx"
23 #include "calcmacros.hxx"
24 #include "dpitemdata.hxx"
25 #include "dpnumgroupinfo.hxx"
26 #include "scdllapi.h"
27 #include "types.hxx"
28 
29 #include <mdds/flat_segment_tree.hpp>
30 
31 #include <memory>
32 #include <set>
33 #include <unordered_set>
34 #include <vector>
35 
36 struct ScQueryParam;
37 class ScDPObject;
38 class ScDocument;
39 class SvNumberFormatter;
40 
41 enum class SvNumFormatType : sal_Int16;
42 
48 {
49 public:
50  typedef std::unordered_set<OUString> StringSetType;
51  typedef mdds::flat_segment_tree<SCROW, bool> EmptyRowsType;
52  typedef std::vector<ScDPItemData> ScDPItemDataVec;
53  typedef std::set<ScDPObject*> ScDPObjectSet;
54  typedef std::vector<SCROW> IndexArrayType;
55 
56  struct SAL_DLLPRIVATE GroupItems
57  {
58  ScDPItemDataVec maItems;
60  sal_Int32 mnGroupType;
61 
62  GroupItems();
63  GroupItems(const GroupItems&) = delete;
64  const GroupItems& operator=(const GroupItems&) = delete;
65  GroupItems(const ScDPNumGroupInfo& rInfo, sal_Int32 nGroupType);
66  };
67 
68  struct SAL_DLLPRIVATE Field
69  {
73  std::unique_ptr<GroupItems> mpGroup;
74 
78  ScDPItemDataVec maItems;
79 
85  IndexArrayType maData;
86 
87  sal_uInt32 mnNumFormat;
88 
89  Field();
90  Field(const Field&) = delete;
91  const Field& operator=(const Field&) = delete;
92  };
93 
98  {
99  public:
100  virtual long getColumnCount() const = 0;
101  virtual OUString getColumnLabel(long nCol) const = 0;
102  virtual bool first() = 0;
103  virtual bool next() = 0;
104  virtual void finish() = 0;
105  virtual void getValue(long nCol, ScDPItemData& rData, SvNumFormatType& rNumType) const = 0;
106  virtual ~DBConnector() {}
107  };
108 
109 private:
110 
113 
117  mutable ScDPObjectSet maRefObjects;
118 
119  typedef std::vector< std::unique_ptr<Field> > FieldsType;
120  typedef std::vector< std::unique_ptr<GroupItems> > GroupFieldsType;
121 
122  FieldsType maFields;
123  GroupFieldsType maGroupFields;
124  std::vector<StringSetType> maStringPools; // one for each field.
125 
126  std::vector<OUString> maLabelNames; // Stores dimension names and the data layout dimension name at position 0.
127  EmptyRowsType maEmptyRows;
130 
132 
133 public:
134  rtl_uString* InternString( size_t nDim, const OUString& rStr );
135  void AddReference(ScDPObject* pObj) const;
136  void RemoveReference(ScDPObject* pObj) const;
137  const ScDPObjectSet& GetAllReferences() const;
138 
139  SCROW GetIdByItemData(long nDim, const ScDPItemData& rItem) const;
140 
141  static sal_uInt32 GetLocaleIndependentFormat( SvNumberFormatter& rFormatter, sal_uInt32 nNumFormat );
142  static OUString GetLocaleIndependentFormattedNumberString( double fValue );
143  static OUString GetLocaleIndependentFormattedString( double fValue, SvNumberFormatter& rFormatter, sal_uInt32 nNumFormat );
144  OUString GetFormattedString(long nDim, const ScDPItemData& rItem, bool bLocaleIndependent) const;
146 
147  long AppendGroupField();
148  void ResetGroupItems(long nDim, const ScDPNumGroupInfo& rNumInfo, sal_Int32 nGroupType);
149  SCROW SetGroupItem(long nDim, const ScDPItemData& rData);
150  void GetGroupDimMemberIds(long nDim, std::vector<SCROW>& rIds) const;
151  void ClearGroupFields();
152  void ClearAllFields();
153  const ScDPNumGroupInfo* GetNumGroupInfo(long nDim) const;
154 
163  sal_Int32 GetGroupType(long nDim) const;
164 
165  SCCOL GetDimensionIndex(const OUString& sName) const;
166  sal_uInt32 GetNumberFormat( long nDim ) const;
167  bool IsDateDimension( long nDim ) const ;
168  long GetDimMemberCount(long nDim) const;
169 
170  const IndexArrayType* GetFieldIndexArray( size_t nDim ) const;
171  const ScDPItemDataVec& GetDimMemberValues( SCCOL nDim ) const;
172  void InitFromDoc(ScDocument* pDoc, const ScRange& rRange);
173  bool InitFromDataBase(DBConnector& rDB);
174 
179  SCROW GetRowCount() const;
180 
186  SCROW GetDataSize() const;
187  SCROW GetItemDataId( sal_uInt16 nDim, SCROW nRow, bool bRepeatIfEmpty ) const;
188  OUString GetDimensionName(std::vector<OUString>::size_type nDim) const;
189  bool IsRowEmpty(SCROW nRow) const;
190  bool ValidQuery(SCROW nRow, const ScQueryParam& rQueryParam) const;
191 
192  ScDocument* GetDoc() const;
193  long GetColumnCount() const;
194 
195  const ScDPItemData* GetItemDataById( long nDim, SCROW nId ) const;
196 
197  size_t GetFieldCount() const;
198  size_t GetGroupFieldCount() const;
199 
200  ScDPCache(const ScDPCache&) = delete;
201  const ScDPCache& operator=(const ScDPCache&) = delete;
202  ScDPCache(ScDocument* pDoc);
203  ~ScDPCache();
204 
205 #if DUMP_PIVOT_TABLE
206  void Dump() const;
207 #endif
208 
209 private:
210  void PostInit();
211  void Clear();
212  const GroupItems* GetGroupItems(long nDim) const;
213 };
214 
215 #endif
216 
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScDPNumGroupInfo maInfo
Definition: dpcache.hxx:59
size_t GetGroupFieldCount() const
Definition: dpcache.cxx:1029
static sal_uInt32 GetLocaleIndependentFormat(SvNumberFormatter &rFormatter, sal_uInt32 nNumFormat)
Definition: dpcache.cxx:1169
ScDPItemDataVec maItems
Definition: dpcache.hxx:58
EmptyRowsType maEmptyRows
Definition: dpcache.hxx:127
long GetDimMemberCount(long nDim) const
Definition: dpcache.cxx:1082
sal_Int32 mnGroupType
Definition: dpcache.hxx:60
OUString GetDimensionName(std::vector< OUString >::size_type nDim) const
Definition: dpcache.cxx:919
static OUString GetLocaleIndependentFormattedString(double fValue, SvNumberFormatter &rFormatter, sal_uInt32 nNumFormat)
Definition: dpcache.cxx:1198
std::vector< StringSetType > maStringPools
Definition: dpcache.hxx:124
size_t GetFieldCount() const
Definition: dpcache.cxx:1024
sal_Int32 GetGroupType(long nDim) const
Return a group type identifier.
Definition: dpcache.cxx:1395
std::vector< std::unique_ptr< GroupItems > > GroupFieldsType
Definition: dpcache.hxx:120
ScDPCache(const ScDPCache &)=delete
ScDocument * GetDoc() const
Definition: dpcache.cxx:886
css::beans::Optional< css::uno::Any > getValue(OUString const &id)
rtl_uString * InternString(size_t nDim, const OUString &rStr)
Definition: dpcache.cxx:1098
const ContentProperties & rData
const ScDPCache & operator=(const ScDPCache &)=delete
const ScDPItemDataVec & GetDimMemberValues(SCCOL nDim) const
Definition: dpcache.cxx:1053
This class represents the cached data part of the datapilot cache table implementation.
Definition: dpcache.hxx:47
SCROW GetItemDataId(sal_uInt16 nDim, SCROW nRow, bool bRepeatIfEmpty) const
Definition: dpcache.cxx:961
SCCOL mnColumnCount
Definition: dpcache.hxx:112
std::unordered_set< OUString > StringSetType
Definition: dpcache.hxx:50
bool IsRowEmpty(SCROW nRow) const
Definition: dpcache.cxx:896
sal_uInt32 mnNumFormat
Definition: dpcache.hxx:87
SCROW GetRowCount() const
Row count is the number of records plus any trailing empty rows in case the source data is sheet and ...
Definition: dpcache.cxx:1034
void AddReference(ScDPObject *pObj) const
Definition: dpcache.cxx:1104
ScDocument * mpDoc
Definition: dpcache.hxx:111
void Clear()
Definition: dpcache.cxx:950
long GetColumnCount() const
Definition: dpcache.cxx:891
~ScDPCache()
Definition: dpcache.cxx:93
ScDPObjectSet maRefObjects
All pivot table objects that references this cache.
Definition: dpcache.hxx:117
std::unique_ptr< GroupItems > mpGroup
Optional items for grouped field.
Definition: dpcache.hxx:73
std::vector< OUString > maLabelNames
Definition: dpcache.hxx:126
Interface for connecting to database source.
Definition: dpcache.hxx:97
void ClearGroupFields()
Definition: dpcache.cxx:1363
SCROW mnDataSize
Definition: dpcache.hxx:128
bool IsDateDimension(long nDim) const
Definition: dpcache.cxx:1069
OUString GetFormattedString(long nDim, const ScDPItemData &rItem, bool bLocaleIndependent) const
Definition: dpcache.cxx:1211
When assigning a string value, you can also assign an interned string whose life-cycle is managed by ...
Definition: dpitemdata.hxx:29
void GetGroupDimMemberIds(long nDim, std::vector< SCROW > &rIds) const
Definition: dpcache.cxx:1323
void InitFromDoc(ScDocument *pDoc, const ScRange &rRange)
Definition: dpcache.cxx:510
sal_Int16 SCCOL
Definition: types.hxx:22
SCROW GetDataSize() const
Data size is the number of records without any trailing empty rows for sheet source data...
Definition: dpcache.cxx:1039
SvNumberFormatter * GetNumberFormatter() const
Definition: dpcache.cxx:1265
std::vector< ScDPItemData > ScDPItemDataVec
Definition: dpcache.hxx:52
SvNumFormatType
void ClearAllFields()
Definition: dpcache.cxx:1368
sal_uInt32 GetNumberFormat(long nDim) const
Definition: dpcache.cxx:1059
GroupFieldsType maGroupFields
Definition: dpcache.hxx:123
SCROW GetIdByItemData(long nDim, const ScDPItemData &rItem) const
Definition: dpcache.cxx:1125
IndexArrayType maData
Original source data represented as indices to the unique value list.
Definition: dpcache.hxx:85
const IndexArrayType * GetFieldIndexArray(size_t nDim) const
Definition: dpcache.cxx:1045
void PostInit()
Definition: dpcache.cxx:932
bool mbDisposing
Definition: dpcache.hxx:131
bool InitFromDataBase(DBConnector &rDB)
Definition: dpcache.cxx:627
sal_Int32 SCROW
Definition: types.hxx:18
ScDPItemDataVec maItems
Unique values in the field, stored in ascending order.
Definition: dpcache.hxx:78
static OUString GetLocaleIndependentFormattedNumberString(double fValue)
Definition: dpcache.cxx:1192
void RemoveReference(ScDPObject *pObj) const
Definition: dpcache.cxx:1109
const ScDPObjectSet & GetAllReferences() const
Definition: dpcache.cxx:1120
void ResetGroupItems(long nDim, const ScDPNumGroupInfo &rNumInfo, sal_Int32 nGroupType)
Definition: dpcache.cxx:1276
FieldsType maFields
Definition: dpcache.hxx:122
void Dump() const
std::vector< std::unique_ptr< Field > > FieldsType
Definition: dpcache.hxx:119
std::vector< SCROW > IndexArrayType
Definition: dpcache.hxx:54
virtual ~DBConnector()
Definition: dpcache.hxx:106
const ScDPNumGroupInfo * GetNumGroupInfo(long nDim) const
Definition: dpcache.cxx:1374
long AppendGroupField()
Definition: dpcache.cxx:1270
const ScDPItemData * GetItemDataById(long nDim, SCROW nId) const
Definition: dpcache.cxx:986
SCCOL GetDimensionIndex(const OUString &sName) const
Definition: dpcache.cxx:1088
std::set< ScDPObject * > ScDPObjectSet
Definition: dpcache.hxx:53
mdds::flat_segment_tree< SCROW, bool > EmptyRowsType
Definition: dpcache.hxx:51
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
SCROW SetGroupItem(long nDim, const ScDPItemData &rData)
Definition: dpcache.cxx:1298
const GroupItems * GetGroupItems(long nDim) const
Definition: dpcache.cxx:903
const char first[]
SCROW mnRowCount
Definition: dpcache.hxx:129
bool ValidQuery(SCROW nRow, const ScQueryParam &rQueryParam) const
Definition: dpcache.cxx:687