Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / inc / interpre.hxx
blobcc675808a50e6379551ef674b3a2124a52db29c5
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef SC_INTERPRE_HXX
21 #define SC_INTERPRE_HXX
23 #include <math.h>
24 #include <rtl/math.hxx>
25 #include <rtl/ustring.hxx>
26 #include <tools/string.hxx>
27 #include "formula/errorcodes.hxx"
28 #include "formula/tokenarray.hxx"
29 #include "scdll.hxx"
30 #include "types.hxx"
31 #include "externalrefmgr.hxx"
32 #include "calcconfig.hxx"
33 #include "token.hxx"
35 #include <map>
37 class ScDocument;
38 class SbxVariable;
39 class ScFormulaCell;
40 class SvNumberFormatter;
41 class ScDBRangeBase;
42 struct ScQueryParam;
43 struct ScDBQueryParamBase;
44 struct ScQueryEntry;
46 struct ScSingleRefData;
47 struct ScComplexRefData;
49 class ScToken;
50 class ScJumpMatrix;
51 struct ScRefCellValue;
53 namespace sc {
55 struct RangeMatrix;
56 struct Compare;
57 struct CompareOptions;
61 namespace svl {
63 class SharedStringPool;
67 #define MAXSTACK (4096 / sizeof(formula::FormulaToken*))
69 class ScTokenStack
71 public:
72 DECL_FIXEDMEMPOOL_NEWDEL( ScTokenStack )
73 formula::FormulaToken* pPointer[ MAXSTACK ];
76 enum ScIterFunc {
77 ifSUM, // Add up
78 ifSUMSQ, // Sums of squares
79 ifPRODUCT, // Product
80 ifAVERAGE, // Average
81 ifCOUNT, // Count Values
82 ifCOUNT2, // Count Values (not empty)
83 ifMIN, // Minimum
84 ifMAX // Maximum
87 enum ScIterFuncIf
89 ifSUMIF, // Conditional sum
90 ifAVERAGEIF // Conditional average
93 enum ScIterFuncIfs
95 ifSUMIFS, // Multi-Conditional sum
96 ifAVERAGEIFS, // Multi-Conditional average
97 ifCOUNTIFS // Multi-Conditional count
100 struct FormulaTokenRef_less
102 bool operator () ( const formula::FormulaConstTokenRef& r1, const formula::FormulaConstTokenRef& r2 ) const
103 { return r1.get() < r2.get(); }
105 typedef ::std::map< const formula::FormulaConstTokenRef, formula::FormulaTokenRef, FormulaTokenRef_less> ScTokenMatrixMap;
107 class ScInterpreter
109 // distibution function objects need the GetxxxDist methods
110 friend class ScGammaDistFunction;
111 friend class ScBetaDistFunction;
112 friend class ScTDistFunction;
113 friend class ScFDistFunction;
114 friend class ScChiDistFunction;
115 friend class ScChiSqDistFunction;
117 public:
118 DECL_FIXEDMEMPOOL_NEWDEL( ScInterpreter )
120 static void SetGlobalConfig(const ScCalcConfig& rConfig);
121 static const ScCalcConfig& GetGlobalConfig();
123 static void GlobalExit(); // called by ScGlobal::Clear()
125 /// Could string be a regular expression?
126 /// If pDoc!=NULL the document options are taken into account and if
127 /// RegularExpressions are disabled the function returns false regardless
128 /// of the string content.
129 static bool MayBeRegExp( const OUString& rStr, const ScDocument* pDoc );
131 /// Fail safe division, returning an errDivisionByZero coded into a double
132 /// if denominator is 0.0
133 static inline double div( const double& fNumerator, const double& fDenominator );
135 ScMatrixRef GetNewMat(SCSIZE nC, SCSIZE nR, bool bEmpty = false);
137 enum VolatileType {
138 VOLATILE,
139 VOLATILE_MACRO,
140 NOT_VOLATILE
143 VolatileType GetVolatileType() const;
145 private:
146 static ScCalcConfig maGlobalConfig;
148 static ScTokenStack* pGlobalStack;
149 static bool bGlobalStackInUse;
151 formula::FormulaTokenIterator aCode;
152 ScAddress aPos;
153 ScTokenArray& rArr;
154 ScDocument* pDok;
155 svl::SharedStringPool& mrStrPool;
156 formula::FormulaTokenRef xResult;
157 ScJumpMatrix* pJumpMatrix; // currently active array condition, if any
158 ScTokenMatrixMap* pTokenMatrixMap; // map ScToken* to formula::FormulaTokenRef if in array condition
159 ScFormulaCell* pMyFormulaCell; // the cell of this formula expression
160 SvNumberFormatter* pFormatter;
162 const formula::FormulaToken*
163 pCur; // current token
164 ScTokenStack* pStackObj; // contains the stacks
165 formula::FormulaToken** pStack; // the current stack
166 sal_uInt16 nGlobalError; // global (local to this formula expression) error
167 sal_uInt16 sp; // stack pointer
168 sal_uInt16 maxsp; // the maximal used stack pointer
169 sal_uLong nFuncFmtIndex; // NumberFormatIndex of a function
170 sal_uLong nCurFmtIndex; // current NumberFormatIndex
171 sal_uLong nRetFmtIndex; // NumberFormatIndex of an expression, if any
172 short nFuncFmtType; // NumberFormatType of a function
173 short nCurFmtType; // current NumberFormatType
174 short nRetFmtType; // NumberFormatType of an expression
175 sal_uInt16 mnStringNoValueError; // the error set in ConvertStringToValue() if no value
176 bool glSubTotal; // flag for subtotal functions
177 sal_uInt8 cPar; // current count of parameters
178 bool bCalcAsShown; // precision as shown
179 bool bMatrixFormula; // formula cell is a matrix formula
181 VolatileType meVolatileType;
183 // nMust <= nAct <= nMax ? ok : PushError
184 inline bool MustHaveParamCount( short nAct, short nMust );
185 inline bool MustHaveParamCount( short nAct, short nMust, short nMax );
186 inline bool MustHaveParamCountMin( short nAct, short nMin );
187 void PushParameterExpected();
188 void PushIllegalParameter();
189 void PushIllegalArgument();
190 void PushNoValue();
191 void PushNA();
193 // Functions for accessing a document
195 void ReplaceCell( ScAddress& ); // for TableOp
196 void ReplaceCell( SCCOL& rCol, SCROW& rRow, SCTAB& rTab ); // for TableOp
197 bool IsTableOpInRange( const ScRange& );
198 sal_uLong GetCellNumberFormat( const ScAddress& rPos, ScRefCellValue& rCell );
199 double ConvertStringToValue( const OUString& );
200 double GetCellValue( const ScAddress&, ScRefCellValue& rCell );
201 double GetCellValueOrZero( const ScAddress&, ScRefCellValue& rCell );
202 double GetValueCellValue( const ScAddress&, double fOrig );
203 void GetCellString( svl::SharedString& rStr, ScRefCellValue& rCell );
204 sal_uInt16 GetCellErrCode( const ScRefCellValue& rCell );
206 bool CreateDoubleArr(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
207 SCCOL nCol2, SCROW nRow2, SCTAB nTab2, sal_uInt8* pCellArr);
208 bool CreateStringArr(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
209 SCCOL nCol2, SCROW nRow2, SCTAB nTab2, sal_uInt8* pCellArr);
210 bool CreateCellArr(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
211 SCCOL nCol2, SCROW nRow2, SCTAB nTab2, sal_uInt8* pCellArr);
213 // Stack operations
215 /** Does substitute with formula::FormulaErrorToken in case nGlobalError is set and the token
216 passed is not formula::FormulaErrorToken.
217 Increments RefCount of the original token if not substituted. */
218 void Push( formula::FormulaToken& r );
220 /** Does not substitute with formula::FormulaErrorToken in case nGlobalError is set.
221 Used to push RPN tokens or from within Push() or tokens that are already
222 explicit formula::FormulaErrorToken. Increments RefCount. */
223 void PushWithoutError( formula::FormulaToken& r );
225 /** Clones the token to be pushed or substitutes with formula::FormulaErrorToken if
226 nGlobalError is set and the token passed is not formula::FormulaErrorToken. */
227 void PushTempToken( const formula::FormulaToken& );
229 /** Does substitute with formula::FormulaErrorToken in case nGlobalError is set and the token
230 passed is not formula::FormulaErrorToken.
231 Increments RefCount of the original token if not substituted.
232 ATTENTION! The token had to be allocated with `new' and must not be used
233 after this call if no RefCount was set because possibly it gets immediately
234 deleted in case of an errStackOverflow or if substituted with formula::FormulaErrorToken! */
235 void PushTempToken( formula::FormulaToken* );
237 /** Does not substitute with formula::FormulaErrorToken in case nGlobalError is set.
238 Used to push tokens from within PushTempToken() or tokens that are already
239 explicit formula::FormulaErrorToken. Increments RefCount.
240 ATTENTION! The token had to be allocated with `new' and must not be used
241 after this call if no RefCount was set because possibly it gets immediately
242 decremented again and thus deleted in case of an errStackOverflow! */
243 void PushTempTokenWithoutError( formula::FormulaToken* );
245 /** If nGlobalError is set push formula::FormulaErrorToken.
246 If nGlobalError is not set do nothing.
247 Used in PushTempToken() and alike to simplify handling.
248 @return: <TRUE/> if nGlobalError. */
249 inline bool IfErrorPushError()
251 if (nGlobalError)
253 PushTempTokenWithoutError( new formula::FormulaErrorToken( nGlobalError));
254 return true;
256 return false;
259 /** Obtain cell result / content from address and push as temp token.
260 bDisplayEmptyAsString is passed to ScEmptyCell in case of an empty cell
261 result. Also obtain number format and type if _both_, type and index
262 pointer, are not NULL. */
263 void PushCellResultToken( bool bDisplayEmptyAsString, const ScAddress & rAddress,
264 short * pRetTypeExpr, sal_uLong * pRetIndexExpr );
266 formula::FormulaTokenRef PopToken();
267 void Pop();
268 void PopError();
269 double PopDouble();
270 svl::SharedString PopString();
271 void ValidateRef( const ScSingleRefData & rRef );
272 void ValidateRef( const ScComplexRefData & rRef );
273 void ValidateRef( const ScRefList & rRefList );
274 void SingleRefToVars( const ScSingleRefData & rRef, SCCOL & rCol, SCROW & rRow, SCTAB & rTab );
275 void PopSingleRef( ScAddress& );
276 void PopSingleRef(SCCOL& rCol, SCROW &rRow, SCTAB& rTab);
277 void DoubleRefToRange( const ScComplexRefData&, ScRange&, bool bDontCheckForTableOp = false );
278 /** If formula::StackVar formula::svDoubleRef pop ScDoubleRefToken and return values of
279 ScComplexRefData.
280 Else if StackVar svRefList return values of the ScComplexRefData where
281 rRefInList is pointing to. rRefInList is incremented. If rRefInList was the
282 last element in list pop ScRefListToken and set rRefInList to 0, else
283 rParam is incremented (!) to allow usage as in
284 while(nParamCount--) PopDoubleRef(aRange,nParamCount,nRefInList);
286 void PopDoubleRef( ScRange & rRange, short & rParam, size_t & rRefInList );
287 void PopDoubleRef( ScRange&, bool bDontCheckForTableOp = false );
288 void DoubleRefToVars( const ScToken* p,
289 SCCOL& rCol1, SCROW &rRow1, SCTAB& rTab1,
290 SCCOL& rCol2, SCROW &rRow2, SCTAB& rTab2,
291 bool bDontCheckForTableOp = false );
292 ScDBRangeBase* PopDBDoubleRef();
293 void PopDoubleRef(SCCOL& rCol1, SCROW &rRow1, SCTAB& rTab1,
294 SCCOL& rCol2, SCROW &rRow2, SCTAB& rTab2,
295 bool bDontCheckForTableOp = false );
296 void PopExternalSingleRef(sal_uInt16& rFileId, OUString& rTabName, ScSingleRefData& rRef);
297 void PopExternalSingleRef(ScExternalRefCache::TokenRef& rToken, ScExternalRefCache::CellFormat* pFmt = NULL);
298 void PopExternalSingleRef(sal_uInt16& rFileId, OUString& rTabName, ScSingleRefData& rRef,
299 ScExternalRefCache::TokenRef& rToken, ScExternalRefCache::CellFormat* pFmt = NULL);
300 void PopExternalDoubleRef(sal_uInt16& rFileId, OUString& rTabName, ScComplexRefData& rRef);
301 void PopExternalDoubleRef(ScExternalRefCache::TokenArrayRef& rArray);
302 void PopExternalDoubleRef(ScMatrixRef& rMat);
303 void GetExternalDoubleRef(sal_uInt16 nFileId, const OUString& rTabName, const ScComplexRefData& aData, ScExternalRefCache::TokenArrayRef& rArray);
304 bool PopDoubleRefOrSingleRef( ScAddress& rAdr );
305 void PopDoubleRefPushMatrix();
306 // If MatrixFormula: convert formula::svDoubleRef to svMatrix, create JumpMatrix.
307 // Else convert area reference parameters marked as ForceArray to array.
308 // Returns true if JumpMatrix created.
309 bool ConvertMatrixParameters();
310 inline void MatrixDoubleRefToMatrix(); // if MatrixFormula: PopDoubleRefPushMatrix
311 // If MatrixFormula or ForceArray: ConvertMatrixParameters()
312 inline bool MatrixParameterConversion();
313 ScMatrixRef PopMatrix();
314 sc::RangeMatrix PopRangeMatrix();
315 void QueryMatrixType(ScMatrixRef& xMat, short& rRetTypeExpr, sal_uLong& rRetIndexExpr);
317 void PushDouble(double nVal);
318 void PushInt( int nVal );
319 void PushStringBuffer( const sal_Unicode* pString );
320 void PushString( const OUString& rStr );
321 void PushString( const svl::SharedString& rString );
322 void PushSingleRef(SCCOL nCol, SCROW nRow, SCTAB nTab);
323 void PushDoubleRef(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
324 SCCOL nCol2, SCROW nRow2, SCTAB nTab2);
325 void PushExternalSingleRef(sal_uInt16 nFileId, const OUString& rTabName,
326 SCCOL nCol, SCROW nRow, SCTAB nTab);
327 void PushExternalDoubleRef(sal_uInt16 nFileId, const OUString& rTabName,
328 SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
329 SCCOL nCol2, SCROW nRow2, SCTAB nTab2);
330 void PushMatrix( const sc::RangeMatrix& rMat );
331 void PushMatrix(const ScMatrixRef& pMat);
332 void PushError( sal_uInt16 nError );
333 /// Raw stack type without default replacements.
334 formula::StackVar GetRawStackType();
335 /// Stack type with replacement of defaults, e.g. svMissing and formula::svEmptyCell will result in formula::svDouble.
336 formula::StackVar GetStackType();
337 // peek StackType of Parameter, Parameter 1 == TOS, 2 == TOS-1, ...
338 formula::StackVar GetStackType( sal_uInt8 nParam );
339 sal_uInt8 GetByte() { return cPar; }
340 // generates a position-dependent SingleRef out of a DoubleRef
341 bool DoubleRefToPosSingleRef( const ScRange& rRange, ScAddress& rAdr );
342 double GetDoubleFromMatrix(const ScMatrixRef& pMat);
343 double GetDouble();
344 double GetDoubleWithDefault(double nDefault);
345 bool IsMissing();
346 bool GetBool() { return GetDouble() != 0.0; }
347 svl::SharedString GetString();
348 svl::SharedString GetStringFromMatrix(const ScMatrixRef& pMat);
349 // pop matrix and obtain one element, upper left or according to jump matrix
350 ScMatValType GetDoubleOrStringFromMatrix( double& rDouble, svl::SharedString& rString );
351 ScMatrixRef CreateMatrixFromDoubleRef( const formula::FormulaToken* pToken,
352 SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
353 SCCOL nCol2, SCROW nRow2, SCTAB nTab2 );
354 inline ScTokenMatrixMap& GetTokenMatrixMap();
355 ScTokenMatrixMap* CreateTokenMatrixMap();
356 ScMatrixRef GetMatrix();
357 sc::RangeMatrix GetRangeMatrix();
359 void ScTableOp(); // repeated operations
360 void ScErrCell(); // special handling for
361 // error cell
363 // common helper functions
365 void SetMaxIterationCount(sal_uInt16 n);
366 inline void CurFmtToFuncFmt()
367 { nFuncFmtType = nCurFmtType; nFuncFmtIndex = nCurFmtIndex; }
368 // Check for String overflow of rResult+rAdd and set error and erase rResult
369 // if so. Return true if ok, false if overflow
370 inline bool CheckStringResultLen( OUString& rResult, const OUString& rAdd );
371 // Set error according to rVal, and set rVal to 0.0 if there was an error.
372 inline void TreatDoubleError( double& rVal );
373 // Lookup using ScLookupCache, @returns true if found and result address
374 bool LookupQueryWithCache( ScAddress & o_rResultPos,
375 const ScQueryParam & rParam ) const;
377 void ScIfJump();
378 void ScIfError( bool bNAonly );
379 void ScChoseJump();
381 // Be sure to only call this if pStack[sp-nStackLevel] really contains a
382 // ScJumpMatrixToken, no further checks are applied!
383 // Returns true if last jump was executed and result matrix pushed.
384 bool JumpMatrix( short nStackLevel );
386 double Compare();
387 /** @param pOptions
388 NULL means case sensitivity document option is to be used!
390 sc::RangeMatrix CompareMat( ScQueryOp eOp, sc::CompareOptions* pOptions = NULL );
391 ScMatrixRef QueryMat( const ScMatrixRef& pMat, sc::CompareOptions& rOptions );
392 void ScEqual();
393 void ScNotEqual();
394 void ScLess();
395 void ScGreater();
396 void ScLessEqual();
397 void ScGreaterEqual();
398 void ScAnd();
399 void ScOr();
400 void ScXor();
401 void ScNot();
402 void ScNeg();
403 void ScPercentSign();
404 void ScIntersect();
405 void ScRangeFunc();
406 void ScUnionFunc();
407 void ScPi();
408 void ScRandom();
409 void ScTrue();
410 void ScFalse();
411 void ScDeg();
412 void ScRad();
413 void ScSin();
414 void ScCos();
415 void ScTan();
416 void ScCot();
417 void ScArcSin();
418 void ScArcCos();
419 void ScArcTan();
420 void ScArcCot();
421 void ScSinHyp();
422 void ScCosHyp();
423 void ScTanHyp();
424 void ScCotHyp();
425 void ScArcSinHyp();
426 void ScArcCosHyp();
427 void ScArcTanHyp();
428 void ScArcCotHyp();
429 void ScCosecant();
430 void ScSecant();
431 void ScCosecantHyp();
432 void ScSecantHyp();
433 void ScExp();
434 void ScLn();
435 void ScLog10();
436 void ScSqrt();
437 void ScIsEmpty();
438 short IsString();
439 void ScIsString();
440 void ScIsNonString();
441 void ScIsLogical();
442 void ScType();
443 void ScCell();
444 void ScCellExternal();
445 void ScIsRef();
446 void ScIsValue();
447 void ScIsFormula();
448 void ScFormula();
449 void ScRoman();
450 void ScArabic();
451 void ScIsNV();
452 void ScIsErr();
453 void ScIsError();
454 short IsEven();
455 void ScIsEven();
456 void ScIsOdd();
457 void ScN();
458 void ScCode();
459 void ScTrim();
460 void ScUpper();
461 void ScPropper();
462 void ScLower();
463 void ScLen();
464 void ScT();
465 void ScValue();
466 void ScNumberValue();
467 void ScClean();
468 void ScChar();
469 void ScJis();
470 void ScAsc();
471 void ScUnicode();
472 void ScUnichar();
473 void ScMin( bool bTextAsZero = false );
474 void ScMax( bool bTextAsZero = false );
475 double IterateParameters( ScIterFunc, bool bTextAsZero = false );
476 void ScSumSQ();
477 void ScSum();
478 void ScProduct();
479 void ScAverage( bool bTextAsZero = false );
480 void ScCount();
481 void ScCount2();
482 void GetStVarParams( double& rVal, double& rValCount, bool bTextAsZero = false );
483 void ScVar( bool bTextAsZero = false );
484 void ScVarP( bool bTextAsZero = false );
485 void ScStDev( bool bTextAsZero = false );
486 void ScStDevP( bool bTextAsZero = false );
487 void ScColumns();
488 void ScRows();
489 void ScTables();
490 void ScColumn();
491 void ScRow();
492 void ScTable();
493 void ScMatch();
494 double IterateParametersIf( ScIterFuncIf );
495 void ScCountIf();
496 void ScSumIf();
497 void ScAverageIf();
498 double IterateParametersIfs( ScIterFuncIfs );
499 void ScSumIfs();
500 void ScAverageIfs();
501 void ScCountIfs();
502 void ScCountEmptyCells();
503 void ScLookup();
504 void ScHLookup();
505 void ScVLookup();
506 void ScSubTotal();
508 // If upon call rMissingField==true then the database field parameter may be
509 // missing (Xcl DCOUNT() syntax), or may be faked as missing by having the
510 // value 0.0 or being exactly the entire database range reference (old SO
511 // compatibility). If this was the case then rMissingField is set to true upon
512 // return. If rMissingField==false upon call all "missing cases" are considered
513 // to be an error.
514 ScDBQueryParamBase* GetDBParams( bool& rMissingField );
516 void DBIterator( ScIterFunc );
517 void ScDBSum();
518 void ScDBCount();
519 void ScDBCount2();
520 void ScDBAverage();
521 void ScDBGet();
522 void ScDBMax();
523 void ScDBMin();
524 void ScDBProduct();
525 void GetDBStVarParams( double& rVal, double& rValCount );
526 void ScDBStdDev();
527 void ScDBStdDevP();
528 void ScDBVar();
529 void ScDBVarP();
530 void ScIndirect();
531 void ScAddressFunc();
532 void ScOffset();
533 void ScIndex();
534 void ScMultiArea();
535 void ScAreas();
536 void ScCurrency();
537 void ScReplace();
538 void ScFixed();
539 void ScFind();
540 void ScExact();
541 void ScLeft();
542 void ScRight();
543 void ScSearch();
544 void ScMid();
545 void ScText();
546 void ScSubstitute();
547 void ScRept();
548 void ScConcat();
549 void ScExternal();
550 void ScMissing();
551 void ScMacro();
552 bool SetSbxVariable( SbxVariable* pVar, const ScAddress& );
553 bool SetSbxVariable( SbxVariable* pVar, SCCOL nCol, SCROW nRow, SCTAB nTab );
554 void ScErrorType();
555 void ScDBArea();
556 void ScColRowNameAuto();
557 void ScGetPivotData();
558 void ScHyperLink();
559 void ScBahtText();
560 void ScBitAnd();
561 void ScBitOr();
562 void ScBitXor();
563 void ScBitRshift();
564 void ScBitLshift();
565 void ScTTT();
566 void ScDebugVar();
568 /** Obtain the date serial number for a given date.
569 @param bStrict
570 If false, nYear < 100 takes the two-digit year setting into account,
571 and rollover of invalid calendar dates takes place, e.g. 1999-02-31 =>
572 1999-03-03.
573 If true, the date passed must be a valid Gregorian calendar date. No
574 two-digit expanding or rollover is done.
576 @param bCheckGregorian
577 If true, date must be Gregorian, i.e. >= 1582-10-15.
578 If false, don't care, any valid date >= 0-1-1 will do.
580 double GetDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, bool bStrict, bool bCheckGregorian );
582 void ScGetActDate();
583 void ScGetActTime();
584 void ScGetYear();
585 void ScGetMonth();
586 void ScGetDay();
587 void ScGetDayOfWeek();
588 void ScGetWeekOfYear();
589 void ScEasterSunday();
590 void ScGetHour();
591 void ScGetMin();
592 void ScGetSec();
593 void ScPlusMinus();
594 void ScAbs();
595 void ScInt();
596 void ScEven();
597 void ScOdd();
598 void ScCeil();
599 void ScFloor();
600 void RoundNumber( rtl_math_RoundingMode eMode );
601 void ScRound();
602 void ScRoundUp();
603 void ScRoundDown();
604 void ScGetDateValue();
605 void ScGetTimeValue();
606 void ScArcTan2();
607 void ScLog();
608 void ScGetDate();
609 void ScGetTime();
610 void ScGetDiffDate();
611 void ScGetDiffDate360();
612 void ScGetDateDif();
613 void ScPower();
614 void ScAmpersand();
615 void ScAdd();
616 void ScSub();
617 void ScMul();
618 void ScDiv();
619 void ScPow();
620 void ScCurrent();
621 void ScStyle();
622 void ScDde();
623 void ScBase();
624 void ScDecimal();
625 void ScConvert();
626 void ScEuroConvert();
628 // financial functions
629 void ScNPV();
630 void ScIRR();
631 void ScMIRR();
632 void ScISPMT();
634 double ScGetBw(double fZins, double fZzr, double fRmz,
635 double fZw, double fF);
636 void ScBW();
637 void ScDIA();
638 double ScGetGDA(double fWert, double fRest, double fDauer,
639 double fPeriode, double fFactor);
640 void ScGDA();
641 void ScGDA2();
642 double ScInterVDB(double fWert,double fRest,double fDauer,double fDauer1,
643 double fPeriode,double fFactor);
644 void ScVDB();
645 void ScLaufz();
646 void ScLIA();
647 double ScGetRmz(double fZins, double fZzr, double fBw,
648 double fZw, double fF);
649 void ScRMZ();
650 void ScZGZ();
651 double ScGetZw(double fZins, double fZzr, double fRmz,
652 double fBw, double fF);
653 void ScZW();
654 void ScZZR();
655 bool RateIteration(double fNper, double fPayment, double fPv,
656 double fFv, double fPayType, double& fGuess);
657 void ScZins();
658 double ScGetZinsZ(double fZins, double fZr, double fZzr, double fBw,
659 double fZw, double fF, double& fRmz);
660 void ScZinsZ();
661 void ScKapz();
662 void ScKumZinsZ();
663 void ScKumKapZ();
664 void ScEffektiv();
665 void ScNominal();
666 void ScMod();
667 void ScIntercept();
668 double ScGetGCD(double fx, double fy);
669 void ScGCD();
670 void ScLCM();
672 // matrix functions
673 void ScMatValue();
674 void MEMat(const ScMatrixRef& mM, SCSIZE n);
675 void ScMatDet();
676 void ScMatInv();
677 void ScMatMult();
678 void ScMatTrans();
679 void ScEMat();
680 void ScMatRef();
681 ScMatrixRef MatConcat(const ScMatrixRef& pMat1, const ScMatrixRef& pMat2);
682 void ScSumProduct();
683 void ScSumX2MY2();
684 void ScSumX2DY2();
685 void ScSumXMY2();
686 void ScGrowth();
687 bool CalculateSkew(double& fSum,double& fCount,double& vSum,std::vector<double>& values);
688 void CalculateSkewOrSkewp( bool bSkewp );
689 void CalculateSlopeIntercept(bool bSlope);
690 void CalculateSmallLarge(bool bSmall);
691 void CalculatePearsonCovar( bool _bPearson, bool _bStexy, bool _bSample ); //fdo#70000 argument _bSample is ignored if _bPearson == true
692 bool CalculateTest( bool _bTemplin
693 ,const SCSIZE nC1, const SCSIZE nC2,const SCSIZE nR1,const SCSIZE nR2
694 ,const ScMatrixRef& pMat1,const ScMatrixRef& pMat2
695 ,double& fT,double& fF);
696 void CalculateLookup(bool bHLookup);
697 bool FillEntry(ScQueryEntry& rEntry);
698 void CalculateAddSub(bool _bSub);
699 void CalculateTrendGrowth(bool _bGrowth);
700 void CalulateRGPRKP(bool _bRKP);
701 void CalculateSumX2MY2SumX2DY2(bool _bSumX2DY2);
702 void CalculateMatrixValue(const ScMatrix* pMat,SCSIZE nC,SCSIZE nR);
703 bool CheckMatrix(bool _bLOG,sal_uInt8& nCase,SCSIZE& nCX,SCSIZE& nCY,SCSIZE& nRX,SCSIZE& nRY,SCSIZE& M,SCSIZE& N,ScMatrixRef& pMatX,ScMatrixRef& pMatY);
704 void ScRGP();
705 void ScRKP();
706 void ScForecast();
707 void ScNoName();
708 void ScBadName();
709 // Statistics:
710 double phi(double x);
711 double integralPhi(double x);
712 double taylor(double* pPolynom, sal_uInt16 nMax, double x);
713 double gauss(double x);
714 double gaussinv(double x);
715 double GetBetaDist(double x, double alpha, double beta); //cumulative distribution function
716 double GetBetaDistPDF(double fX, double fA, double fB); //probability density function)
717 double GetChiDist(double fChi, double fDF); // for LEGACY.CHIDIST, returns right tail
718 double GetChiSqDistCDF(double fX, double fDF); // for CHISQDIST, returns left tail
719 double GetChiSqDistPDF(double fX, double fDF); // probability density function
720 double GetFDist(double x, double fF1, double fF2);
721 double GetTDist(double T, double fDF);
722 double Fakultaet(double x);
723 double BinomKoeff(double n, double k);
724 double GetGamma(double x);
725 double GetLogGamma(double x);
726 double GetBeta(double fAlpha, double fBeta);
727 double GetLogBeta(double fAlpha, double fBeta);
728 double GetBinomDistPMF(double x, double n, double p); //probability mass function
729 double GetHypGeomDist( double x, double n, double M, double N );
730 void ScLogGamma();
731 void ScGamma();
732 void ScPhi();
733 void ScGauss();
734 void ScStdNormDist();
735 void ScFisher();
736 void ScFisherInv();
737 void ScFact();
738 void ScNormDist();
739 void ScGammaDist();
740 void ScGammaInv();
741 void ScExpDist();
742 void ScBinomDist();
743 void ScPoissonDist();
744 void ScKombin();
745 void ScKombin2();
746 void ScVariationen();
747 void ScVariationen2();
748 void ScB();
749 void ScHypGeomDist();
750 void ScHypGeomDist_MS();
751 void ScLogNormDist();
752 void ScLogNormInv();
753 void ScTDist();
754 void ScFDist();
755 void ScFDist_LT();
756 void ScChiDist(); // for LEGACY.CHIDIST, returns right tail
757 void ScChiSqDist(); // returns left tail or density
758 void ScChiSqDist_MS();
759 void ScChiSqInv(); //invers to CHISQDIST
760 void ScWeibull();
761 void ScBetaDist();
762 void ScBetaDist_MS();
763 void ScFInv();
764 void ScFInv_LT();
765 void ScTInv();
766 void ScChiInv();
767 void ScBetaInv();
768 void ScCritBinom();
769 void ScNegBinomDist();
770 void ScKurt();
771 void ScHarMean();
772 void ScGeoMean();
773 void ScStandard();
774 void ScSkew();
775 void ScSkewp();
776 void ScMedian();
777 double GetMedian( ::std::vector<double> & rArray );
778 double GetPercentile( ::std::vector<double> & rArray, double fPercentile );
779 void GetNumberSequenceArray( sal_uInt8 nParamCount, ::std::vector<double>& rArray );
780 void GetSortArray(sal_uInt8 nParamCount, ::std::vector<double>& rSortArray, ::std::vector<long>* pIndexOrder = NULL);
781 void QuickSort(::std::vector<double>& rSortArray, ::std::vector<long>* pIndexOrder = NULL);
782 void ScModalValue();
783 void ScAveDev();
784 void ScDevSq();
785 void ScZTest();
786 void ScTTest();
787 void ScFTest();
788 void ScChiTest();
789 void ScRank();
790 void ScPercentile();
791 void ScPercentrank();
792 void ScLarge();
793 void ScSmall();
794 void ScFrequency();
795 void ScQuartile();
796 void ScNormInv();
797 void ScSNormInv();
798 void ScConfidence();
799 void ScConfidenceT();
800 void ScTrimMean();
801 void ScProbability();
802 void ScCorrel();
803 void ScCovarianceP();
804 void ScCovarianceS();
805 void ScPearson();
806 void ScRSQ();
807 void ScSTEXY();
808 void ScSlope();
809 void ScTrend();
810 void ScInfo();
811 void ScLenB();
812 void ScRightB();
813 void ScLeftB();
814 void ScMidB();
816 void ScFilterXML();
817 void ScWebservice();
819 static const double fMaxGammaArgument;
821 double GetGammaContFraction(double fA,double fX);
822 double GetGammaSeries(double fA,double fX);
823 double GetLowRegIGamma(double fA,double fX); // lower regularized incomplete gamma function, GAMMAQ
824 double GetUpRegIGamma(double fA,double fX); // upper regularized incomplete gamma function, GAMMAP
825 // probability density function; fLambda is "scale" parameter
826 double GetGammaDistPDF(double fX, double fAlpha, double fLambda);
827 // cumulative distribution function; fLambda is "scale" parameter
828 double GetGammaDist(double fX, double fAlpha, double fLambda);
829 double GetTInv( double fAlpha, double fSize );
831 public:
832 ScInterpreter( ScFormulaCell* pCell, ScDocument* pDoc,
833 const ScAddress&, ScTokenArray& );
834 ~ScInterpreter();
836 formula::StackVar Interpret();
838 void SetError(sal_uInt16 nError)
839 { if (nError && !nGlobalError) nGlobalError = nError; }
841 sal_uInt16 GetError() const { return nGlobalError; }
842 formula::StackVar GetResultType() const { return xResult->GetType(); }
843 svl::SharedString GetStringResult() const;
844 double GetNumResult() const { return xResult->GetDouble(); }
845 formula::FormulaTokenRef GetResultToken() const { return xResult; }
846 short GetRetFormatType() const { return nRetFmtType; }
847 sal_uLong GetRetFormatIndex() const { return nRetFmtIndex; }
850 inline void ScInterpreter::MatrixDoubleRefToMatrix()
852 if ( bMatrixFormula && GetStackType() == formula::svDoubleRef )
854 GetTokenMatrixMap(); // make sure it exists, create if not.
855 PopDoubleRefPushMatrix();
859 inline bool ScInterpreter::MatrixParameterConversion()
861 if ( (bMatrixFormula || pCur->HasForceArray()) && !pJumpMatrix && sp > 0 )
862 return ConvertMatrixParameters();
863 return false;
866 inline ScTokenMatrixMap& ScInterpreter::GetTokenMatrixMap()
868 if (!pTokenMatrixMap)
869 pTokenMatrixMap = CreateTokenMatrixMap();
870 return *pTokenMatrixMap;
873 inline bool ScInterpreter::MustHaveParamCount( short nAct, short nMust )
875 if ( nAct == nMust )
876 return true;
877 if ( nAct < nMust )
878 PushParameterExpected();
879 else
880 PushIllegalParameter();
881 return false;
884 inline bool ScInterpreter::MustHaveParamCount( short nAct, short nMust, short nMax )
886 if ( nMust <= nAct && nAct <= nMax )
887 return true;
888 if ( nAct < nMust )
889 PushParameterExpected();
890 else
891 PushIllegalParameter();
892 return false;
895 inline bool ScInterpreter::MustHaveParamCountMin( short nAct, short nMin )
897 if ( nAct >= nMin )
898 return true;
899 PushParameterExpected();
900 return false;
903 inline bool ScInterpreter::CheckStringResultLen( OUString& rResult, const OUString& rAdd )
905 if ( (sal_uLong) rResult.getLength() + rAdd.getLength() > STRING_MAXLEN )
907 SetError( errStringOverflow );
908 rResult = "";
909 return false;
911 return true;
914 inline void ScInterpreter::TreatDoubleError( double& rVal )
916 if ( !::rtl::math::isFinite( rVal ) )
918 sal_uInt16 nErr = GetDoubleErrorValue( rVal );
919 if ( nErr )
920 SetError( nErr );
921 else
922 SetError( errNoValue );
923 rVal = 0.0;
927 inline double ScInterpreter::div( const double& fNumerator, const double& fDenominator )
929 return (fDenominator != 0.0) ? (fNumerator / fDenominator) :
930 CreateDoubleError( errDivisionByZero);
933 #endif
935 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */