LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sc / inc / dpcache.hxx
blobe46e38f66a52cce0d9a965b78fb617aba6a4fe49
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #pragma once
21 #include "address.hxx"
22 #include "calcmacros.hxx"
23 #include "dpitemdata.hxx"
24 #include "dpnumgroupinfo.hxx"
25 #include "scdllapi.h"
26 #include "types.hxx"
28 #include <mdds/flat_segment_tree.hpp>
29 #include <tools/long.hxx>
30 #include <o3tl/sorted_vector.hxx>
32 #include <memory>
33 #include <unordered_set>
34 #include <vector>
36 struct ScQueryParam;
37 class ScDPObject;
38 class ScDocument;
39 class SvNumberFormatter;
41 enum class SvNumFormatType : sal_Int16;
43 /**
44 * This class represents the cached data part of the datapilot cache table
45 * implementation.
47 class SC_DLLPUBLIC ScDPCache
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 o3tl::sorted_vector<ScDPObject*> ScDPObjectSet;
54 typedef std::vector<SCROW> IndexArrayType;
56 struct SAL_DLLPRIVATE GroupItems
58 ScDPItemDataVec maItems;
59 ScDPNumGroupInfo maInfo;
60 sal_Int32 mnGroupType;
62 GroupItems();
63 GroupItems(const GroupItems&) = delete;
64 const GroupItems& operator=(const GroupItems&) = delete;
65 GroupItems(const ScDPNumGroupInfo& rInfo, sal_Int32 nGroupType);
68 struct SAL_DLLPRIVATE Field
70 /**
71 * Optional items for grouped field.
73 std::unique_ptr<GroupItems> mpGroup;
75 /**
76 * Unique values in the field, stored in ascending order.
78 ScDPItemDataVec maItems;
80 /**
81 * Original source data represented as indices to the unique value
82 * list. The order of the data is as they appear in the original
83 * data source.
85 IndexArrayType maData;
87 sal_uInt32 mnNumFormat;
89 Field();
90 Field(const Field&) = delete;
91 const Field& operator=(const Field&) = delete;
94 /**
95 * Interface for connecting to database source. Column index is 0-based.
97 class DBConnector
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() {}
109 private:
111 ScDocument& mrDoc;
112 SCCOL mnColumnCount;
115 * All pivot table objects that references this cache.
117 mutable ScDPObjectSet maRefObjects;
119 typedef std::vector< std::unique_ptr<Field> > FieldsType;
120 typedef std::vector< std::unique_ptr<GroupItems> > GroupFieldsType;
122 FieldsType maFields;
123 GroupFieldsType maGroupFields;
124 std::vector<StringSetType> maStringPools; // one for each field.
126 std::vector<OUString> maLabelNames; // Stores dimension names and the data layout dimension name at position 0.
127 EmptyRowsType maEmptyRows;
128 SCROW mnDataSize;
129 SCROW mnRowCount;
131 bool mbDisposing;
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;
139 SCROW GetIdByItemData(tools::Long nDim, const ScDPItemData& rItem) const;
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;
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;
156 * Return a group type identifier. The values correspond with
157 * css::sheet::DataPilotFieldGroupBy constant values.
159 * @param nDim 0-based dimension index.
161 * @return group type identifier, or 0 on failure.
163 sal_Int32 GetGroupType(tools::Long nDim) const;
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;
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);
176 * Row count is the number of records plus any trailing empty rows in case
177 * the source data is sheet and contains trailing empty rows.
179 SCROW GetRowCount() const;
182 * Data size is the number of records without any trailing empty rows for
183 * sheet source data. For any other source type, this should equal the
184 * row count.
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;
192 ScDocument& GetDoc() const;
193 tools::Long GetColumnCount() const;
195 const ScDPItemData* GetItemDataById( tools::Long nDim, SCROW nId ) const;
197 size_t GetFieldCount() const;
198 size_t GetGroupFieldCount() const;
200 ScDPCache(const ScDPCache&) = delete;
201 const ScDPCache& operator=(const ScDPCache&) = delete;
202 ScDPCache(ScDocument& rDoc);
203 ~ScDPCache();
205 #if DUMP_PIVOT_TABLE
206 void Dump() const;
207 #endif
209 private:
210 void PostInit();
211 void Clear();
212 const GroupItems* GetGroupItems(tools::Long nDim) const;
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */