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 #ifndef INCLUDED_SC_INC_FORMULARESULT_HXX
21 #define INCLUDED_SC_INC_FORMULARESULT_HXX
22 
23 #include "global.hxx"
24 #include "calcmacros.hxx"
25 #include <svl/sharedstring.hxx>
26 #include <formula/token.hxx>
27 #include <formula/types.hxx>
28 
30 
31 namespace sc {
32 
34 {
36 
37  double mfValue;
41 
43  FormulaResultValue( double fValue );
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  // Clone token if the 16-bit only reference counter is nearing it's
60  // capacity during fill or copy&paste, leaving 4k for temporary passing
61  // around. (That should be enough for all times (TM) ;-)
62  static const sal_uInt16 MAX_TOKENREF_COUNT = 0xf000;
63  static void IncrementTokenRef( const formula::FormulaToken* & rp )
64  {
65  if (rp)
66  {
67  if (rp->GetRef() >= MAX_TOKENREF_COUNT)
68  rp = rp->Clone();
69  rp->IncRef();
70  }
71  }
72 
73  union
74  {
75  double mfValue; // double result direct for performance and memory consumption
76  const formula::FormulaToken* mpToken; // if not, result token obtained from interpreter
77  };
78  bool mbToken :1; // whether content of union is a token
79  bool mbEmpty :1; // empty cell result
80  bool mbEmptyDisplayedAsString :1; // only if mbEmpty
81  // If set it implies that the result is a simple double (in mfValue) and no error
82  bool mbValueCached :1;
83  Multiline meMultiline :2; // result is multiline
84  FormulaError mnError; // error code
85 
88  void ResetToDefaults();
89 
101  void ResolveToken( const formula::FormulaToken * p );
102 
103 public:
105  ScFormulaResult();
106 
107  ScFormulaResult( const ScFormulaResult & r );
108 
110  explicit ScFormulaResult( const formula::FormulaToken* p );
111 
113 
116 
118  void Assign( const ScFormulaResult & r );
119 
128  void SetToken( const formula::FormulaToken* p );
129 
132 
136 
139  formula::StackVar GetType() const;
140 
144 
147  bool IsEmptyDisplayedAsString() const;
148 
155  bool IsValue() const;
156 
157  bool IsValueNoError() const;
158 
161  bool IsMultiline() const;
162 
163  bool GetErrorOrDouble( FormulaError& rErr, double& rVal ) const;
165 
169 
171  void SetResultError( FormulaError nErr );
172 
180  void SetDouble( double f );
181 
184  double GetDouble() const;
185 
189 
191  ScConstMatrixRef GetMatrix() const;
192 
194  const OUString& GetHybridFormula() const;
195 
199  void SetHybridDouble( double f );
200 
204  void SetHybridString( const svl::SharedString & rStr );
205 
210 
214  void SetHybridFormula( const OUString & rFormula );
215 
216  void SetMatrix( SCCOL nCols, SCROW nRows, const ScConstMatrixRef& pMat, const formula::FormulaToken* pUL );
217 
221 
225 };
226 
227 #endif // INCLUDED_SC_INC_FORMULARESULT_HXX
228 
229 /* 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
svl::SharedString GetString() const
Return string if type formula::svString or formula::svHybridCell or formula::svMatrixCell and upper l...
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:325
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:22
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:18
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:27
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