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 #pragma once
20 
21 #include "address.hxx"
22 #include "calcmacros.hxx"
23 #include "dpitemdata.hxx"
24 #include "dpnumgroupinfo.hxx"
25 #include "scdllapi.h"
26 #include "types.hxx"
27 
28 #include <mdds/flat_segment_tree.hpp>
29 #include <tools/long.hxx>
30 #include <o3tl/sorted_vector.hxx>
31 
32 #include <memory>
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;
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 tools::Long getColumnCount() const = 0;
101  virtual OUString getColumnLabel(tools::Long nCol) const = 0;
102  virtual bool first() = 0;
103  virtual bool next() = 0;
104  virtual void finish() = 0;
105  virtual void getValue(tools::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(tools::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(tools::Long nDim, const ScDPItemData& rItem, bool bLocaleIndependent) const;
146 
148  void ResetGroupItems(tools::Long nDim, const ScDPNumGroupInfo& rNumInfo, sal_Int32 nGroupType);
149  SCROW SetGroupItem(tools::Long nDim, const ScDPItemData& rData);
150  void GetGroupDimMemberIds(tools::Long nDim, std::vector<SCROW>& rIds) const;
151  void ClearGroupFields();
152  void ClearAllFields();
153  const ScDPNumGroupInfo* GetNumGroupInfo(tools::Long nDim) const;
154 
163  sal_Int32 GetGroupType(tools::Long nDim) const;
164 
165  SCCOL GetDimensionIndex(std::u16string_view sName) const;
166  sal_uInt32 GetNumberFormat( tools::Long nDim ) const;
167  bool IsDateDimension( tools::Long nDim ) const ;
169 
170  const IndexArrayType* GetFieldIndexArray( size_t nDim ) const;
171  const ScDPItemDataVec& GetDimMemberValues( SCCOL nDim ) const;
172  void InitFromDoc(ScDocument& rDoc, 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  tools::Long GetColumnCount() const;
194 
195  const ScDPItemData* GetItemDataById( tools::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& rDoc);
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(tools::Long nDim) const;
213 };
214 
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScDPNumGroupInfo maInfo
Definition: dpcache.hxx:59
size_t GetGroupFieldCount() const
Definition: dpcache.cxx:1023
static sal_uInt32 GetLocaleIndependentFormat(SvNumberFormatter &rFormatter, sal_uInt32 nNumFormat)
Definition: dpcache.cxx:1163
ScDPItemDataVec maItems
Definition: dpcache.hxx:58
OUString GetFormattedString(tools::Long nDim, const ScDPItemData &rItem, bool bLocaleIndependent) const
Definition: dpcache.cxx:1202
EmptyRowsType maEmptyRows
Definition: dpcache.hxx:127
tools::Long GetDimMemberCount(tools::Long nDim) const
Definition: dpcache.cxx:1076
sal_Int32 mnGroupType
Definition: dpcache.hxx:60
OUString GetDimensionName(std::vector< OUString >::size_type nDim) const
Definition: dpcache.cxx:913
static OUString GetLocaleIndependentFormattedString(double fValue, SvNumberFormatter &rFormatter, sal_uInt32 nNumFormat)
Definition: dpcache.cxx:1189
std::vector< StringSetType > maStringPools
Definition: dpcache.hxx:124
size_t GetFieldCount() const
Definition: dpcache.cxx:1018
std::vector< std::unique_ptr< GroupItems > > GroupFieldsType
Definition: dpcache.hxx:120
SCROW SetGroupItem(tools::Long nDim, const ScDPItemData &rData)
Definition: dpcache.cxx:1289
ScDocument & GetDoc() const
Definition: dpcache.cxx:880
SCROW GetIdByItemData(tools::Long nDim, const ScDPItemData &rItem) const
Definition: dpcache.cxx:1119
ScDPCache(const ScDPCache &)=delete
long Long
const GroupItems * GetGroupItems(tools::Long nDim) const
Definition: dpcache.cxx:897
rtl_uString * InternString(size_t nDim, const OUString &rStr)
Definition: dpcache.cxx:1092
const ContentProperties & rData
const ScDPCache & operator=(const ScDPCache &)=delete
const ScDPItemDataVec & GetDimMemberValues(SCCOL nDim) const
Definition: dpcache.cxx:1047
This class represents the cached data part of the datapilot cache table implementation.
Definition: dpcache.hxx:47
void InitFromDoc(ScDocument &rDoc, const ScRange &rRange)
Definition: dpcache.cxx:507
SCROW GetItemDataId(sal_uInt16 nDim, SCROW nRow, bool bRepeatIfEmpty) const
Definition: dpcache.cxx:955
SCCOL GetDimensionIndex(std::u16string_view sName) const
Definition: dpcache.cxx:1082
SCCOL mnColumnCount
Definition: dpcache.hxx:112
std::unordered_set< OUString > StringSetType
Definition: dpcache.hxx:50
bool IsRowEmpty(SCROW nRow) const
Definition: dpcache.cxx:890
sal_uInt32 mnNumFormat
Definition: dpcache.hxx:87
sal_Int32 GetGroupType(tools::Long nDim) const
Return a group type identifier.
Definition: dpcache.cxx:1386
tools::Long AppendGroupField()
Definition: dpcache.cxx:1261
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:1028
const ScDPItemData * GetItemDataById(tools::Long nDim, SCROW nId) const
Definition: dpcache.cxx:980
void AddReference(ScDPObject *pObj) const
Definition: dpcache.cxx:1098
const ScDPNumGroupInfo * GetNumGroupInfo(tools::Long nDim) const
Definition: dpcache.cxx:1365
void Clear()
Definition: dpcache.cxx:944
~ScDPCache()
Definition: dpcache.cxx:94
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:1354
SCROW mnDataSize
Definition: dpcache.hxx:128
When assigning a string value, you can also assign an interned string whose life-cycle is managed by ...
Definition: dpitemdata.hxx:28
ScDocument & mrDoc
Definition: dpcache.hxx:111
o3tl::sorted_vector< ScDPObject * > ScDPObjectSet
Definition: dpcache.hxx:53
sal_Int16 SCCOL
Definition: types.hxx:21
void ResetGroupItems(tools::Long nDim, const ScDPNumGroupInfo &rNumInfo, sal_Int32 nGroupType)
Definition: dpcache.cxx:1267
SCROW GetDataSize() const
Data size is the number of records without any trailing empty rows for sheet source data...
Definition: dpcache.cxx:1033
SvNumberFormatter * GetNumberFormatter() const
Definition: dpcache.cxx:1256
std::vector< ScDPItemData > ScDPItemDataVec
Definition: dpcache.hxx:52
tools::Long GetColumnCount() const
Definition: dpcache.cxx:885
SvNumFormatType
void ClearAllFields()
Definition: dpcache.cxx:1359
css::beans::Optional< css::uno::Any > getValue(std::u16string_view id)
GroupFieldsType maGroupFields
Definition: dpcache.hxx:123
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:1039
void PostInit()
Definition: dpcache.cxx:926
bool mbDisposing
Definition: dpcache.hxx:131
bool InitFromDataBase(DBConnector &rDB)
Definition: dpcache.cxx:623
sal_Int32 SCROW
Definition: types.hxx:17
ScDPItemDataVec maItems
Unique values in the field, stored in ascending order.
Definition: dpcache.hxx:78
static OUString GetLocaleIndependentFormattedNumberString(double fValue)
Definition: dpcache.cxx:1183
void RemoveReference(ScDPObject *pObj) const
Definition: dpcache.cxx:1103
bool IsDateDimension(tools::Long nDim) const
Definition: dpcache.cxx:1063
const ScDPObjectSet & GetAllReferences() const
Definition: dpcache.cxx:1114
sal_uInt32 GetNumberFormat(tools::Long nDim) const
Definition: dpcache.cxx:1053
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
void GetGroupDimMemberIds(tools::Long nDim, std::vector< SCROW > &rIds) const
Definition: dpcache.cxx:1314
constexpr OUStringLiteral first
mdds::flat_segment_tree< SCROW, bool > EmptyRowsType
Definition: dpcache.hxx:51
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
SCROW mnRowCount
Definition: dpcache.hxx:129
bool ValidQuery(SCROW nRow, const ScQueryParam &rQueryParam) const
Definition: dpcache.cxx:683