build fix
[LibreOffice.git] / sc / inc / formulagroup.hxx
blob57fe258661de827b71a0c25113983d777e78b411
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 #include <formula/opcode.hxx>
21 #if HAVE_FEATURE_OPENCL
22 #include <opencl/platforminfo.hxx>
23 #endif
24 #include <svl/sharedstringpool.hxx>
26 #include <memory>
27 #include <set>
28 #include <unordered_map>
29 #include <vector>
31 class ScDocument;
32 class ScTokenArray;
33 class ScFormulaCell;
35 namespace sc {
37 struct FormulaGroupEntry
39 union
41 ScFormulaCell* mpCell; // non-shared formula cell
42 ScFormulaCell** mpCells; // pointer to the top formula cell in a shared group.
45 size_t mnRow;
46 size_t mnLength;
47 bool mbShared;
49 FormulaGroupEntry( ScFormulaCell** pCells, size_t nRow, size_t nLength );
51 FormulaGroupEntry( ScFormulaCell* pCell, size_t nRow );
54 struct FormulaGroupContext
56 typedef AlignedAllocator<double,256> DoubleAllocType;
57 typedef std::vector<double, DoubleAllocType> NumArrayType;
58 typedef std::vector<rtl_uString*> StrArrayType;
59 typedef std::vector<std::unique_ptr<NumArrayType>> NumArrayStoreType;
60 typedef std::vector<std::unique_ptr<StrArrayType>> StrArrayStoreType;
62 struct ColKey
64 SCTAB mnTab;
65 SCCOL mnCol;
67 struct Hash
69 size_t operator() ( const ColKey& rKey ) const;
72 ColKey( SCTAB nTab, SCCOL nCol );
74 bool operator== ( const ColKey& r ) const;
77 struct ColArray
79 NumArrayType* mpNumArray;
80 StrArrayType* mpStrArray;
81 size_t mnSize;
83 ColArray( NumArrayType* pNumArray, StrArrayType* pStrArray );
86 typedef std::unordered_map<ColKey, ColArray, ColKey::Hash> ColArraysType;
88 NumArrayStoreType m_NumArrays; /// manage life cycle of numeric arrays.
89 StrArrayStoreType m_StrArrays; /// manage life cycle of string arrays.
91 ColArraysType maColArrays; /// keep track of longest array for each column.
93 ColArray* getCachedColArray( SCTAB nTab, SCCOL nCol, size_t nSize );
95 ColArray* setCachedColArray(
96 SCTAB nTab, SCCOL nCol, NumArrayType* pNumArray, StrArrayType* pStrArray );
98 void ensureStrArray( ColArray& rColArray, size_t nArrayLen );
99 void ensureNumArray( ColArray& rColArray, size_t nArrayLen );
101 FormulaGroupContext();
102 FormulaGroupContext(const FormulaGroupContext&) = delete;
103 const FormulaGroupContext& operator=(const FormulaGroupContext&) = delete;
104 ~FormulaGroupContext();
108 * Abstract base class for a "compiled" formula
110 class SC_DLLPUBLIC CompiledFormula
112 public:
113 CompiledFormula();
114 virtual ~CompiledFormula();
118 * Abstract base class for vectorised formula group interpreters,
119 * plus a global instance factory.
121 class SC_DLLPUBLIC FormulaGroupInterpreter
123 static FormulaGroupInterpreter *msInstance;
125 protected:
126 ScCalcConfig maCalcConfig;
128 FormulaGroupInterpreter() {}
129 virtual ~FormulaGroupInterpreter() {}
131 /// Merge global and document specific settings.
132 void MergeCalcConfig(const ScDocument& rDoc);
134 public:
135 static FormulaGroupInterpreter *getStatic();
136 #if HAVE_FEATURE_OPENCL
137 static void fillOpenCLInfo(std::vector<OpenCLPlatformInfo>& rPlatforms);
138 static bool switchOpenCLDevice(const OUString& rDeviceId, bool bAutoSelect, bool bForceEvaluation = false);
139 // This is intended to be called from opencl-test.cxx only
140 static void enableOpenCL_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();
152 virtual ~FormulaGroupInterpreterSoftware() override {}
154 virtual ScMatrixRef inverseMatrix(const ScMatrix& rMat) override;
155 virtual bool interpret(ScDocument& rDoc, const ScAddress& rTopPos, ScFormulaCellGroupRef& xGroup, ScTokenArray& rCode) override;
160 #endif
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */