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 #include <tools/long.hxx>
31 #include <o3tl/sorted_vector.hxx>
32 
33 #include <memory>
34 #include <unordered_set>
35 #include <vector>
36 
37 struct ScQueryParam;
38 class ScDPObject;
39 class ScDocument;
40 class SvNumberFormatter;
41 
42 enum class SvNumFormatType : sal_Int16;
43 
49 {
50 public:
51  typedef std::unordered_set<OUString> StringSetType;
52  typedef mdds::flat_segment_tree<SCROW, bool> EmptyRowsType;
53  typedef std::vector<ScDPItemData> ScDPItemDataVec;
55  typedef std::vector<SCROW> IndexArrayType;
56 
57  struct SAL_DLLPRIVATE GroupItems
58  {
59  ScDPItemDataVec maItems;
61  sal_Int32 mnGroupType;
62 
63  GroupItems();
64  GroupItems(const GroupItems&) = delete;
65  const GroupItems& operator=(const GroupItems&) = delete;
66  GroupItems(const ScDPNumGroupInfo& rInfo, sal_Int32 nGroupType);
67  };
68 
69  struct SAL_DLLPRIVATE Field
70  {
74  std::unique_ptr<GroupItems> mpGroup;
75 
79  ScDPItemDataVec maItems;
80 
86  IndexArrayType maData;
87 
88  sal_uInt32 mnNumFormat;
89 
90  Field();
91  Field(const Field&) = delete;
92  const Field& operator=(const Field&) = delete;
93  };
94 
99  {
100  public:
101  virtual tools::Long getColumnCount() const = 0;
102  virtual OUString getColumnLabel(tools::Long nCol) const = 0;
103  virtual bool first() = 0;
104  virtual bool next() = 0;
105  virtual void finish() = 0;
106  virtual void getValue(tools::Long nCol, ScDPItemData& rData, SvNumFormatType& rNumType) const = 0;
107  virtual ~DBConnector() {}
108  };
109 
110 private:
111 
114 
118  mutable ScDPObjectSet maRefObjects;
119 
120  typedef std::vector< std::unique_ptr<Field> > FieldsType;
121  typedef std::vector< std::unique_ptr<GroupItems> > GroupFieldsType;
122 
123  FieldsType maFields;
124  GroupFieldsType maGroupFields;
125  std::vector<StringSetType> maStringPools; // one for each field.
126 
127  std::vector<OUString> maLabelNames; // Stores dimension names and the data layout dimension name at position 0.
128  EmptyRowsType maEmptyRows;
131 
133 
134 public:
135  rtl_uString* InternString( size_t nDim, const OUString& rStr );
136  void AddReference(ScDPObject* pObj) const;
137  void RemoveReference(ScDPObject* pObj) const;
138  const ScDPObjectSet& GetAllReferences() const;
139 
140  SCROW GetIdByItemData(tools::Long nDim, const ScDPItemData& rItem) const;
141 
142  static sal_uInt32 GetLocaleIndependentFormat( SvNumberFormatter& rFormatter, sal_uInt32 nNumFormat );
143  static OUString GetLocaleIndependentFormattedNumberString( double fValue );
144  static OUString GetLocaleIndependentFormattedString( double fValue, SvNumberFormatter& rFormatter, sal_uInt32 nNumFormat );
145  OUString GetFormattedString(tools::Long nDim, const ScDPItemData& rItem, bool bLocaleIndependent) const;
147 
149  void ResetGroupItems(tools::Long nDim, const ScDPNumGroupInfo& rNumInfo, sal_Int32 nGroupType);
150  SCROW SetGroupItem(tools::Long nDim, const ScDPItemData& rData);
151  void GetGroupDimMemberIds(tools::Long nDim, std::vector<SCROW>& rIds) const;
152  void ClearGroupFields();
153  void ClearAllFields();
154  const ScDPNumGroupInfo* GetNumGroupInfo(tools::Long nDim) const;
155 
164  sal_Int32 GetGroupType(tools::Long nDim) const;
165 
166  SCCOL GetDimensionIndex(const OUString& sName) const;
167  sal_uInt32 GetNumberFormat( tools::Long nDim ) const;
168  bool IsDateDimension( tools::Long nDim ) const ;
170 
171  const IndexArrayType* GetFieldIndexArray( size_t nDim ) const;
172  const ScDPItemDataVec& GetDimMemberValues( SCCOL nDim ) const;
173  void InitFromDoc(ScDocument& rDoc, const ScRange& rRange);
174  bool InitFromDataBase(DBConnector& rDB);
175 
180  SCROW GetRowCount() const;
181 
187  SCROW GetDataSize() const;
188  SCROW GetItemDataId( sal_uInt16 nDim, SCROW nRow, bool bRepeatIfEmpty ) const;
189  OUString GetDimensionName(std::vector<OUString>::size_type nDim) const;
190  bool IsRowEmpty(SCROW nRow) const;
191  bool ValidQuery(SCROW nRow, const ScQueryParam& rQueryParam) const;
192 
193  ScDocument& GetDoc() const;
194  tools::Long GetColumnCount() const;
195 
196  const ScDPItemData* GetItemDataById( tools::Long nDim, SCROW nId ) const;
197 
198  size_t GetFieldCount() const;
199  size_t GetGroupFieldCount() const;
200 
201  ScDPCache(const ScDPCache&) = delete;
202  const ScDPCache& operator=(const ScDPCache&) = delete;
203  ScDPCache(ScDocument& rDoc);
204  ~ScDPCache();
205 
206 #if DUMP_PIVOT_TABLE
207  void Dump() const;
208 #endif
209 
210 private:
211  void PostInit();
212  void Clear();
213  const GroupItems* GetGroupItems(tools::Long nDim) const;
214 };
215 
216 #endif
217 
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScDPNumGroupInfo maInfo
Definition: dpcache.hxx:60
size_t GetGroupFieldCount() const
Definition: dpcache.cxx:1028
static sal_uInt32 GetLocaleIndependentFormat(SvNumberFormatter &rFormatter, sal_uInt32 nNumFormat)
Definition: dpcache.cxx:1168
ScDPItemDataVec maItems
Definition: dpcache.hxx:59
OUString GetFormattedString(tools::Long nDim, const ScDPItemData &rItem, bool bLocaleIndependent) const
Definition: dpcache.cxx:1210
EmptyRowsType maEmptyRows
Definition: dpcache.hxx:128
tools::Long GetDimMemberCount(tools::Long nDim) const
Definition: dpcache.cxx:1081
sal_Int32 mnGroupType
Definition: dpcache.hxx:61
OUString GetDimensionName(std::vector< OUString >::size_type nDim) const
Definition: dpcache.cxx:918
static OUString GetLocaleIndependentFormattedString(double fValue, SvNumberFormatter &rFormatter, sal_uInt32 nNumFormat)
Definition: dpcache.cxx:1197
std::vector< StringSetType > maStringPools
Definition: dpcache.hxx:125
size_t GetFieldCount() const
Definition: dpcache.cxx:1023
std::vector< std::unique_ptr< GroupItems > > GroupFieldsType
Definition: dpcache.hxx:121
SCROW SetGroupItem(tools::Long nDim, const ScDPItemData &rData)
Definition: dpcache.cxx:1297
ScDocument & GetDoc() const
Definition: dpcache.cxx:885
SCROW GetIdByItemData(tools::Long nDim, const ScDPItemData &rItem) const
Definition: dpcache.cxx:1124
ScDPCache(const ScDPCache &)=delete
long Long
const GroupItems * GetGroupItems(tools::Long nDim) const
Definition: dpcache.cxx:902
css::beans::Optional< css::uno::Any > getValue(OUString const &id)
rtl_uString * InternString(size_t nDim, const OUString &rStr)
Definition: dpcache.cxx:1097
const ContentProperties & rData
const ScDPCache & operator=(const ScDPCache &)=delete
const ScDPItemDataVec & GetDimMemberValues(SCCOL nDim) const
Definition: dpcache.cxx:1052
This class represents the cached data part of the datapilot cache table implementation.
Definition: dpcache.hxx:48
void InitFromDoc(ScDocument &rDoc, const ScRange &rRange)
Definition: dpcache.cxx:510
SCROW GetItemDataId(sal_uInt16 nDim, SCROW nRow, bool bRepeatIfEmpty) const
Definition: dpcache.cxx:960
SCCOL mnColumnCount
Definition: dpcache.hxx:113
std::unordered_set< OUString > StringSetType
Definition: dpcache.hxx:51
bool IsRowEmpty(SCROW nRow) const
Definition: dpcache.cxx:895
sal_uInt32 mnNumFormat
Definition: dpcache.hxx:88
sal_Int32 GetGroupType(tools::Long nDim) const
Return a group type identifier.
Definition: dpcache.cxx:1394
tools::Long AppendGroupField()
Definition: dpcache.cxx:1269
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:1033
const ScDPItemData * GetItemDataById(tools::Long nDim, SCROW nId) const
Definition: dpcache.cxx:985
void AddReference(ScDPObject *pObj) const
Definition: dpcache.cxx:1103
const ScDPNumGroupInfo * GetNumGroupInfo(tools::Long nDim) const
Definition: dpcache.cxx:1373
void Clear()
Definition: dpcache.cxx:949
~ScDPCache()
Definition: dpcache.cxx:93
ScDPObjectSet maRefObjects
All pivot table objects that references this cache.
Definition: dpcache.hxx:118
std::unique_ptr< GroupItems > mpGroup
Optional items for grouped field.
Definition: dpcache.hxx:74
std::vector< OUString > maLabelNames
Definition: dpcache.hxx:127
Interface for connecting to database source.
Definition: dpcache.hxx:98
void ClearGroupFields()
Definition: dpcache.cxx:1362
SCROW mnDataSize
Definition: dpcache.hxx:129
When assigning a string value, you can also assign an interned string whose life-cycle is managed by ...
Definition: dpitemdata.hxx:29
ScDocument & mrDoc
Definition: dpcache.hxx:112
o3tl::sorted_vector< ScDPObject * > ScDPObjectSet
Definition: dpcache.hxx:54
sal_Int16 SCCOL
Definition: types.hxx:22
void ResetGroupItems(tools::Long nDim, const ScDPNumGroupInfo &rNumInfo, sal_Int32 nGroupType)
Definition: dpcache.cxx:1275
SCROW GetDataSize() const
Data size is the number of records without any trailing empty rows for sheet source data...
Definition: dpcache.cxx:1038
SvNumberFormatter * GetNumberFormatter() const
Definition: dpcache.cxx:1264
std::vector< ScDPItemData > ScDPItemDataVec
Definition: dpcache.hxx:53
tools::Long GetColumnCount() const
Definition: dpcache.cxx:890
SvNumFormatType
void ClearAllFields()
Definition: dpcache.cxx:1367
GroupFieldsType maGroupFields
Definition: dpcache.hxx:124
IndexArrayType maData
Original source data represented as indices to the unique value list.
Definition: dpcache.hxx:86
const IndexArrayType * GetFieldIndexArray(size_t nDim) const
Definition: dpcache.cxx:1044
void PostInit()
Definition: dpcache.cxx:931
bool mbDisposing
Definition: dpcache.hxx:132
bool InitFromDataBase(DBConnector &rDB)
Definition: dpcache.cxx:626
sal_Int32 SCROW
Definition: types.hxx:18
ScDPItemDataVec maItems
Unique values in the field, stored in ascending order.
Definition: dpcache.hxx:79
static OUString GetLocaleIndependentFormattedNumberString(double fValue)
Definition: dpcache.cxx:1191
void RemoveReference(ScDPObject *pObj) const
Definition: dpcache.cxx:1108
bool IsDateDimension(tools::Long nDim) const
Definition: dpcache.cxx:1068
const ScDPObjectSet & GetAllReferences() const
Definition: dpcache.cxx:1119
sal_uInt32 GetNumberFormat(tools::Long nDim) const
Definition: dpcache.cxx:1058
FieldsType maFields
Definition: dpcache.hxx:123
void Dump() const
std::vector< std::unique_ptr< Field > > FieldsType
Definition: dpcache.hxx:120
std::vector< SCROW > IndexArrayType
Definition: dpcache.hxx:55
virtual ~DBConnector()
Definition: dpcache.hxx:107
SCCOL GetDimensionIndex(const OUString &sName) const
Definition: dpcache.cxx:1087
void GetGroupDimMemberIds(tools::Long nDim, std::vector< SCROW > &rIds) const
Definition: dpcache.cxx:1322
mdds::flat_segment_tree< SCROW, bool > EmptyRowsType
Definition: dpcache.hxx:52
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
const char first[]
SCROW mnRowCount
Definition: dpcache.hxx:130
bool ValidQuery(SCROW nRow, const ScQueryParam &rQueryParam) const
Definition: dpcache.cxx:686