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 SC_FORMULAGROUP_HXX
11 #define SC_FORMULAGROUP_HXX
13 #include "address.hxx"
15 #include "platforminfo.hxx"
17 #include "svl/sharedstringpool.hxx"
20 #include <boost/noncopyable.hpp>
21 #include <boost/ptr_container/ptr_vector.hpp>
22 #include <boost/unordered_set.hpp>
29 struct FormulaGroupContext
: boost::noncopyable
31 typedef std::vector
<double> NumArrayType
;
32 typedef std::vector
<rtl_uString
*> StrArrayType
;
33 typedef boost::ptr_vector
<NumArrayType
> NumArrayStoreType
;
34 typedef boost::ptr_vector
<StrArrayType
> StrArrayStoreType
;
43 size_t operator() ( const ColKey
& rKey
) const;
46 ColKey( SCTAB nTab
, SCCOL nCol
);
48 bool operator== ( const ColKey
& r
) const;
49 bool operator!= ( const ColKey
& r
) const;
54 NumArrayType
* mpNumArray
;
55 StrArrayType
* mpStrArray
;
58 ColArray( NumArrayType
* pNumArray
, StrArrayType
* pStrArray
);
61 typedef boost::unordered_map
<ColKey
, ColArray
, ColKey::Hash
> ColArraysType
;
63 NumArrayStoreType maNumArrays
; /// manage life cycle of numeric arrays.
64 StrArrayStoreType maStrArrays
; /// manage life cycle of string arrays.
66 ColArraysType maColArrays
; /// keep track of longest array for each column.
68 ColArray
* getCachedColArray( SCTAB nTab
, SCCOL nCol
, size_t nSize
);
70 ColArray
* setCachedColArray(
71 SCTAB nTab
, SCCOL nCol
, NumArrayType
* pNumArray
, StrArrayType
* pStrArray
);
73 void ensureStrArray( ColArray
& rColArray
, size_t nArrayLen
);
74 void ensureNumArray( ColArray
& rColArray
, size_t nArrayLen
);
78 * Abstract base class for a "compiled" formula
80 class SC_DLLPUBLIC CompiledFormula
85 * Abstract base class for vectorised formula group interpreters,
86 * plus a global instance factory.
88 class SC_DLLPUBLIC FormulaGroupInterpreter
90 static FormulaGroupInterpreter
*msInstance
;
92 FormulaGroupInterpreter() {}
93 virtual ~FormulaGroupInterpreter() {}
96 static FormulaGroupInterpreter
*getStatic();
97 static void fillOpenCLInfo(std::vector
<OpenclPlatformInfo
>& rPlatforms
);
98 static bool switchOpenCLDevice(const OUString
& rDeviceId
, bool bAutoSelect
, bool bForceEvaluation
= false);
99 static void enableOpenCL(bool bEnable
);
100 static void getOpenCLDeviceInfo(sal_Int32
& rDeviceId
, sal_Int32
& rPlatformId
);
102 virtual ScMatrixRef
inverseMatrix(const ScMatrix
& rMat
) = 0;
103 virtual CompiledFormula
* createCompiledFormula(ScDocument
& rDoc
,
104 const ScAddress
& rTopPos
,
105 ScFormulaCellGroupRef
& xGroup
,
106 ScTokenArray
& rCode
) = 0;
107 virtual bool interpret(ScDocument
& rDoc
, const ScAddress
& rTopPos
, ScFormulaCellGroupRef
& xGroup
, ScTokenArray
& rCode
) = 0;
110 /// Inherit from this for alternate formula group calculation approaches.
111 class SC_DLLPUBLIC FormulaGroupInterpreterSoftware
: public FormulaGroupInterpreter
114 FormulaGroupInterpreterSoftware();
115 virtual ~FormulaGroupInterpreterSoftware() {}
117 virtual ScMatrixRef
inverseMatrix(const ScMatrix
& rMat
);
118 virtual CompiledFormula
* createCompiledFormula(ScDocument
& rDoc
,
119 const ScAddress
& rTopPos
,
120 ScFormulaCellGroupRef
& xGroup
,
121 ScTokenArray
& rCode
) SAL_OVERRIDE
;
122 virtual bool interpret(ScDocument
& rDoc
, const ScAddress
& rTopPos
, ScFormulaCellGroupRef
& xGroup
, ScTokenArray
& rCode
) SAL_OVERRIDE
;
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */