1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
)
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()
42 ScInterpreter
aInt(NULL
, mpDoc
, maAddr
, *mpCode
.get());
45 mnFormatType
= aInt
.GetRetFormatType();
46 mnFormatIndex
= aInt
.GetRetFormatIndex();
47 maResult
.SetToken(aInt
.GetResultToken().get());
50 bool ScSimpleFormulaCalculator::IsValue()
54 return maResult
.IsValue();
57 sal_uInt16
ScSimpleFormulaCalculator::GetErrCode()
61 sal_uInt16 nErr
= mpCode
->GetCodeError();
64 return maResult
.GetResultError();
67 double ScSimpleFormulaCalculator::GetValue()
71 if ((!mpCode
->GetCodeError() || mpCode
->GetCodeError() == errDoubleRef
) &&
72 !maResult
.GetResultError())
73 return maResult
.GetDouble();
78 svl::SharedString
ScSimpleFormulaCalculator::GetString()
82 if ((!mpCode
->GetCodeError() || mpCode
->GetCodeError() == errDoubleRef
) &&
83 !maResult
.GetResultError())
84 return maResult
.GetString();
86 return svl::SharedString::getEmptyString();
89 bool ScSimpleFormulaCalculator::HasColRowName()
92 return mpCode
->GetNextColRowName() != NULL
;
95 ScTokenArray
* ScSimpleFormulaCalculator::GetCode()
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */