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>
31
32#include <memory>
33#include <unordered_set>
34#include <vector>
35
36struct ScQueryParam;
37class ScDPObject;
38class ScDocument;
40
41enum class SvNumFormatType : sal_Int16;
42
48{
49public:
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 {
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
79
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
109private:
110
113
118
119 typedef std::vector< std::unique_ptr<Field> > FieldsType;
120 typedef std::vector< std::unique_ptr<GroupItems> > GroupFieldsType;
121
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.
130
132
133public:
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;
145 SvNumberFormatter* GetNumberFormatter() const;
146
147 tools::Long AppendGroupField();
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 ;
168 tools::Long GetDimMemberCount(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
209private:
210 void PostInit();
211 void Clear();
212 const GroupItems* GetGroupItems(tools::Long nDim) const;
213};
214
215/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Interface for connecting to database source.
Definition: dpcache.hxx:98
virtual OUString getColumnLabel(tools::Long nCol) const =0
virtual void finish()=0
virtual bool next()=0
virtual ~DBConnector()
Definition: dpcache.hxx:106
virtual bool first()=0
virtual tools::Long getColumnCount() const =0
virtual void getValue(tools::Long nCol, ScDPItemData &rData, SvNumFormatType &rNumType) const =0
This class represents the cached data part of the datapilot cache table implementation.
Definition: dpcache.hxx:48
const ScDPCache & operator=(const ScDPCache &)=delete
GroupFieldsType maGroupFields
Definition: dpcache.hxx:123
o3tl::sorted_vector< ScDPObject * > ScDPObjectSet
Definition: dpcache.hxx:53
ScDocument & mrDoc
Definition: dpcache.hxx:111
std::vector< OUString > maLabelNames
Definition: dpcache.hxx:126
SCROW mnRowCount
Definition: dpcache.hxx:129
ScDPCache(const ScDPCache &)=delete
std::unordered_set< OUString > StringSetType
Definition: dpcache.hxx:50
std::vector< SCROW > IndexArrayType
Definition: dpcache.hxx:54
FieldsType maFields
Definition: dpcache.hxx:122
std::vector< StringSetType > maStringPools
Definition: dpcache.hxx:124
std::vector< std::unique_ptr< Field > > FieldsType
Definition: dpcache.hxx:119
SCROW mnDataSize
Definition: dpcache.hxx:128
mdds::flat_segment_tree< SCROW, bool > EmptyRowsType
Definition: dpcache.hxx:51
EmptyRowsType maEmptyRows
Definition: dpcache.hxx:127
ScDPObjectSet maRefObjects
All pivot table objects that references this cache.
Definition: dpcache.hxx:117
SCCOL mnColumnCount
Definition: dpcache.hxx:112
std::vector< std::unique_ptr< GroupItems > > GroupFieldsType
Definition: dpcache.hxx:120
void Dump() const
std::vector< ScDPItemData > ScDPItemDataVec
Definition: dpcache.hxx:52
bool mbDisposing
Definition: dpcache.hxx:131
When assigning a string value, you can also assign an interned string whose life-cycle is managed by ...
Definition: dpitemdata.hxx:29
void Clear(EHistoryType eHistory)
long Long
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
Field(const Field &)=delete
const Field & operator=(const Field &)=delete
IndexArrayType maData
Original source data represented as indices to the unique value list.
Definition: dpcache.hxx:85
ScDPItemDataVec maItems
Unique values in the field, stored in ascending order.
Definition: dpcache.hxx:78
std::unique_ptr< GroupItems > mpGroup
Optional items for grouped field.
Definition: dpcache.hxx:73
sal_uInt32 mnNumFormat
Definition: dpcache.hxx:87
ScDPItemDataVec maItems
Definition: dpcache.hxx:58
sal_Int32 mnGroupType
Definition: dpcache.hxx:60
ScDPNumGroupInfo maInfo
Definition: dpcache.hxx:59
const GroupItems & operator=(const GroupItems &)=delete
GroupItems(const GroupItems &)=delete
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
SvNumFormatType