LibreOffice Module sc (master) 1
interpretercontext.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 <vector>
13#include <memory>
14#include "types.hxx"
15
16namespace formula
17{
18class FormulaToken;
19}
20
21#define TOKEN_CACHE_SIZE 8
22
23class ScDocument;
25struct ScLookupCacheMap;
26class ScInterpreter;
27enum class SvNumFormatType : sal_Int16;
28
29// SetNumberFormat() is not thread-safe, so calls to it need to be delayed to the main thread.
31{
34 sal_uInt32 mnNumberFormat;
35};
36
38{
39 sal_uInt32 nIndex;
41 bool bIsValid : 1;
42
44 : nIndex(0)
45 , eType(static_cast<SvNumFormatType>(0))
46 , bIsValid(false)
47 {
48 }
49};
50
52
54{
57 std::vector<formula::FormulaToken*> maTokens;
58 std::vector<DelayedSetNumberFormat> maDelayedSetNumberFormat;
59 std::unique_ptr<ScLookupCacheMap> mxScLookupCache; // cache for lookups like VLOOKUP and MATCH
60 // Allocation cache for "aConditions" array in ScInterpreter::IterateParameterIfs()
61 // This is populated/used only when formula-group threading is enabled.
62 std::vector<sal_uInt8> maConditions;
64
65 ScInterpreterContext(const ScDocument& rDoc, SvNumberFormatter* pFormatter);
66
68
70
72 {
73 if (mpFormatter == nullptr)
74 const_cast<ScInterpreterContext*>(this)->initFormatTable();
75 return mpFormatter;
76 }
77
78 SvNumFormatType GetNumberFormatType(sal_uInt32 nFIndex) const;
79
80private:
82 void ResetTokens();
83 void SetDocAndFormatter(const ScDocument& rDoc, SvNumberFormatter* pFormatter);
84 void Cleanup();
85 void ClearLookupCache();
86 void initFormatTable();
89};
90
93
95{
98
99 std::vector<std::unique_ptr<ScInterpreterContext>> maPool;
102
104 : mnNextFree(0)
105 , mbThreaded(bThreaded)
106 {
107 }
108
110
113
114 // API for threaded case
115
116 // Ensures nNumThreads elements in pool.
117 void Init(size_t nNumThreads, const ScDocument& rDoc, SvNumberFormatter* pFormatter);
118
119 // Returns ScInterpreterContext* for thread index nThreadIdx
121
122 // API for non-threaded
123
124 // Ensures there is one unused element in the pool.
125 void Init(const ScDocument& rDoc, SvNumberFormatter* pFormatter);
126
127 // Returns ScInterpreterContext* for non-threaded use.
129
130 // Common API for threaded/non-threaded
131
132 // Cleans up the contexts prepared by call to immediately previous Init() and
133 // marks them all as unused.
134 void ReturnToPool();
135
136public:
137 // Only to be used to clear lookup cache in all pool elements
138 static void ClearLookupCaches();
139};
140
142{
144
145public:
146 ScThreadedInterpreterContextGetterGuard(size_t nNumThreads, const ScDocument& rDoc,
147 SvNumberFormatter* pFormatter);
149
150 // Returns ScInterpreterContext* for thread index nThreadIdx
152};
153
155{
157#if !defined NDEBUG
159#endif
160
161public:
164
165 // Returns ScInterpreterContext* for non-threaded use.
167};
168
169/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
ScInterpreterContextPool & rPool
ScInterpreterContext * GetInterpreterContext() const
ScInterpreterContextGetterGuard(const ScDocument &rDoc, SvNumberFormatter *pFormatter)
void Init(size_t nNumThreads, const ScDocument &rDoc, SvNumberFormatter *pFormatter)
ScInterpreterContextPool(bool bThreaded)
static ScInterpreterContextPool aNonThreadedInterpreterPool
static ScInterpreterContextPool aThreadedInterpreterPool
std::vector< std::unique_ptr< ScInterpreterContext > > maPool
ScInterpreterContext * GetInterpreterContext() const
ScInterpreterContext * GetInterpreterContextForThreadIdx(size_t nThreadIdx) const
ScInterpreterContext * GetInterpreterContextForThreadIdx(size_t nThreadIdx) const
ScThreadedInterpreterContextGetterGuard(size_t nNumThreads, const ScDocument &rDoc, SvNumberFormatter *pFormatter)
SvNumFormatType eType
ScInterpreterContext()=delete
void SetDocAndFormatter(const ScDocument &rDoc, SvNumberFormatter *pFormatter)
const ScDocument * mpDoc
std::unique_ptr< ScLookupCacheMap > mxScLookupCache
std::vector< formula::FormulaToken * > maTokens
SvNumberFormatter * GetFormatTable() const
SvNumFormatType GetNumberFormatType(sal_uInt32 nFIndex) const
std::vector< sal_uInt8 > maConditions
std::vector< DelayedSetNumberFormat > maDelayedSetNumberFormat
ScInterpreter * pInterpreter
NFIndexAndFmtType maNFTypeCache
SvNumberFormatter * mpFormatter
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
SvNumFormatType