LibreOffice Module sc (master) 1
formularesult.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 * 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#pragma once
21
22#include "global.hxx"
23#include "calcmacros.hxx"
24#include <svl/sharedstring.hxx>
25#include <formula/token.hxx>
26#include <formula/types.hxx>
27
29
30namespace sc {
31
33{
35
36 double mfValue;
38 bool mbMultiLine = false;
41
43 FormulaResultValue( double fValue );
44 FormulaResultValue( svl::SharedString aStr, bool bMultiLine );
46};
47
48}
49
53{
54 typedef unsigned char Multiline;
55 static const Multiline MULTILINE_UNKNOWN = 0;
56 static const Multiline MULTILINE_FALSE = 1;
57 static const Multiline MULTILINE_TRUE = 2;
58
59 union
60 {
61 double mfValue; // double result direct for performance and memory consumption
62 const formula::FormulaToken* mpToken; // if not, result token obtained from interpreter
63 };
64 bool mbToken :1; // whether content of union is a token
65 bool mbEmpty :1; // empty cell result
66 bool mbEmptyDisplayedAsString :1; // only if mbEmpty
67 // If set it implies that the result is a simple double (in mfValue) and no error
69 Multiline meMultiline :2; // result is multiline
70 FormulaError mnError; // error code
71
74 void ResetToDefaults();
75
87 void ResolveToken( const formula::FormulaToken * p );
88
89public:
92
94
96 explicit ScFormulaResult( const formula::FormulaToken* p );
97
99
102
104 void Assign( const ScFormulaResult & r );
105
114 void SetToken( const formula::FormulaToken* p );
115
118
122
126
130
133 bool IsEmptyDisplayedAsString() const;
134
141 bool IsValue() const;
142
143 bool IsValueNoError() const;
144
147 bool IsMultiline() const;
148
149 bool GetErrorOrDouble( FormulaError& rErr, double& rVal ) const;
151
155
157 void SetResultError( FormulaError nErr );
158
166 void SetDouble( double f );
167
170 double GetDouble() const;
171
174 const svl::SharedString & GetString() const;
175
178
180 OUString GetHybridFormula() const;
181
185 void SetHybridDouble( double f );
186
190 void SetHybridString( const svl::SharedString & rStr );
191
196
200 void SetHybridFormula( const OUString & rFormula );
201
202 void SetMatrix( SCCOL nCols, SCROW nRows, const ScConstMatrixRef& pMat, const formula::FormulaToken* pUL );
203
207
211};
212
213/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Store a variable formula cell result, balancing between runtime performance and memory consumption.
static const Multiline MULTILINE_TRUE
void SetDouble(double f)
Set direct double.
const ScMatrixFormulaCellToken * GetMatrixFormulaCellToken() const
Get the const ScMatrixFormulaCellToken* if token is of that type, else NULL.
void ResetToDefaults()
Reset mnError, mbEmpty and mbEmptyDisplayedAsString to their defaults prior to assigning other types.
void SetHybridDouble(double f)
Should only be used by import filters, best in the order SetHybridDouble(), SetHybridString(),...
void SetResultError(FormulaError nErr)
Set error code, don't touch token or double.
ScMatrixFormulaCellToken * GetMatrixFormulaCellTokenNonConst()
Get the ScMatrixFormulaCellToken* if token is of that type, else NULL.
Multiline meMultiline
ScFormulaResult & operator=(const ScFormulaResult &r)
Well, guess what ...
bool mbEmptyDisplayedAsString
formula::FormulaConstTokenRef GetToken() const
May be NULL if SetToken() did so, also if type formula::svDouble or formula::svError!
static const Multiline MULTILINE_FALSE
void SetToken(const formula::FormulaToken *p)
Sets a direct double if token type is formula::svDouble, or mbEmpty if formula::svEmptyCell,...
static const Multiline MULTILINE_UNKNOWN
const formula::FormulaToken * mpToken
ScFormulaResult()
Effectively type svUnknown.
unsigned char Multiline
ScConstMatrixRef GetMatrix() const
Return matrix if type formula::svMatrixCell and ScMatrix present, else NULL.
formula::FormulaConstTokenRef GetCellResultToken() const
Return upper left token if formula::svMatrixCell, else return GetToken().
double GetDouble() const
Return value if type formula::svDouble or formula::svHybridCell or formula::svMatrixCell and upper le...
bool IsEmptyDisplayedAsString() const
If type is formula::svEmptyCell (including matrix upper left) and should be displayed as empty string...
void SetHybridEmptyDisplayedAsString()
Should only be used by import filters, best in the order SetHybridDouble(), SetHybridFormula(),...
bool GetErrorOrDouble(FormulaError &rErr, double &rVal) const
void SetHybridString(const svl::SharedString &rStr)
Should only be used by import filters, best in the order SetHybridDouble(), SetHybridString()/SetHybr...
void ResolveToken(const formula::FormulaToken *p)
If token is of formula::svError set error code and decrement RefCount.
const svl::SharedString & GetString() const
Return string if type formula::svString or formula::svHybridCell or formula::svMatrixCell and upper l...
bool IsValueNoError() const
formula::StackVar GetType() const
Return type of result, including formula::svError, formula::svEmptyCell, formula::svDouble and formul...
void SetHybridFormula(const OUString &rFormula)
Should only be used by import filters, best in the order SetHybridDouble(), SetHybridString()/SetHybr...
bool IsMultiline() const
Determines whether or not the result is a string containing more than one paragraph.
void SetMatrix(SCCOL nCols, SCROW nRows, const ScConstMatrixRef &pMat, const formula::FormulaToken *pUL)
bool IsValue() const
Test for cell result type formula::svDouble, including upper left if formula::svMatrixCell.
OUString GetHybridFormula() const
Return formula string if type formula::svHybridCell, else empty string.
void Assign(const ScFormulaResult &r)
Assignment as in operator=() but without return.
formula::StackVar GetCellResultType() const
If type is formula::svMatrixCell return the type of upper left element, else GetType()
FormulaError mnError
sc::FormulaResultValue GetResult() const
FormulaError GetResultError() const
Get error code if set or GetCellResultType() is formula::svError or svUnknown, else 0.
Stores the matrix result at the formula cell, additionally the range the matrix formula occupies.
Definition: token.hxx:325
FormulaError
::boost::intrusive_ptr< const FormulaToken > FormulaConstTokenRef
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
svl::SharedString maString
unsigned char sal_uInt8
::boost::intrusive_ptr< const ScMatrix > ScConstMatrixRef
Definition: types.hxx:26
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17