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
20 #include <opencl/platforminfo.hxx>
21 #endif
22 
23 #include <memory>
24 #include <unordered_map>
25 #include <vector>
26 
27 class ScDocument;
28 class ScTokenArray;
29 class ScFormulaCell;
30 
31 namespace 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;
43  bool mbShared;
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  {
77  NumArrayType* mpNumArray;
78  StrArrayType* mpStrArray;
79  size_t mnSize;
80 
81  ColArray( NumArrayType* pNumArray, StrArrayType* pStrArray );
82  };
83 
84  typedef std::unordered_map<ColKey, ColArray, ColKey::Hash> ColArraysType;
85 
86  NumArrayStoreType m_NumArrays;
87  StrArrayStoreType m_StrArrays;
88 
89  ColArraysType maColArrays;
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 
102  FormulaGroupContext(const FormulaGroupContext&) = delete;
103  const FormulaGroupContext& operator=(const FormulaGroupContext&) = delete;
105 };
106 
111 {
112 public:
113  CompiledFormula();
114  virtual ~CompiledFormula();
115 };
116 
122 {
124 
125 protected:
127 
130 
132  void MergeCalcConfig(const ScDocument& rDoc);
133 
134 public:
135  static FormulaGroupInterpreter *getStatic();
136 #if HAVE_FEATURE_OPENCL
137  static void fillOpenCLInfo(std::vector<OpenCLPlatformInfo>& rPlatforms);
138  static bool switchOpenCLDevice(const OUString& 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:112
Abstract base class for a "compiled" formula.
::boost::intrusive_ptr< ScFormulaCellGroup > ScFormulaCellGroupRef
Definition: types.hxx:43
ColArray * setCachedColArray(SCTAB nTab, SCCOL nCol, NumArrayType *pNumArray, StrArrayType *pStrArray)
void getOpenCLDeviceInfo(size_t &rDeviceId, size_t &rPlatformId)
std::vector< std::unique_ptr< NumArrayType > > NumArrayStoreType
Abstract base class for vectorised formula group interpreters, plus a global instance factory...
bool switchOpenCLDevice(const OUString *pDeviceId, bool bAutoSelect, bool bForceEvaluation, OUString &rOutSelectedDeviceVersionIDString)
ColArray * getCachedColArray(SCTAB nTab, SCCOL nCol, size_t nSize)
keep track of longest array for each column.
size_t operator()(const ColKey &rKey) const
std::vector< std::unique_ptr< StrArrayType > > StrArrayStoreType
void ensureStrArray(ColArray &rColArray, size_t nArrayLen)
ColArray(NumArrayType *pNumArray, StrArrayType *pStrArray)
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
Definition: types.hxx:25
std::vector< double, DoubleAllocType > NumArrayType
bool operator==(const ColKey &r) const
StrArrayStoreType m_StrArrays
manage life cycle of numeric arrays.
void discardCachedColArray(SCTAB nTab, SCCOL nCol)
const FormulaGroupContext & operator=(const FormulaGroupContext &)=delete
sal_Int16 SCCOL
Definition: types.hxx:21
virtual ~CompiledFormula()
ColKey(SCTAB nTab, SCCOL nCol)
AlignedAllocator< double, 256 > DoubleAllocType
static FormulaGroupInterpreter * msInstance
FormulaGroupEntry(ScFormulaCell **pCells, size_t nRow, size_t nLength)
Custom allocator for STL container to ensure that the base address of allocated storage is aligned to...
std::vector< rtl_uString * > StrArrayType
Configuration options for formula interpreter.
Definition: calcconfig.hxx:43
NumArrayStoreType m_NumArrays
ScFormulaCell ** mpCells
ScFormulaCell * mpCell
std::unordered_map< ColKey, ColArray, ColKey::Hash > ColArraysType
void ensureNumArray(ColArray &rColArray, size_t nArrayLen)
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
sal_Int16 SCTAB
Definition: types.hxx:22
const std::vector< OpenCLPlatformInfo > & fillOpenCLInfo()
ColArraysType maColArrays
manage life cycle of string arrays.