Bump version to 6.4-15
[LibreOffice.git] / sc / inc / formulagroup.hxx
blob8cdc97818d0cfc1a00b4617c3cb56402e08a5318
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_feature_opencl.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** const mpCells; // pointer to the top formula cell in a shared group.
42 size_t const mnRow;
43 size_t const mnLength;
44 bool const 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 const mnTab;
64 SCCOL const 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 discardCachedColArray(SCTAB nTab, SCCOL nCol);
99 void ensureStrArray( ColArray& rColArray, size_t nArrayLen );
100 void ensureNumArray( ColArray& rColArray, size_t nArrayLen );
102 FormulaGroupContext();
103 FormulaGroupContext(const FormulaGroupContext&) = delete;
104 const FormulaGroupContext& operator=(const FormulaGroupContext&) = delete;
105 ~FormulaGroupContext();
109 * Abstract base class for a "compiled" formula
111 class SC_DLLPUBLIC CompiledFormula
113 public:
114 CompiledFormula();
115 virtual ~CompiledFormula();
119 * Abstract base class for vectorised formula group interpreters,
120 * plus a global instance factory.
122 class SC_DLLPUBLIC FormulaGroupInterpreter
124 static FormulaGroupInterpreter *msInstance;
126 protected:
127 ScCalcConfig maCalcConfig;
129 FormulaGroupInterpreter() {}
130 virtual ~FormulaGroupInterpreter() {}
132 /// Merge global and document specific settings.
133 void MergeCalcConfig(const ScDocument& rDoc);
135 public:
136 static FormulaGroupInterpreter *getStatic();
137 #if HAVE_FEATURE_OPENCL
138 static void fillOpenCLInfo(std::vector<OpenCLPlatformInfo>& rPlatforms);
139 static bool switchOpenCLDevice(const OUString& rDeviceId, bool bAutoSelect, bool bForceEvaluation = false);
140 // This is intended to be called from opencl-test.cxx only
141 static void enableOpenCL_UnitTestsOnly();
142 static void disableOpenCL_UnitTestsOnly();
143 static void getOpenCLDeviceInfo(sal_Int32& rDeviceId, sal_Int32& rPlatformId);
144 #endif
145 virtual ScMatrixRef inverseMatrix(const ScMatrix& rMat) = 0;
146 virtual bool interpret(ScDocument& rDoc, const ScAddress& rTopPos, ScFormulaCellGroupRef& xGroup, ScTokenArray& rCode) = 0;
151 #endif
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */