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 #ifndef INCLUDED_SC_INC_FORMULAGROUP_HXX
11 #define INCLUDED_SC_INC_FORMULAGROUP_HXX
12 
13 #include <config_feature_opencl.h>
14 
15 #include "address.hxx"
16 #include "calcconfig.hxx"
17 #include "types.hxx"
18 #include "stlalgorithm.hxx"
19 
20 #if HAVE_FEATURE_OPENCL
21 #include <opencl/platforminfo.hxx>
22 #endif
23 
24 #include <memory>
25 #include <unordered_map>
26 #include <vector>
27 
28 class ScDocument;
29 class ScTokenArray;
30 class ScFormulaCell;
31 
32 namespace sc {
33 
35 {
36  union
37  {
38  ScFormulaCell* mpCell; // non-shared formula cell
39  ScFormulaCell** mpCells; // pointer to the top formula cell in a shared group.
40  };
41 
42  size_t mnRow;
43  size_t mnLength;
44  bool mbShared;
45 
46  FormulaGroupEntry( ScFormulaCell** pCells, size_t nRow, size_t nLength );
47 
48  FormulaGroupEntry( ScFormulaCell* pCell, size_t nRow );
49 };
50 
51 // Despite the name, this is actually a cache of cell values, used by OpenCL
52 // code ... I think. And obviously it's not really a struct either.
54 {
56  typedef std::vector<double, DoubleAllocType> NumArrayType;
57  typedef std::vector<rtl_uString*> StrArrayType;
58  typedef std::vector<std::unique_ptr<NumArrayType>> NumArrayStoreType;
59  typedef std::vector<std::unique_ptr<StrArrayType>> StrArrayStoreType;
60 
61  struct ColKey
62  {
65 
66  struct Hash
67  {
68  size_t operator() ( const ColKey& rKey ) const;
69  };
70 
71  ColKey( SCTAB nTab, SCCOL nCol );
72 
73  bool operator== ( const ColKey& r ) const;
74  };
75 
76  struct ColArray
77  {
78  NumArrayType* mpNumArray;
79  StrArrayType* mpStrArray;
80  size_t mnSize;
81 
82  ColArray( NumArrayType* pNumArray, StrArrayType* pStrArray );
83  };
84 
85  typedef std::unordered_map<ColKey, ColArray, ColKey::Hash> ColArraysType;
86 
87  NumArrayStoreType m_NumArrays;
88  StrArrayStoreType m_StrArrays;
89 
90  ColArraysType maColArrays;
91 
92  ColArray* getCachedColArray( SCTAB nTab, SCCOL nCol, size_t nSize );
93 
95  SCTAB nTab, SCCOL nCol, NumArrayType* pNumArray, StrArrayType* pStrArray );
96 
97  void discardCachedColArray(SCTAB nTab, SCCOL nCol);
98 
99  void ensureStrArray( ColArray& rColArray, size_t nArrayLen );
100  void ensureNumArray( ColArray& rColArray, size_t nArrayLen );
101 
103  FormulaGroupContext(const FormulaGroupContext&) = delete;
104  const FormulaGroupContext& operator=(const FormulaGroupContext&) = delete;
106 };
107 
112 {
113 public:
114  CompiledFormula();
115  virtual ~CompiledFormula();
116 };
117 
123 {
125 
126 protected:
128 
131 
133  void MergeCalcConfig(const ScDocument& rDoc);
134 
135 public:
136  static FormulaGroupInterpreter *getStatic();
137 #if HAVE_FEATURE_OPENCL
138  static void fillOpenCLInfo(std::vector<OpenCLPlatformInfo>& rPlatforms);
139  static bool switchOpenCLDevice(const OUString& rDeviceId, bool bAutoSelect, bool bForceEvaluation = false);
140  // This is intended to be called from opencl-test.cxx only
141  static void enableOpenCL_UnitTestsOnly();
142  static void disableOpenCL_UnitTestsOnly();
143  static void getOpenCLDeviceInfo(sal_Int32& rDeviceId, sal_Int32& rPlatformId);
144 #endif
145  virtual ScMatrixRef inverseMatrix(const ScMatrix& rMat) = 0;
146  virtual bool interpret(ScDocument& rDoc, const ScAddress& rTopPos, ScFormulaCellGroupRef& xGroup, ScTokenArray& rCode) = 0;
147 };
148 
149 }
150 
151 #endif
152 
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Matrix data type that can store values of mixed types.
Definition: scmatrix.hxx:113
Abstract base class for a "compiled" formula.
::boost::intrusive_ptr< ScFormulaCellGroup > ScFormulaCellGroupRef
Definition: types.hxx:44
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:26
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:22
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:28
sal_Int16 SCTAB
Definition: types.hxx:23
const std::vector< OpenCLPlatformInfo > & fillOpenCLInfo()
ColArraysType maColArrays
manage life cycle of string arrays.