1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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"
18 #include "stlalgorithm.hxx"
20 #if HAVE_FEATURE_OPENCL
21 #include <opencl/platforminfo.hxx>
25 #include <unordered_map>
34 struct FormulaGroupEntry
38 ScFormulaCell
* mpCell
; // non-shared formula cell
39 ScFormulaCell
** mpCells
; // pointer to the top formula cell in a shared group.
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
;
68 size_t operator() ( const ColKey
& rKey
) const;
71 ColKey( SCTAB nTab
, SCCOL nCol
);
73 bool operator== ( const ColKey
& r
) const;
78 NumArrayType
* mpNumArray
;
79 StrArrayType
* mpStrArray
;
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
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
;
125 ScCalcConfig maCalcConfig
;
127 FormulaGroupInterpreter() {}
128 virtual ~FormulaGroupInterpreter() {}
130 /// Merge global and document specific settings.
131 void MergeCalcConfig(const ScDocument
& rDoc
);
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
);
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
151 FormulaGroupInterpreterSoftware();
153 virtual ScMatrixRef
inverseMatrix(const ScMatrix
& rMat
) override
;
154 virtual bool interpret(ScDocument
& rDoc
, const ScAddress
& rTopPos
, ScFormulaCellGroupRef
& xGroup
, ScTokenArray
& rCode
) override
;
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */