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 
30 namespace 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  // Clone token if the 16-bit only reference counter is nearing it's
59  // capacity during fill or copy&paste, leaving 4k for temporary passing
60  // around. (That should be enough for all times (TM) ;-)
61  static const sal_uInt16 MAX_TOKENREF_COUNT = 0xf000;
62  static void IncrementTokenRef( const formula::FormulaToken* & rp )
63  {
64  if (rp)
65  {
66  if (rp->GetRef() >= MAX_TOKENREF_COUNT)
67  rp = rp->Clone();
68  rp->IncRef();
69  }
70  }
71 
72  union
73  {
74  double mfValue; // double result direct for performance and memory consumption
75  const formula::FormulaToken* mpToken; // if not, result token obtained from interpreter
76  };
77  bool mbToken :1; // whether content of union is a token
78  bool mbEmpty :1; // empty cell result
79  bool mbEmptyDisplayedAsString :1; // only if mbEmpty
80  // If set it implies that the result is a simple double (in mfValue) and no error
81  bool mbValueCached :1;
82  Multiline meMultiline :2; // result is multiline
83  FormulaError mnError; // error code
84 
87  void ResetToDefaults();
88 
100  void ResolveToken( const formula::FormulaToken * p );
101 
102 public:
104  ScFormulaResult();
105 
106  ScFormulaResult( const ScFormulaResult & r );
107 
109  explicit ScFormulaResult( const formula::FormulaToken* p );
110 
112 
115 
117  void Assign( const ScFormulaResult & r );
118 
127  void SetToken( const formula::FormulaToken* p );
128 
131 
135 
138  formula::StackVar GetType() const;
139 
143 
146  bool IsEmptyDisplayedAsString() const;
147 
154  bool IsValue() const;
155 
156  bool IsValueNoError() const;
157 
160  bool IsMultiline() const;
161 
162  bool GetErrorOrDouble( FormulaError& rErr, double& rVal ) const;
164 
168 
170  void SetResultError( FormulaError nErr );
171 
179  void SetDouble( double f );
180 
183  double GetDouble() const;
184 
187  const svl::SharedString & GetString() const;
188 
190  ScConstMatrixRef GetMatrix() const;
191 
193  const OUString& GetHybridFormula() const;
194 
198  void SetHybridDouble( double f );
199 
203  void SetHybridString( const svl::SharedString & rStr );
204 
209 
213  void SetHybridFormula( const OUString & rFormula );
214 
215  void SetMatrix( SCCOL nCols, SCROW nRows, const ScConstMatrixRef& pMat, const formula::FormulaToken* pUL );
216 
220 
224 };
225 
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void IncrementTokenRef(const formula::FormulaToken *&rp)
void SetHybridFormula(const OUString &rFormula)
Should only be used by import filters, best in the order SetHybridDouble(), SetHybridString()/SetHybr...
::boost::intrusive_ptr< const FormulaToken > FormulaConstTokenRef
svl::SharedString maString
formula::FormulaConstTokenRef GetCellResultToken() const
Return upper left token if formula::svMatrixCell, else return GetToken().
formula::StackVar GetType() const
Return type of result, including formula::svError, formula::svEmptyCell, formula::svDouble and formul...
static const Multiline MULTILINE_UNKNOWN
void SetMatrix(SCCOL nCols, SCROW nRows, const ScConstMatrixRef &pMat, const formula::FormulaToken *pUL)
static const Multiline MULTILINE_TRUE
const OUString & GetHybridFormula() const
Return formula string if type formula::svHybridCell, else empty string.
void IncRef() const
void SetResultError(FormulaError nErr)
Set error code, don't touch token or double.
Stores the matrix result at the formula cell, additionally the range the matrix formula occupies...
Definition: token.hxx:324
void SetHybridEmptyDisplayedAsString()
Should only be used by import filters, best in the order SetHybridDouble(), SetHybridFormula(), SetHybridEmptyDisplayedAsString() must be last.
bool IsMultiline() const
Determines whether or not the result is a string containing more than one paragraph.
Store a variable formula cell result, balancing between runtime performance and memory consumption...
bool IsEmptyDisplayedAsString() const
If type is formula::svEmptyCell (including matrix upper left) and should be displayed as empty string...
unsigned char Multiline
void SetToken(const formula::FormulaToken *p)
Sets a direct double if token type is formula::svDouble, or mbEmpty if formula::svEmptyCell, else token.
bool IsValue() const
Test for cell result type formula::svDouble, including upper left if formula::svMatrixCell.
static const Multiline MULTILINE_FALSE
const formula::FormulaToken * mpToken
bool GetErrorOrDouble(FormulaError &rErr, double &rVal) const
sal_Int16 SCCOL
Definition: types.hxx:21
const svl::SharedString & GetString() const
Return string if type formula::svString or formula::svHybridCell or formula::svMatrixCell and upper l...
ScFormulaResult & operator=(const ScFormulaResult &r)
Well, guess what ...
ScConstMatrixRef GetMatrix() const
Return matrix if type formula::svMatrixCell and ScMatrix present, else NULL.
FormulaError mnError
virtual FormulaToken * Clone() const
FormulaError
ScMatrixFormulaCellToken * GetMatrixFormulaCellTokenNonConst()
Get the ScMatrixFormulaCellToken* if token is of that type, else NULL.
void Assign(const ScFormulaResult &r)
Assignment as in operator=() but without return.
sal_Int32 SCROW
Definition: types.hxx:17
bool IsValueNoError() const
Multiline meMultiline
ScFormulaResult()
Effectively type svUnknown.
void SetHybridDouble(double f)
Should only be used by import filters, best in the order SetHybridDouble(), SetHybridString(), or only SetHybridFormula() for formula string to be compiled later.
unsigned char sal_uInt8
void ResetToDefaults()
Reset mnError, mbEmpty and mbEmptyDisplayedAsString to their defaults prior to assigning other types...
::boost::intrusive_ptr< const ScMatrix > ScConstMatrixRef
Definition: types.hxx:26
formula::StackVar GetCellResultType() const
If type is formula::svMatrixCell return the type of upper left element, else GetType() ...
double GetDouble() const
Return value if type formula::svDouble or formula::svHybridCell or formula::svMatrixCell and upper le...
const ScMatrixFormulaCellToken * GetMatrixFormulaCellToken() const
Get the const ScMatrixFormulaCellToken* if token is of that type, else NULL.
formula::FormulaConstTokenRef GetToken() const
May be NULL if SetToken() did so, also if type formula::svDouble or formula::svError! ...
void ResolveToken(const formula::FormulaToken *p)
If token is of formula::svError set error code and decrement RefCount.
void SetHybridString(const svl::SharedString &rStr)
Should only be used by import filters, best in the order SetHybridDouble(), SetHybridString()/SetHybr...
bool mbEmptyDisplayedAsString
void SetDouble(double f)
Set direct double.
static const sal_uInt16 MAX_TOKENREF_COUNT
FormulaError GetResultError() const
Get error code if set or GetCellResultType() is formula::svError or svUnknown, else 0...
sc::FormulaResultValue GetResult() const
oslInterlockedCount GetRef() const