fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / data / simpleformulacalc.cxx
blobc17313d512bd660edd6335796bd5a9a7bb4aa085
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include "simpleformulacalc.hxx"
11 #include "document.hxx"
12 #include "tokenarray.hxx"
13 #include "interpre.hxx"
14 #include "compiler.hxx"
16 ScSimpleFormulaCalculator::ScSimpleFormulaCalculator( ScDocument* pDoc, const ScAddress& rAddr,
17 const OUString& rFormula, formula::FormulaGrammar::Grammar eGram )
18 : mnFormatType(0)
19 , mnFormatIndex(0)
20 , mbCalculated(false)
21 , maAddr(rAddr)
22 , mpDoc(pDoc)
24 // compile already here
25 ScCompiler aComp(pDoc, rAddr);
26 aComp.SetGrammar(eGram);
27 mpCode.reset(aComp.CompileString(rFormula));
28 if(!mpCode->GetCodeError() && mpCode->GetLen())
29 aComp.CompileTokenArray();
32 ScSimpleFormulaCalculator::~ScSimpleFormulaCalculator()
36 void ScSimpleFormulaCalculator::Calculate()
38 if(mbCalculated)
39 return;
41 mbCalculated = true;
42 ScInterpreter aInt(NULL, mpDoc, maAddr, *mpCode.get());
43 aInt.Interpret();
45 mnFormatType = aInt.GetRetFormatType();
46 mnFormatIndex = aInt.GetRetFormatIndex();
47 maResult.SetToken(aInt.GetResultToken().get());
50 bool ScSimpleFormulaCalculator::IsValue()
52 Calculate();
54 return maResult.IsValue();
57 sal_uInt16 ScSimpleFormulaCalculator::GetErrCode()
59 Calculate();
61 sal_uInt16 nErr = mpCode->GetCodeError();
62 if (nErr)
63 return nErr;
64 return maResult.GetResultError();
67 double ScSimpleFormulaCalculator::GetValue()
69 Calculate();
71 if ((!mpCode->GetCodeError() || mpCode->GetCodeError() == errDoubleRef) &&
72 !maResult.GetResultError())
73 return maResult.GetDouble();
75 return 0.0;
78 svl::SharedString ScSimpleFormulaCalculator::GetString()
80 Calculate();
82 if ((!mpCode->GetCodeError() || mpCode->GetCodeError() == errDoubleRef) &&
83 !maResult.GetResultError())
84 return maResult.GetString();
86 return svl::SharedString::getEmptyString();
89 bool ScSimpleFormulaCalculator::HasColRowName()
91 mpCode->Reset();
92 return mpCode->GetNextColRowName() != NULL;
95 ScTokenArray* ScSimpleFormulaCalculator::GetCode()
97 return mpCode.get();
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */