LibreOffice Module sc (master) 1
jumpmatrix.cxx
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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <jumpmatrix.hxx>
21#include <scmatrix.hxx>
22#include <osl/diagnose.h>
23
24namespace {
25// Don't bother with buffer overhead for less than y rows.
26const SCSIZE kBufferThreshold = 128;
27}
28
30 : mvJump(nColsP * nRowsP)
31 // Initialize result matrix in case of
32 // a premature end of the interpreter
33 // due to errors.
34 , pMat(new ScMatrix(nColsP, nRowsP, CreateDoubleError(FormulaError::NotAvailable)))
35 , nCols(nColsP)
36 , nRows(nRowsP)
37 , nCurCol(0)
38 , nCurRow(0)
39 , nResMatCols(nColsP)
40 , nResMatRows(nRowsP)
41 , meOp(eOp)
42 , bStarted(false)
43 , mnBufferCol(0)
44 , mnBufferRowStart(0)
45 , mnBufferEmptyCount(0)
46 , mnBufferEmptyPathCount(0)
47{
49}
50
52{
53 for (const auto & i : mvParams)
54 i->DecRef();
55}
56
57void ScJumpMatrix::GetDimensions(SCSIZE& rCols, SCSIZE& rRows) const
58{
59 rCols = nCols;
60 rRows = nRows;
61}
62
63void ScJumpMatrix::SetJump(SCSIZE nCol, SCSIZE nRow, double fBool,
64 short nStart, short nNext)
65{
66 mvJump[static_cast<sal_uInt64>(nCol) * nRows + nRow].SetJump(fBool, nStart, nNext, SHRT_MAX);
67}
68
70 SCSIZE nCol, SCSIZE nRow, double& rBool, short& rStart, short& rNext, short& rStop) const
71{
72 if (nCols == 1 && nRows == 1)
73 {
74 nCol = 0;
75 nRow = 0;
76 }
77 else if (nCols == 1 && nRow < nRows) nCol = 0;
78 else if (nRows == 1 && nCol < nCols) nRow = 0;
79 else if (nCols <= nCol || nRows <= nRow)
80 {
81 OSL_FAIL("ScJumpMatrix::GetJump: dimension error");
82 nCol = 0;
83 nRow = 0;
84 }
85 mvJump[static_cast<sal_uInt64>(nCol) * nRows + nRow].
86 GetJump(rBool, rStart, rNext, rStop);
87}
88
89void ScJumpMatrix::SetAllJumps(double fBool, short nStart, short nNext, short nStop)
90{
91 sal_uInt64 n = static_cast<sal_uInt64>(nCols) * nRows;
92 for (sal_uInt64 j = 0; j < n; ++j)
93 {
94 mvJump[j].SetJump(fBool, nStart,
95 nNext, nStop);
96 }
97}
98
100{
101 mvParams = std::move(p);
102}
103
104void ScJumpMatrix::GetPos(SCSIZE& rCol, SCSIZE& rRow) const
105{
106 rCol = nCurCol;
107 rRow = nCurRow;
108}
109
111{
112 if (!bStarted)
113 {
114 bStarted = true;
115 nCurCol = nCurRow = 0;
116 }
117 else
118 {
119 if (++nCurRow >= nResMatRows)
120 {
121 nCurRow = 0;
122 ++nCurCol;
123 }
124 }
125 GetPos(rCol, rRow);
126 return nCurCol < nResMatCols;
127}
128
130{
131 rCols = nResMatCols;
132 rRows = nResMatRows;
133}
134
136{
137 if (nNewCols <= nResMatCols && nNewRows <= nResMatRows)
138 return;
139
141 pMat = pMat->CloneAndExtend(nNewCols, nNewRows);
142 if (nResMatCols < nNewCols)
143 {
144 pMat->FillDouble(
145 CreateDoubleError(FormulaError::NotAvailable),
146 nResMatCols, 0, nNewCols - 1, nResMatRows - 1);
147 }
148 if (nResMatRows < nNewRows)
149 {
150 pMat->FillDouble(
151 CreateDoubleError(FormulaError::NotAvailable),
152 0, nResMatRows, nNewCols - 1, nNewRows - 1);
153 }
154 if (nRows == 1 && nCurCol != 0)
155 {
156 nCurCol = 0;
157 nCurRow = nResMatRows - 1;
158 }
159 nResMatCols = nNewCols;
160 nResMatRows = nNewRows;
161}
162
164{
165 // We now always have a matrix but caller logic may still want to check it.
166 return bool(pMat);
167}
168
170{
171 return mvRefList;
172}
173
175{
176 if (!mvBufferDoubles.empty() &&
177 (eType != BUFFER_DOUBLE || nC != mnBufferCol || nR != mnBufferRowStart + mvBufferDoubles.size()))
178 {
180 mvBufferDoubles.clear();
181 }
182 if (!mvBufferStrings.empty() &&
183 (eType != BUFFER_STRING || nC != mnBufferCol || nR != mnBufferRowStart + mvBufferStrings.size()))
184 {
186 mvBufferStrings.clear();
187 }
188 if (mnBufferEmptyCount &&
190 {
193 }
196 {
199 }
200}
201
203{
204 if (nResMatRows >= kBufferThreshold)
206 return pMat.get();
207}
208
209void ScJumpMatrix::PutResultDouble( double fVal, SCSIZE nC, SCSIZE nR )
210{
211 if (nResMatRows < kBufferThreshold)
212 pMat->PutDouble( fVal, nC, nR);
213 else
214 {
216 if (mvBufferDoubles.empty())
217 {
218 mnBufferCol = nC;
219 mnBufferRowStart = nR;
220 }
221 mvBufferDoubles.push_back( fVal);
222 }
223}
224
226{
227 if (nResMatRows < kBufferThreshold)
228 pMat->PutString( rStr, nC, nR);
229 else
230 {
232 if (mvBufferStrings.empty())
233 {
234 mnBufferCol = nC;
235 mnBufferRowStart = nR;
236 }
237 mvBufferStrings.push_back( rStr);
238 }
239}
240
242{
243 if (nResMatRows < kBufferThreshold)
244 pMat->PutEmpty( nC, nR);
245 else
246 {
249 {
250 mnBufferCol = nC;
251 mnBufferRowStart = nR;
252 }
254 }
255}
256
258{
259 if (nResMatRows < kBufferThreshold)
260 pMat->PutEmptyPath( nC, nR);
261 else
262 {
265 {
266 mnBufferCol = nC;
267 mnBufferRowStart = nR;
268 }
270 }
271}
272
273/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:44
void GetDimensions(SCSIZE &rCols, SCSIZE &rRows) const
Definition: jumpmatrix.cxx:57
SCSIZE nRows
Definition: jumpmatrix.hxx:64
SCSIZE nCols
Definition: jumpmatrix.hxx:63
SCSIZE mnBufferEmptyCount
Definition: jumpmatrix.hxx:80
ScMatrixRef pMat
Definition: jumpmatrix.hxx:60
SCSIZE nCurCol
Definition: jumpmatrix.hxx:65
SCSIZE mnBufferEmptyPathCount
Definition: jumpmatrix.hxx:81
void PutResultString(const svl::SharedString &rStr, SCSIZE nC, SCSIZE nR)
Definition: jumpmatrix.cxx:225
void PutResultDouble(double fVal, SCSIZE nC, SCSIZE nR)
Definition: jumpmatrix.cxx:209
ScRefList mvRefList
Definition: jumpmatrix.hxx:61
void SetNewResMat(SCSIZE nNewCols, SCSIZE nNewRows)
Definition: jumpmatrix.cxx:135
void SetJump(SCSIZE nCol, SCSIZE nRow, double fBool, short nStart, short nNext)
Definition: jumpmatrix.cxx:63
bool Next(SCSIZE &rCol, SCSIZE &rRow)
Definition: jumpmatrix.cxx:110
SCSIZE nResMatCols
Definition: jumpmatrix.hxx:67
void FlushBufferOtherThan(BufferType eType, SCSIZE nC, SCSIZE nR)
Flush different types or non-consecutive buffers.
Definition: jumpmatrix.cxx:174
ScRefList & GetRefList()
Definition: jumpmatrix.cxx:169
void GetJump(SCSIZE nCol, SCSIZE nRow, double &rBool, short &rStart, short &rNext, short &rStop) const
Definition: jumpmatrix.cxx:69
SCSIZE mnBufferCol
Definition: jumpmatrix.hxx:78
ScMatrix * GetResultMatrix()
also applies pending buffered values
Definition: jumpmatrix.cxx:202
std::vector< ScJumpMatrixEntry > mvJump
Definition: jumpmatrix.hxx:59
::std::vector< svl::SharedString > mvBufferStrings
Definition: jumpmatrix.hxx:76
SCSIZE nResMatRows
Definition: jumpmatrix.hxx:68
void SetJumpParameters(ScTokenVec &&p)
Definition: jumpmatrix.cxx:99
void GetPos(SCSIZE &rCol, SCSIZE &rRow) const
Definition: jumpmatrix.cxx:104
::std::vector< double > mvBufferDoubles
Definition: jumpmatrix.hxx:77
ScTokenVec mvParams
Definition: jumpmatrix.hxx:62
bool HasResultMatrix() const
Definition: jumpmatrix.cxx:163
void SetAllJumps(double fBool, short nStart, short nNext, short nStop=SHRT_MAX)
Definition: jumpmatrix.cxx:89
void PutResultEmptyPath(SCSIZE nC, SCSIZE nR)
Definition: jumpmatrix.cxx:257
SCSIZE nCurRow
Definition: jumpmatrix.hxx:66
ScJumpMatrix(const ScJumpMatrix &)=delete
void GetResMatDimensions(SCSIZE &rCols, SCSIZE &rRows)
Definition: jumpmatrix.cxx:129
void PutResultEmpty(SCSIZE nC, SCSIZE nR)
Definition: jumpmatrix.cxx:241
SCSIZE mnBufferRowStart
Definition: jumpmatrix.hxx:79
Matrix data type that can store values of mixed types.
Definition: scmatrix.hxx:101
FormulaError
double CreateDoubleError(FormulaError nErr)
DocumentType eType
void * p
sal_Int64 n
::std::vector< const formula::FormulaToken * > ScTokenVec
Definition: jumpmatrix.hxx:30
int i
OpCode
::std::vector< ScComplexRefData > ScRefList
Definition: token.hxx:37