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 "address.hxx"
15 #include "platforminfo.hxx"
16 #include "stlalgorithm.hxx"
18 #include <svl/sharedstringpool.hxx>
21 #include <boost/noncopyable.hpp>
22 #include <boost/ptr_container/ptr_vector.hpp>
23 #include <boost/unordered_set.hpp>
31 struct FormulaGroupEntry
35 ScFormulaCell
* mpCell
; // non-shared formula cell
36 ScFormulaCell
** mpCells
; // pointer to the top formula cell in a shared group.
43 FormulaGroupEntry( ScFormulaCell
** pCells
, size_t nRow
, size_t nLength
);
45 FormulaGroupEntry( ScFormulaCell
* pCell
, size_t nRow
);
48 struct FormulaGroupContext
: boost::noncopyable
50 typedef AlignedAllocator
<double,256> DoubleAllocType
;
51 typedef std::vector
<double, DoubleAllocType
> NumArrayType
;
52 typedef std::vector
<rtl_uString
*> StrArrayType
;
53 typedef boost::ptr_vector
<NumArrayType
> NumArrayStoreType
;
54 typedef boost::ptr_vector
<StrArrayType
> StrArrayStoreType
;
63 size_t operator() ( const ColKey
& rKey
) const;
66 ColKey( SCTAB nTab
, SCCOL nCol
);
68 bool operator== ( const ColKey
& r
) const;
69 bool operator!= ( const ColKey
& r
) const;
74 NumArrayType
* mpNumArray
;
75 StrArrayType
* mpStrArray
;
78 ColArray( NumArrayType
* pNumArray
, StrArrayType
* pStrArray
);
81 typedef boost::unordered_map
<ColKey
, ColArray
, ColKey::Hash
> ColArraysType
;
83 NumArrayStoreType maNumArrays
; /// manage life cycle of numeric arrays.
84 StrArrayStoreType maStrArrays
; /// manage life cycle of string arrays.
86 ColArraysType maColArrays
; /// keep track of longest array for each column.
88 ColArray
* getCachedColArray( SCTAB nTab
, SCCOL nCol
, size_t nSize
);
90 ColArray
* setCachedColArray(
91 SCTAB nTab
, SCCOL nCol
, NumArrayType
* pNumArray
, StrArrayType
* pStrArray
);
93 void ensureStrArray( ColArray
& rColArray
, size_t nArrayLen
);
94 void ensureNumArray( ColArray
& rColArray
, size_t nArrayLen
);
96 FormulaGroupContext();
97 ~FormulaGroupContext();
101 * Abstract base class for a "compiled" formula
103 class SC_DLLPUBLIC CompiledFormula
107 virtual ~CompiledFormula();
111 * Abstract base class for vectorised formula group interpreters,
112 * plus a global instance factory.
114 class SC_DLLPUBLIC FormulaGroupInterpreter
116 static FormulaGroupInterpreter
*msInstance
;
118 FormulaGroupInterpreter() {}
119 virtual ~FormulaGroupInterpreter() {}
122 static FormulaGroupInterpreter
*getStatic();
123 static void fillOpenCLInfo(std::vector
<OpenclPlatformInfo
>& rPlatforms
);
124 static bool switchOpenCLDevice(const OUString
& rDeviceId
, bool bAutoSelect
, bool bForceEvaluation
= false);
125 static void enableOpenCL(bool bEnable
);
126 static void getOpenCLDeviceInfo(sal_Int32
& rDeviceId
, sal_Int32
& rPlatformId
);
128 virtual ScMatrixRef
inverseMatrix(const ScMatrix
& rMat
) = 0;
129 virtual CompiledFormula
* createCompiledFormula(ScDocument
& rDoc
,
130 const ScAddress
& rTopPos
,
131 ScFormulaCellGroup
& rGroup
,
132 ScTokenArray
& rCode
) = 0;
133 virtual bool interpret(ScDocument
& rDoc
, const ScAddress
& rTopPos
, ScFormulaCellGroupRef
& xGroup
, ScTokenArray
& rCode
) = 0;
136 /// Inherit from this for alternate formula group calculation approaches.
137 class SC_DLLPUBLIC FormulaGroupInterpreterSoftware
: public FormulaGroupInterpreter
140 FormulaGroupInterpreterSoftware();
141 virtual ~FormulaGroupInterpreterSoftware() {}
143 virtual ScMatrixRef
inverseMatrix(const ScMatrix
& rMat
) SAL_OVERRIDE
;
144 virtual CompiledFormula
* createCompiledFormula(ScDocument
& rDoc
,
145 const ScAddress
& rTopPos
,
146 ScFormulaCellGroup
& rGroup
,
147 ScTokenArray
& rCode
) SAL_OVERRIDE
;
148 virtual bool interpret(ScDocument
& rDoc
, const ScAddress
& rTopPos
, ScFormulaCellGroupRef
& xGroup
, ScTokenArray
& rCode
) SAL_OVERRIDE
;
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */