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;
40
42 FormulaResultValue( double fValue );
45};
46
47}
48
52{
53 typedef unsigned char Multiline;
54 static const Multiline MULTILINE_UNKNOWN = 0;
55 static const Multiline MULTILINE_FALSE = 1;
56 static const Multiline MULTILINE_TRUE = 2;
57
58 union
59 {
60 double mfValue; // double result direct for performance and memory consumption
61 const formula::FormulaToken* mpToken; // if not, result token obtained from interpreter
62 };
63 bool mbToken :1; // whether content of union is a token
64 bool mbEmpty :1; // empty cell result
65 bool mbEmptyDisplayedAsString :1; // only if mbEmpty
66 // If set it implies that the result is a simple double (in mfValue) and no error
68 Multiline meMultiline :2; // result is multiline
69 FormulaError mnError; // error code
70
73 void ResetToDefaults();
74
86 void ResolveToken( const formula::FormulaToken * p );
87
88public:
91
93
95 explicit ScFormulaResult( const formula::FormulaToken* p );
96
98
101
103 void Assign( const ScFormulaResult & r );
104
113 void SetToken( const formula::FormulaToken* p );
114
117
121
125
129
132 bool IsEmptyDisplayedAsString() const;
133
140 bool IsValue() const;
141
142 bool IsValueNoError() const;
143
146 bool IsMultiline() const;
147
148 bool GetErrorOrDouble( FormulaError& rErr, double& rVal ) const;
150
154
156 void SetResultError( FormulaError nErr );
157
165 void SetDouble( double f );
166
169 double GetDouble() const;
170
173 const svl::SharedString & GetString() const;
174
177
179 OUString GetHybridFormula() const;
180
184 void SetHybridDouble( double f );
185
189 void SetHybridString( const svl::SharedString & rStr );
190
195
199 void SetHybridFormula( const OUString & rFormula );
200
201 void SetMatrix( SCCOL nCols, SCROW nRows, const ScConstMatrixRef& pMat, const formula::FormulaToken* pUL );
202
206
210};
211
212/* 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.
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