LibreOffice Module sc (master) 1
formulagroup.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10#pragma once
11
12#include <config_feature_opencl.h>
13
14#include "address.hxx"
15#include "calcconfig.hxx"
16#include "types.hxx"
17#include "stlalgorithm.hxx"
18
19#if HAVE_FEATURE_OPENCL
21#endif
22
23#include <memory>
24#include <unordered_map>
25#include <vector>
26
27class ScDocument;
28class ScTokenArray;
29class ScFormulaCell;
30
31namespace sc {
32
34{
35 union
36 {
37 ScFormulaCell* mpCell; // non-shared formula cell
38 ScFormulaCell** mpCells; // pointer to the top formula cell in a shared group.
39 };
40
41 size_t mnRow;
42 size_t mnLength;
44
45 FormulaGroupEntry( ScFormulaCell** pCells, size_t nRow, size_t nLength );
46
47 FormulaGroupEntry( ScFormulaCell* pCell, size_t nRow );
48};
49
50// Despite the name, this is actually a cache of cell values, used by OpenCL
51// code ... I think. And obviously it's not really a struct either.
53{
55 typedef std::vector<double, DoubleAllocType> NumArrayType;
56 typedef std::vector<rtl_uString*> StrArrayType;
57 typedef std::vector<std::unique_ptr<NumArrayType>> NumArrayStoreType;
58 typedef std::vector<std::unique_ptr<StrArrayType>> StrArrayStoreType;
59
60 struct ColKey
61 {
64
65 struct Hash
66 {
67 size_t operator() ( const ColKey& rKey ) const;
68 };
69
70 ColKey( SCTAB nTab, SCCOL nCol );
71
72 bool operator== ( const ColKey& r ) const;
73 };
74
75 struct ColArray
76 {
79 size_t mnSize;
80
81 ColArray( NumArrayType* pNumArray, StrArrayType* pStrArray );
82 };
83
84 typedef std::unordered_map<ColKey, ColArray, ColKey::Hash> ColArraysType;
85
88
90
91 ColArray* getCachedColArray( SCTAB nTab, SCCOL nCol, size_t nSize );
92
94 SCTAB nTab, SCCOL nCol, NumArrayType* pNumArray, StrArrayType* pStrArray );
95
96 void discardCachedColArray(SCTAB nTab, SCCOL nCol);
97
98 void ensureStrArray( ColArray& rColArray, size_t nArrayLen );
99 void ensureNumArray( ColArray& rColArray, size_t nArrayLen );
100
105};
106
111{
112public:
114 virtual ~CompiledFormula();
115};
116
122{
124
125protected:
127
130
132 void MergeCalcConfig(const ScDocument& rDoc);
133
134public:
135 static FormulaGroupInterpreter *getStatic();
136#if HAVE_FEATURE_OPENCL
137 static void fillOpenCLInfo(std::vector<OpenCLPlatformInfo>& rPlatforms);
138 static bool switchOpenCLDevice(std::u16string_view 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 disableOpenCL_UnitTestsOnly();
142 static void getOpenCLDeviceInfo(sal_Int32& rDeviceId, sal_Int32& rPlatformId);
143#endif
144 virtual ScMatrixRef inverseMatrix(const ScMatrix& rMat) = 0;
145 virtual bool interpret(ScDocument& rDoc, const ScAddress& rTopPos, ScFormulaCellGroupRef& xGroup, ScTokenArray& rCode) = 0;
146};
147
148}
149
150/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Matrix data type that can store values of mixed types.
Definition: scmatrix.hxx:101
Custom allocator for STL container to ensure that the base address of allocated storage is aligned to...
Abstract base class for a "compiled" formula.
virtual ~CompiledFormula()
Abstract base class for vectorised formula group interpreters, plus a global instance factory.
static FormulaGroupInterpreter * msInstance
virtual ScMatrixRef inverseMatrix(const ScMatrix &rMat)=0
virtual bool interpret(ScDocument &rDoc, const ScAddress &rTopPos, ScFormulaCellGroupRef &xGroup, ScTokenArray &rCode)=0
bool switchOpenCLDevice(std::u16string_view aDevice, bool bAutoSelect, bool bForceEvaluation, OUString &rOutSelectedDeviceVersionIDString)
const std::vector< OpenCLPlatformInfo > & fillOpenCLInfo()
void getOpenCLDeviceInfo(size_t &rDeviceId, size_t &rPlatformId)
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
Configuration options for formula interpreter.
Definition: calcconfig.hxx:44
ColArray(NumArrayType *pNumArray, StrArrayType *pStrArray)
size_t operator()(const ColKey &rKey) const
ColKey(SCTAB nTab, SCCOL nCol)
bool operator==(const ColKey &r) const
const FormulaGroupContext & operator=(const FormulaGroupContext &)=delete
std::vector< rtl_uString * > StrArrayType
std::vector< double, DoubleAllocType > NumArrayType
std::unordered_map< ColKey, ColArray, ColKey::Hash > ColArraysType
StrArrayStoreType m_StrArrays
manage life cycle of numeric arrays.
void ensureNumArray(ColArray &rColArray, size_t nArrayLen)
AlignedAllocator< double, 256 > DoubleAllocType
void discardCachedColArray(SCTAB nTab, SCCOL nCol)
ColArray * setCachedColArray(SCTAB nTab, SCCOL nCol, NumArrayType *pNumArray, StrArrayType *pStrArray)
ColArray * getCachedColArray(SCTAB nTab, SCCOL nCol, size_t nSize)
keep track of longest array for each column.
std::vector< std::unique_ptr< NumArrayType > > NumArrayStoreType
NumArrayStoreType m_NumArrays
FormulaGroupContext(const FormulaGroupContext &)=delete
std::vector< std::unique_ptr< StrArrayType > > StrArrayStoreType
ColArraysType maColArrays
manage life cycle of string arrays.
void ensureStrArray(ColArray &rColArray, size_t nArrayLen)
FormulaGroupEntry(ScFormulaCell **pCells, size_t nRow, size_t nLength)
ScFormulaCell * mpCell
ScFormulaCell ** mpCells
sal_Int16 SCTAB
Definition: types.hxx:22
::boost::intrusive_ptr< ScFormulaCellGroup > ScFormulaCellGroupRef
Definition: types.hxx:43
sal_Int16 SCCOL
Definition: types.hxx:21
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
Definition: types.hxx:25