Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sc / inc / formulagroup.hxx
blobf0dcb4888a7278cfe79c716b2a0a4a189f84031e
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/.
8 */
10 #ifndef INCLUDED_SC_INC_FORMULAGROUP_HXX
11 #define INCLUDED_SC_INC_FORMULAGROUP_HXX
13 #include <config_features.h>
15 #include "address.hxx"
16 #include "calcconfig.hxx"
17 #include "types.hxx"
18 #include "stlalgorithm.hxx"
20 #if HAVE_FEATURE_OPENCL
21 #include <opencl/platforminfo.hxx>
22 #endif
24 #include <memory>
25 #include <unordered_map>
26 #include <vector>
28 class ScDocument;
29 class ScTokenArray;
30 class ScFormulaCell;
32 namespace sc {
34 struct FormulaGroupEntry
36 union
38 ScFormulaCell* mpCell; // non-shared formula cell
39 ScFormulaCell** mpCells; // pointer to the top formula cell in a shared group.
42 size_t mnRow;
43 size_t mnLength;
44 bool mbShared;
46 FormulaGroupEntry( ScFormulaCell** pCells, size_t nRow, size_t nLength );
48 FormulaGroupEntry( ScFormulaCell* pCell, size_t nRow );
51 // Despite the name, this is actually a cache of cell values, used by OpenCL
52 // code ... I think. And obviously it's not really a struct either.
53 struct FormulaGroupContext
55 typedef AlignedAllocator<double,256> DoubleAllocType;
56 typedef std::vector<double, DoubleAllocType> NumArrayType;
57 typedef std::vector<rtl_uString*> StrArrayType;
58 typedef std::vector<std::unique_ptr<NumArrayType>> NumArrayStoreType;
59 typedef std::vector<std::unique_ptr<StrArrayType>> StrArrayStoreType;
61 struct ColKey
63 SCTAB mnTab;
64 SCCOL mnCol;
66 struct Hash
68 size_t operator() ( const ColKey& rKey ) const;
71 ColKey( SCTAB nTab, SCCOL nCol );
73 bool operator== ( const ColKey& r ) const;
76 struct ColArray
78 NumArrayType* mpNumArray;
79 StrArrayType* mpStrArray;
80 size_t mnSize;
82 ColArray( NumArrayType* pNumArray, StrArrayType* pStrArray );
85 typedef std::unordered_map<ColKey, ColArray, ColKey::Hash> ColArraysType;
87 NumArrayStoreType m_NumArrays; /// manage life cycle of numeric arrays.
88 StrArrayStoreType m_StrArrays; /// manage life cycle of string arrays.
90 ColArraysType maColArrays; /// keep track of longest array for each column.
92 ColArray* getCachedColArray( SCTAB nTab, SCCOL nCol, size_t nSize );
94 ColArray* setCachedColArray(
95 SCTAB nTab, SCCOL nCol, NumArrayType* pNumArray, StrArrayType* pStrArray );
97 void ensureStrArray( ColArray& rColArray, size_t nArrayLen );
98 void ensureNumArray( ColArray& rColArray, size_t nArrayLen );
100 FormulaGroupContext();
101 FormulaGroupContext(const FormulaGroupContext&) = delete;
102 const FormulaGroupContext& operator=(const FormulaGroupContext&) = delete;
103 ~FormulaGroupContext();
107 * Abstract base class for a "compiled" formula
109 class SC_DLLPUBLIC CompiledFormula
111 public:
112 CompiledFormula();
113 virtual ~CompiledFormula();
117 * Abstract base class for vectorised formula group interpreters,
118 * plus a global instance factory.
120 class SC_DLLPUBLIC FormulaGroupInterpreter
122 static FormulaGroupInterpreter *msInstance;
124 protected:
125 ScCalcConfig maCalcConfig;
127 FormulaGroupInterpreter() {}
128 virtual ~FormulaGroupInterpreter() {}
130 /// Merge global and document specific settings.
131 void MergeCalcConfig(const ScDocument& rDoc);
133 public:
134 static FormulaGroupInterpreter *getStatic();
135 #if HAVE_FEATURE_OPENCL
136 static void fillOpenCLInfo(std::vector<OpenCLPlatformInfo>& rPlatforms);
137 static bool switchOpenCLDevice(const OUString& rDeviceId, bool bAutoSelect, bool bForceEvaluation = false);
138 // This is intended to be called from opencl-test.cxx only
139 static void enableOpenCL_UnitTestsOnly();
140 static void disableOpenCL_UnitTestsOnly();
141 static void getOpenCLDeviceInfo(sal_Int32& rDeviceId, sal_Int32& rPlatformId);
142 #endif
143 virtual ScMatrixRef inverseMatrix(const ScMatrix& rMat) = 0;
144 virtual bool interpret(ScDocument& rDoc, const ScAddress& rTopPos, ScFormulaCellGroupRef& xGroup, ScTokenArray& rCode) = 0;
147 /// Inherit from this for alternate formula group calculation approaches.
148 class SC_DLLPUBLIC FormulaGroupInterpreterSoftware : public FormulaGroupInterpreter
150 public:
151 FormulaGroupInterpreterSoftware();
153 virtual ScMatrixRef inverseMatrix(const ScMatrix& rMat) override;
154 virtual bool interpret(ScDocument& rDoc, const ScAddress& rTopPos, ScFormulaCellGroupRef& xGroup, ScTokenArray& rCode) override;
159 #endif
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */