Bump version to 4.3-4
[LibreOffice.git] / sc / inc / formulagroup.hxx
bloba063cdfa314395e969099801d6411009e8cc24d1
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 "address.hxx"
14 #include "types.hxx"
15 #include "platforminfo.hxx"
16 #include "stlalgorithm.hxx"
18 #include <svl/sharedstringpool.hxx>
20 #include <vector>
21 #include <boost/noncopyable.hpp>
22 #include <boost/ptr_container/ptr_vector.hpp>
23 #include <boost/unordered_set.hpp>
25 class ScDocument;
26 class ScTokenArray;
27 class ScFormulaCell;
29 namespace sc {
31 struct FormulaGroupEntry
33 union
35 ScFormulaCell* mpCell; // non-shared formula cell
36 ScFormulaCell** mpCells; // pointer to the top formula cell in a shared group.
39 size_t mnRow;
40 size_t mnLength;
41 bool mbShared;
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;
56 struct ColKey
58 SCTAB mnTab;
59 SCCOL mnCol;
61 struct Hash
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;
72 struct ColArray
74 NumArrayType* mpNumArray;
75 StrArrayType* mpStrArray;
76 size_t mnSize;
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
105 public:
106 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;
117 protected:
118 FormulaGroupInterpreter() {}
119 virtual ~FormulaGroupInterpreter() {}
121 public:
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
139 public:
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;
153 #endif
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */