1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
21 #define TOKEN_CACHE_SIZE 8
24 class SvNumberFormatter
;
25 struct ScLookupCacheMap
;
27 enum class SvNumFormatType
: sal_Int16
;
29 // SetNumberFormat() is not thread-safe, so calls to it need to be delayed to the main thread.
30 struct DelayedSetNumberFormat
34 sal_uInt32 mnNumberFormat
;
37 struct NFIndexAndFmtType
40 SvNumFormatType eType
: 16;
45 , eType(static_cast<SvNumFormatType
>(0))
51 class ScInterpreterContextPool
;
53 struct ScInterpreterContext
55 const ScDocument
* mpDoc
;
56 size_t mnTokenCachePos
;
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
;
63 ScInterpreter
* pInterpreter
;
65 ScInterpreterContext(const ScDocument
& rDoc
, SvNumberFormatter
* pFormatter
);
67 ScInterpreterContext() = delete;
69 ~ScInterpreterContext();
71 SvNumberFormatter
* GetFormatTable() const
73 if (mpFormatter
== nullptr)
74 const_cast<ScInterpreterContext
*>(this)->initFormatTable();
78 SvNumFormatType
GetNumberFormatType(sal_uInt32 nFIndex
) const;
81 friend class ScInterpreterContextPool
;
83 void SetDocAndFormatter(const ScDocument
& rDoc
, SvNumberFormatter
* pFormatter
);
85 void ClearLookupCache(const ScDocument
* pDoc
);
86 void initFormatTable();
87 SvNumberFormatter
* mpFormatter
;
88 mutable NFIndexAndFmtType maNFTypeCache
;
91 class ScThreadedInterpreterContextGetterGuard
;
92 class ScInterpreterContextGetterGuard
;
94 class ScInterpreterContextPool
96 friend class ScThreadedInterpreterContextGetterGuard
;
97 friend class ScInterpreterContextGetterGuard
;
99 std::vector
<std::unique_ptr
<ScInterpreterContext
>> maPool
;
103 ScInterpreterContextPool(bool bThreaded
)
105 , mbThreaded(bThreaded
)
109 ~ScInterpreterContextPool() {}
111 static ScInterpreterContextPool aThreadedInterpreterPool
;
112 static ScInterpreterContextPool aNonThreadedInterpreterPool
;
114 // API for threaded case
116 // Ensures nNumThreads elements in pool.
117 void Init(size_t nNumThreads
, const ScDocument
& rDoc
, SvNumberFormatter
* pFormatter
);
119 // Returns ScInterpreterContext* for thread index nThreadIdx
120 ScInterpreterContext
* GetInterpreterContextForThreadIdx(size_t nThreadIdx
) const;
122 // API for non-threaded
124 // Ensures there is one unused element in the pool.
125 void Init(const ScDocument
& rDoc
, SvNumberFormatter
* pFormatter
);
127 // Returns ScInterpreterContext* for non-threaded use.
128 ScInterpreterContext
* GetInterpreterContext() const;
130 // Common API for threaded/non-threaded
132 // Cleans up the contexts prepared by call to immediately previous Init() and
133 // marks them all as unused.
137 // Only to be used to clear lookup cache in all pool elements
138 static void ClearLookupCaches(const ScDocument
* pDoc
);
141 class ScThreadedInterpreterContextGetterGuard
143 ScInterpreterContextPool
& rPool
;
146 ScThreadedInterpreterContextGetterGuard(size_t nNumThreads
, const ScDocument
& rDoc
,
147 SvNumberFormatter
* pFormatter
);
148 ~ScThreadedInterpreterContextGetterGuard();
150 // Returns ScInterpreterContext* for thread index nThreadIdx
151 ScInterpreterContext
* GetInterpreterContextForThreadIdx(size_t nThreadIdx
) const;
154 class ScInterpreterContextGetterGuard
156 ScInterpreterContextPool
& rPool
;
162 ScInterpreterContextGetterGuard(const ScDocument
& rDoc
, SvNumberFormatter
* pFormatter
);
163 ~ScInterpreterContextGetterGuard();
165 // Returns ScInterpreterContext* for non-threaded use.
166 ScInterpreterContext
* GetInterpreterContext() const;
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */