LibreOffice Module scaddins (master) 1
analysishelper.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#pragma once
20
21
22#include <com/sun/star/uno/Reference.hxx>
23#include <unotools/resmgr.hxx>
24
25#include <cmath>
26
27#include <memory>
28#include <vector>
29
30namespace com::sun::star::beans { class XPropertySet; }
31namespace com::sun::star::uno { class XComponentContext; }
32namespace com::sun::star::util { class XNumberFormatter2; }
33
34namespace sca::analysis {
35
36class ScaAnyConverter;
37
38inline bool IsLeapYear( sal_uInt16 nYear );
39
40#ifdef DISABLE_DYNLOADING
41
42// Avoid clash with the functions with same name in
43// scaddins/source/datefunc/datefunc.cxx. I am not sure if each pair
44// have identical semantics, but if yes, one copy should be enough,
45// but what would be a suitable library where such functions could go?
46// Or can the analysis library depend on the date library or the other
47// way around?
48
49#define DaysInMonth analysishelper_DaysInMonth
50#define DateToDays analysishelper_DateToDays
51#define DaysToDate analysishelper_DaysToDate
52#define GetNullDate analysishelper_GetNullDate
53
54#endif
55
56sal_uInt16 DaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear );
57sal_Int32 DateToDays( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear );
59void DaysToDate( sal_Int32 nDays, sal_uInt16& rDay, sal_uInt16& rMonth, sal_uInt16& rYear );
61sal_Int32 GetNullDate( const css::uno::Reference< css::beans::XPropertySet >& xOptions );
62sal_Int32 GetDiffDate360(
63 sal_uInt16 nDay1, sal_uInt16 nMonth1, sal_uInt16 nYear1, bool bLeapYear1,
64 sal_uInt16 nDay2, sal_uInt16 nMonth2, sal_uInt16 nYear2,
65 bool bUSAMethod );
66inline sal_Int32 GetDiffDate360( const css::uno::Reference< css::beans::XPropertySet >& xOpt, sal_Int32 nDate1, sal_Int32 nDate2, bool bUSAMethod );
67sal_Int32 GetDiffDate360( sal_Int32 nNullDate, sal_Int32 nDate1, sal_Int32 nDate2, bool bUSAMethod );
68
69sal_Int32 GetDaysInYears( sal_uInt16 nYear1, sal_uInt16 nYear2 );
70inline sal_Int16 GetDayOfWeek( sal_Int32 nDate );
73sal_Int32 GetDiffDate( sal_Int32 nNullDate, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode,
74 sal_Int32* pOptDaysIn1stYear );
77double GetYearDiff( sal_Int32 nNullDate, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode );
80sal_Int32 GetDaysInYear( sal_Int32 nNullDate, sal_Int32 nDate, sal_Int32 nMode );
83double GetYearFrac( sal_Int32 nNullDate, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode );
86inline double GetYearFrac( const css::uno::Reference< css::beans::XPropertySet >& xOpt, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode );
87
88double BinomialCoefficient( double n, double k );
89double GetGcd( double f1, double f2 );
92double ConvertToDec( const OUString& rFromNum, sal_uInt16 nBaseFrom, sal_uInt16 nCharLim );
95OUString ConvertFromDec(
96 double fNum, double fMin, double fMax, sal_uInt16 nBase,
97 sal_Int32 nPlaces, sal_Int32 nMaxPlaces, bool bUsePlaces );
98double Erf( double fX );
99double Erfc( double fX );
100bool ParseDouble( const sal_Unicode*& rpDoubleAsString, double& rReturn );
101OUString GetString( double fNumber, bool bLeadingSign, sal_uInt16 nMaxNumOfDigits = 15 );
102
105double GetAmordegrc( sal_Int32 nNullDate, double fCost, sal_Int32 nDate, sal_Int32 nFirstPer,
106 double fRestVal, double fPer, double fRate, sal_Int32 nBase );
109double GetAmorlinc( sal_Int32 nNullDate, double fCost, sal_Int32 nDate, sal_Int32 nFirstPer,
110 double fRestVal, double fPer, double fRate, sal_Int32 nBase );
113double GetDuration( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, double fCoup,
114 double fYield, sal_Int32 nFreq, sal_Int32 nBase );
117double GetYieldmat( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nIssue,
118 double fRate, double fPrice, sal_Int32 nBase );
121double GetOddfprice( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nIssue,
122 sal_Int32 nFirstCoup, double fRate, double fYield, double fRedemp,
123 sal_Int32 nFreq, sal_Int32 nBase );
126double getYield_( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, double fCoup, double fPrice,
127 double fRedemp, sal_Int32 nFreq, sal_Int32 nBase );
130double getPrice_( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, double fRate, double fYield,
131 double fRedemp, sal_Int32 nFreq, sal_Int32 nBase );
134double GetOddfyield( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nIssue,
135 sal_Int32 nFirstCoup, double fRate, double fPrice, double fRedemp,
136 sal_Int32 nFreq, sal_Int32 nBase );
139double GetOddlprice( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nLastInterest,
140 double fRate, double fYield, double fRedemp, sal_Int32 nFreq, sal_Int32 nBase );
143double GetOddlyield( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nLastInterest,
144 double fRate, double fPrice, double fRedemp, sal_Int32 nFreq, sal_Int32 nBase );
145double GetPmt( double fRate, double fNper, double fPv, double fFv, sal_Int32 nPayType );
146double GetFv( double fRate, double fNper, double fPmt, double fPv, sal_Int32 nPayType );
147
150double GetCouppcd( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq,
151 sal_Int32 nBase );
154double GetCoupncd( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq,
155 sal_Int32 nBase );
158double GetCoupdaybs( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq,
159 sal_Int32 nBase );
162double GetCoupdaysnc( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq,
163 sal_Int32 nBase );
164
167double GetCoupnum( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat,
168 sal_Int32 nFreq, sal_Int32 nBase );
171double GetCoupdays( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq,
172 sal_Int32 nBase );
173
174
175enum class FDCategory
176{
177 DateTime,
178 Finance,
179 Inf,
180 Math,
181 Tech
182};
183
184
186{
187 const char* pIntName;
188 TranslateId pUINameID; // resource ID to UI name
189 const TranslateId* pDescrID; // resource ID to description, parameter names and ~ description
190 bool bDouble; // name already exist in Calc
191 bool bWithOpt; // first parameter is internal
192 const char** pCompListID; // list of valid names
193 sal_uInt16 nNumOfParams; // number of named / described parameters
194 FDCategory eCat; // function category
195 const char* pSuffix; // if bDouble, append a suffix other than "_ADD" for UI
196};
197
198
199class FuncData final
200{
201private:
202 OUString aIntName;
204 const TranslateId* pDescrID; // leads also to parameter descriptions!
205 bool bDouble; // flag for names that already exist in Calc
206 bool bWithOpt; // has internal parameter on first position
207
208 sal_uInt16 nParam; // num of parameters
209 std::vector<OUString> aCompList; // list of all valid names
210 FDCategory eCat; // function category
211 OUString aSuffix; // if bDouble and not empty, append a suffix other than "_ADD" for UI
212
213public:
214 FuncData(const FuncDataBase& rBaseData);
215
216 inline const TranslateId& GetUINameID() const;
217 inline const TranslateId* GetDescrID() const;
218 inline bool IsDouble() const;
219 inline const OUString& GetSuffix() const;
220
221 sal_uInt16 GetStrIndex( sal_uInt16 nParamNum ) const;
222 inline bool Is( std::u16string_view rCompareTo ) const;
223
224 inline const std::vector<OUString> &
225 GetCompNameList() const;
226
227 inline FDCategory GetCategory() const;
228};
229
230typedef std::vector< FuncData > FuncDataList;
231
232void InitFuncDataList(FuncDataList& rList);
233
234// Predicate for use with std::find_if
236{
237 const OUString& m_rId;
238 explicit FindFuncData( const OUString& rId ) : m_rId(rId) {}
239 bool operator() ( FuncData const & rCandidate ) const { return rCandidate.Is(m_rId); }
240};
241
244{
245private:
246 std::vector<sal_Int32> maVector;
247
248 void Insert( sal_Int32 nDay );
249 void Insert( sal_Int32 nDay, sal_Int32 nNullDate, bool bInsertOnWeekend );
252 void Insert( double fDay, sal_Int32 nNullDate, bool bInsertOnWeekend );
253
260 const ScaAnyConverter& rAnyConv,
261 const css::uno::Any& rHolAny,
262 sal_Int32 nNullDate,
263 bool bInsertOnWeekend );
264
265public:
268
269 sal_uInt32 Count() const
270 { return maVector.size(); }
271
273 sal_Int32 Get( sal_uInt32 n ) const
274 { return maVector[n]; }
275
277 bool Find( sal_Int32 nVal ) const;
278
285 ScaAnyConverter& rAnyConv,
286 const css::uno::Reference< css::beans::XPropertySet >& xOptions,
287 const css::uno::Any& rHolAny,
288 sal_Int32 nNullDate);
289};
290
291
293{
294private:
295 std::vector<double> maVector;
296protected:
297 void ListAppend( double fValue ) { maVector.push_back(fValue); }
298
301 void Append( double fValue )
302 { if( CheckInsert( fValue ) ) ListAppend( fValue ); }
303
309 void Append(
310 const ScaAnyConverter& rAnyConv,
311 const css::uno::Any& rAny,
312 bool bIgnoreEmpty );
313
319 void Append(
320 const ScaAnyConverter& rAnyConv,
321 const css::uno::Sequence< css::uno::Any >& rAnySeq,
322 bool bIgnoreEmpty );
323
329 void Append(
330 const ScaAnyConverter& rAnyConv,
331 const css::uno::Sequence< css::uno::Sequence< css::uno::Any > >& rAnySeq,
332 bool bIgnoreEmpty );
333
334public:
335 virtual ~ScaDoubleList() {}
336
337 sal_uInt32 Count() const
338 { return maVector.size(); }
339 double Get( sal_uInt32 n ) const
340 { return maVector[n]; }
341
344 void Append( const css::uno::Sequence< css::uno::Sequence< double > >& rValueArr );
347 void Append( const css::uno::Sequence< css::uno::Sequence< sal_Int32 > >& rValueArr );
348
354 void Append(
355 ScaAnyConverter& rAnyConv,
356 const css::uno::Reference< css::beans::XPropertySet >& xOpt,
357 const css::uno::Sequence< css::uno::Any >& rAnySeq );
358
361 virtual bool CheckInsert( double fValue ) const;
362};
363
364
367{
368public:
369 virtual bool CheckInsert( double fValue ) const override;
370};
371
372
375{
376public:
377 virtual bool CheckInsert( double fValue ) const override;
378};
379
380
382{
383 double r;
384 double i;
386
387public:
388 inline Complex( double fReal, double fImag = 0.0, sal_Unicode cC = '\0' );
391 explicit Complex( const OUString& rComplexAsString );
392
393 inline static bool IsImagUnit( sal_Unicode c );
394 static bool ParseString( const OUString& rComplexAsString, Complex& rReturn );
397 OUString GetString() const;
398
399 inline double Real() const;
400 inline double Imag() const;
401
404 double Arg() const;
405 inline double Abs() const;
406
407 // following functions change the complex number itself to avoid unnecessary copy actions!
410 void Power( double fPower );
411 void Sqrt();
414 void Sin();
417 void Cos();
420 void Div( const Complex& rDivisor );
421 void Exp();
422 inline void Conjugate();
425 void Ln();
428 void Log10();
431 void Log2();
432 inline void Mult( double fFact );
433 inline void Mult( const Complex& rMult );
434 inline void Sub( const Complex& rMult );
435 inline void Add( const Complex& rAdd );
438 void Tan();
441 void Sec();
444 void Csc();
447 void Cot();
450 void Sinh();
453 void Cosh();
456 void Sech();
459 void Csch();
460
461};
462
463
464class ComplexList final
465{
466private:
467 std::vector<Complex> maVector;
468public:
469 ~ComplexList();
470
471 inline const Complex& Get( sal_uInt32 nIndex ) const;
472
473 bool empty() const
474 { return maVector.empty(); }
475 sal_uInt32 Count() const
476 { return maVector.size(); }
477
478 inline void Append( Complex&& pNew );
481 void Append( const css::uno::Sequence< css::uno::Sequence< OUString > >& rComplexNumList );
484 void Append( const css::uno::Sequence< css::uno::Any >& aMultPars );
485};
486
487
489{
493
494
495#define INV_MATCHLEV 1764 // guess, what this is... :-)
496
497
499{
500protected:
501 friend class ConvertDataList;
502 double fConst;
503 OUString aName;
506public:
508 const char pUnitName[],
509 double fConvertConstant,
511 bool bPrefSupport = false );
512
513 virtual ~ConvertData();
514
515 sal_Int16 GetMatchingLevel( const OUString& rRef ) const;
516 // 0.0 = no equality
517 // 1.0 = matches exact
518 // rest = matches without an assumed prefix of one character
519 // rest gives power for 10 represented by the prefix (e.g. 3 for k or -9 for n
520
523 virtual double Convert( double fVal, const ConvertData& rTo,
524 sal_Int16 nMatchLevelFrom, sal_Int16 nMatchLevelTo ) const;
525 virtual double ConvertFromBase( double fVal, sal_Int16 nMatchLevel ) const;
526
527 inline ConvertDataClass Class() const;
528};
529
530class ConvertDataLinear final : public ConvertData
531{
532 double fOffs;
533public:
534 inline ConvertDataLinear(
535 const char pUnitName[],
536 double fConvertConstant,
537 double fConvertOffset,
539 bool bPrefSupport = false );
540
541 virtual ~ConvertDataLinear() override;
542
543 virtual double Convert( double fVal, const ConvertData& rTo,
544 sal_Int16 nMatchLevelFrom, sal_Int16 nMatchLevelTo ) const override;
545 // for cases where f(x) = a + bx applies (e.g. Temperatures)
546
547 // converts fVal from this unit to rFrom unit
548 // throws exception if not from same class
549 // this implementation is for proportional cases only
550 double ConvertToBase( double fVal, sal_Int16 nMatchLevel ) const;
551 virtual double ConvertFromBase( double fVal, sal_Int16 nMatchLevel ) const override;
552};
553
554
556{
557private:
558 std::vector<std::unique_ptr<ConvertData>> maVector;
559public:
562
565 double Convert( double fVal, const OUString& rFrom, const OUString& rTo );
566};
567
568
569inline bool IsLeapYear( sal_uInt16 n )
570{
571 return ( (( ( n % 4 ) == 0 ) && ( ( n % 100 ) != 0)) || ( ( n % 400 ) == 0 ) );
572}
573
574
575inline sal_Int32 GetDiffDate360( const css::uno::Reference< css::beans::XPropertySet >& xOpt, sal_Int32 nDate1, sal_Int32 nDate2, bool bUSAMethod )
576{
577 return GetDiffDate360( GetNullDate( xOpt ), nDate1, nDate2, bUSAMethod );
578}
579
580
581inline sal_Int16 GetDayOfWeek( sal_Int32 n )
582{ // monday = 0, ..., sunday = 6
583 return static_cast< sal_Int16 >( ( n - 1 ) % 7 );
584}
585
586
587inline double GetYearFrac( const css::uno::Reference< css::beans::XPropertySet >& xOpt, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode )
588{
589 return GetYearFrac( GetNullDate( xOpt ), nStartDate, nEndDate, nMode );
590}
591
592
594{
595 return pUINameID;
596}
597
598
600{
601 return pDescrID;
602}
603
604
605inline bool FuncData::IsDouble() const
606{
607 return bDouble;
608}
609
610
611inline const OUString& FuncData::GetSuffix() const
612{
613 return aSuffix;
614}
615
616
617inline bool FuncData::Is( std::u16string_view r ) const
618{
619 return aIntName == r;
620}
621
622
623inline const std::vector<OUString> & FuncData::GetCompNameList() const
624{
625 return aCompList;
626}
627
628
630{
631 return eCat;
632}
633
634
635inline Complex::Complex( double fReal, double fImag, sal_Unicode cC ) :
636 r( fReal ), i( fImag ), c( cC )
637{
638}
639
640
641inline double Complex::Real() const
642{
643 return r;
644}
645
646
647inline double Complex::Imag() const
648{
649 return i;
650}
651
652
653inline double Complex::Abs() const
654{
655 return std::hypot(r, i);
656}
657
658
660{
661 i = -i;
662}
663
664
665inline void Complex::Mult( double f )
666{
667 i *= f;
668 r *= f;
669}
670
671
672inline void Complex::Mult( const Complex& rM )
673{
674 double r_ = r;
675 double i_ = i;
676
677 r = r_ * rM.r - i_ * rM.i;
678 i = r_ * rM.i + i_ * rM.r;
679
680 if( !c ) c = rM.c;
681}
682
683
684inline void Complex::Sub( const Complex& rC )
685{
686 r -= rC.r;
687 i -= rC.i;
688 if( !c ) c = rC.c;
689}
690
691
692inline void Complex::Add( const Complex& rAdd )
693{
694 r += rAdd.r;
695 i += rAdd.i;
696 if( !c ) c = rAdd.c;
697}
698
699
700inline const Complex& ComplexList::Get( sal_uInt32 n ) const
701{
702 return maVector[n];
703}
704
705
706inline void ComplexList::Append( Complex&& p )
707{
708 maVector.emplace_back(p);
709}
710
711
713{
714 return eClass;
715}
716
717inline ConvertDataLinear::ConvertDataLinear( const char p[], double fC, double fO, ConvertDataClass e,
718 bool bPrefSupport ) :
719 ConvertData( p, fC, e, bPrefSupport ),
720 fOffs( fO )
721{
722}
723
724
727{
728private:
729 sal_uInt16 nOrigDay;
730 sal_uInt16 nDay;
731 sal_uInt16 nMonth;
732 sal_uInt16 nYear;
733 bool bLastDayMode : 1;
734 bool bLastDay : 1;
735 bool b30Days : 1;
736 bool bUSMode : 1;
737
739 void setDay();
740
742 inline sal_uInt16 getDaysInMonth() const;
744 inline sal_uInt16 getDaysInMonth( sal_uInt16 _nMon ) const;
745
747 sal_Int32 getDaysInMonthRange( sal_uInt16 nFrom, sal_uInt16 nTo ) const;
749 sal_Int32 getDaysInYearRange( sal_uInt16 nFrom, sal_uInt16 nTo ) const;
750
754 void doAddYears( sal_Int32 nYearCount );
755
756public:
757 ScaDate();
766 ScaDate( sal_Int32 nNullDate, sal_Int32 nDate, sal_Int32 nBase );
767 ScaDate( const ScaDate& rCopy );
768 ScaDate& operator=( const ScaDate& rCopy );
769
771 sal_uInt16 getMonth() const { return nMonth; };
773 sal_uInt16 getYear() const { return nYear; };
774
778 void addMonths( sal_Int32 nMonthCount );
779
781 inline void setYear( sal_uInt16 nNewYear );
785 inline void addYears( sal_Int32 nYearCount );
786
788 sal_Int32 getDate( sal_Int32 nNullDate ) const;
792 static sal_Int32 getDiff( const ScaDate& rFrom, const ScaDate& rTo );
793
794 bool operator<( const ScaDate& rCmp ) const;
795 bool operator<=( const ScaDate& rCmp ) const { return !(rCmp < *this); }
796 bool operator>( const ScaDate& rCmp ) const { return rCmp < *this; }
797 bool operator>=( const ScaDate& rCmp ) const { return !(*this < rCmp); }
798};
799
800inline sal_uInt16 ScaDate::getDaysInMonth() const
801{
802 return getDaysInMonth( nMonth );
803}
804
805inline sal_uInt16 ScaDate::getDaysInMonth( sal_uInt16 _nMon ) const
806{
807 return b30Days ? 30 : DaysInMonth( _nMon, nYear );
808}
809
810inline void ScaDate::setYear( sal_uInt16 nNewYear )
811{
812 nYear = nNewYear;
813 setDay();
814}
815
816inline void ScaDate::addYears( sal_Int32 nYearCount )
817{
818 doAddYears( nYearCount );
819 setDay();
820}
821
822
825{
826private:
827 css::uno::Reference< css::util::XNumberFormatter2 > xFormatter;
828 sal_Int32 nDefaultFormat;
830
836 double convertToDouble(
837 const OUString& rString ) const;
838
839public:
840 explicit ScaAnyConverter(
841 const css::uno::Reference< css::uno::XComponentContext >& xContext );
843
847 void init(
848 const css::uno::Reference< css::beans::XPropertySet >& xPropSet );
849
857 double& rfResult,
858 const css::uno::Any& rAny ) const;
859
867 double& rfResult,
868 const css::uno::Reference< css::beans::XPropertySet >& xPropSet,
869 const css::uno::Any& rAny );
870
876 double getDouble(
877 const css::uno::Reference< css::beans::XPropertySet >& xPropSet,
878 const css::uno::Any& rAny,
879 double fDefault );
880
888 sal_Int32& rnResult,
889 const css::uno::Reference< css::beans::XPropertySet >& xPropSet,
890 const css::uno::Any& rAny );
891
897 sal_Int32 getInt32(
898 const css::uno::Reference< css::beans::XPropertySet >& xPropSet,
899 const css::uno::Any& rAny,
900 sal_Int32 nDefault );
901};
902
903}
904
905/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< Complex > maVector
void Append(Complex &&pNew)
void Append(const css::uno::Sequence< css::uno::Any > &aMultPars)
const Complex & Get(sal_uInt32 nIndex) const
void Append(const css::uno::Sequence< css::uno::Sequence< OUString > > &rComplexNumList)
OUString GetString() const
void Div(const Complex &rDivisor)
void Power(double fPower)
void Add(const Complex &rAdd)
static bool ParseString(const OUString &rComplexAsString, Complex &rReturn)
void Sub(const Complex &rMult)
static bool IsImagUnit(sal_Unicode c)
void Mult(double fFact)
Complex(double fReal, double fImag=0.0, sal_Unicode cC='\0')
ConvertDataLinear(const char pUnitName[], double fConvertConstant, double fConvertOffset, ConvertDataClass eClass, bool bPrefSupport=false)
double ConvertToBase(double fVal, sal_Int16 nMatchLevel) const
virtual double ConvertFromBase(double fVal, sal_Int16 nMatchLevel) const override
virtual double Convert(double fVal, const ConvertData &rTo, sal_Int16 nMatchLevelFrom, sal_Int16 nMatchLevelTo) const override
double Convert(double fVal, const OUString &rFrom, const OUString &rTo)
std::vector< std::unique_ptr< ConvertData > > maVector
virtual double Convert(double fVal, const ConvertData &rTo, sal_Int16 nMatchLevelFrom, sal_Int16 nMatchLevelTo) const
ConvertData(const char pUnitName[], double fConvertConstant, ConvertDataClass eClass, bool bPrefSupport=false)
ConvertDataClass Class() const
virtual double ConvertFromBase(double fVal, sal_Int16 nMatchLevel) const
sal_Int16 GetMatchingLevel(const OUString &rRef) const
std::vector< OUString > aCompList
FDCategory GetCategory() const
sal_uInt16 GetStrIndex(sal_uInt16 nParamNum) const
const TranslateId * pDescrID
const OUString & GetSuffix() const
FuncData(const FuncDataBase &rBaseData)
bool Is(std::u16string_view rCompareTo) const
const std::vector< OUString > & GetCompNameList() const
const TranslateId & GetUINameID() const
const TranslateId * GetDescrID() const
Helper class for Any->double conversion, using current language settings.
double convertToDouble(const OUString &rString) const
Converts a string to double using the number formatter.
ScaAnyConverter(const css::uno::Reference< css::uno::XComponentContext > &xContext)
bool getDouble(double &rfResult, const css::uno::Any &rAny) const
Converts an Any to double (without initialization).
sal_Int32 getInt32(const css::uno::Reference< css::beans::XPropertySet > &xPropSet, const css::uno::Any &rAny, sal_Int32 nDefault)
Converts an Any to sal_Int32 (with initialization).
css::uno::Reference< css::util::XNumberFormatter2 > xFormatter
void init(const css::uno::Reference< css::beans::XPropertySet > &xPropSet)
Initializing with current language settings.
bool getInt32(sal_Int32 &rnResult, const css::uno::Reference< css::beans::XPropertySet > &xPropSet, const css::uno::Any &rAny)
Converts an Any to sal_Int32 (with initialization).
double getDouble(const css::uno::Reference< css::beans::XPropertySet > &xPropSet, const css::uno::Any &rAny, double fDefault)
Converts an Any to double (with initialization).
bool getDouble(double &rfResult, const css::uno::Reference< css::beans::XPropertySet > &xPropSet, const css::uno::Any &rAny)
Converts an Any to double (with initialization).
Helper class for date calculation for various financial functions.
bool operator<=(const ScaDate &rCmp) const
sal_uInt16 nDay
is the day of the original date.
sal_Int32 getDate(sal_Int32 nNullDate) const
bool operator>=(const ScaDate &rCmp) const
void doAddYears(sal_Int32 nYearCount)
Adds/subtracts the given count of years, does not adjust day.
bool bLastDayMode
is the current year.
sal_uInt16 getDaysInMonth() const
sal_Int32 getDaysInYearRange(sal_uInt16 nFrom, sal_uInt16 nTo) const
@ return count of days in the given year range
void addMonths(sal_Int32 nMonthCount)
adds/subtracts the given count of months, adjusts day
void setYear(sal_uInt16 nNewYear)
sets the given year, adjusts day
void setDay()
is true, if the US method of 30-day-calculations is used.
void addYears(sal_Int32 nYearCount)
adds/subtracts the given count of years, adjusts day
bool bLastDay
if true, recalculate nDay after every calculation.
bool operator>(const ScaDate &rCmp) const
sal_uInt16 nYear
is the current month (one-based).
sal_uInt16 getYear() const
sal_uInt16 getMonth() const
ScaDate & operator=(const ScaDate &rCopy)
sal_Int32 getDaysInMonthRange(sal_uInt16 nFrom, sal_uInt16 nTo) const
@ return count of days in the given month range
static sal_Int32 getDiff(const ScaDate &rFrom, const ScaDate &rTo)
bool b30Days
is true, if original date was the last day in month.
bool bUSMode
is true, if every month has 30 days in calculations.
sal_uInt16 nMonth
is the calculated day depending on the current month/year.
bool operator<(const ScaDate &rCmp) const
stores double values >=0.0, throws exception for double values <0.0
virtual bool CheckInsert(double fValue) const override
stores double values >0.0, throws exception for double values <0.0, does nothing for 0....
virtual bool CheckInsert(double fValue) const override
void Append(const ScaAnyConverter &rAnyConv, const css::uno::Sequence< css::uno::Any > &rAnySeq, bool bIgnoreEmpty)
void Append(ScaAnyConverter &rAnyConv, const css::uno::Reference< css::beans::XPropertySet > &xOpt, const css::uno::Sequence< css::uno::Any > &rAnySeq)
void Append(const css::uno::Sequence< css::uno::Sequence< sal_Int32 > > &rValueArr)
void Append(const ScaAnyConverter &rAnyConv, const css::uno::Any &rAny, bool bIgnoreEmpty)
std::vector< double > maVector
double Get(sal_uInt32 n) const
void Append(const css::uno::Sequence< css::uno::Sequence< double > > &rValueArr)
virtual bool CheckInsert(double fValue) const
void Append(const ScaAnyConverter &rAnyConv, const css::uno::Sequence< css::uno::Sequence< css::uno::Any > > &rAnySeq, bool bIgnoreEmpty)
void ListAppend(double fValue)
sorted list with unique sal_Int32 values
sal_Int32 Get(sal_uInt32 n) const
void InsertHolidayList(const ScaAnyConverter &rAnyConv, const css::uno::Any &rHolAny, sal_Int32 nNullDate, bool bInsertOnWeekend)
void InsertHolidayList(ScaAnyConverter &rAnyConv, const css::uno::Reference< css::beans::XPropertySet > &xOptions, const css::uno::Any &rHolAny, sal_Int32 nNullDate)
void * p
sal_Int64 n
class SAL_NO_VTABLE XPropertySet
int i
double GetYearDiff(sal_Int32 nNullDate, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode)
double GetOddfprice(sal_Int32, sal_Int32, sal_Int32, sal_Int32, sal_Int32, double, double, double, sal_Int32, sal_Int32)
double getYield_(sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, double fCoup, double fPrice, double fRedemp, sal_Int32 nFreq, sal_Int32 nBase)
double BinomialCoefficient(double n, double k)
double GetOddfyield(sal_Int32, sal_Int32, sal_Int32, sal_Int32, sal_Int32, double, double, double, sal_Int32, sal_Int32)
void InitFuncDataList(FuncDataList &rList)
sal_Int32 GetNullDate(const uno::Reference< beans::XPropertySet > &xOpt)
Get the null date used by the spreadsheet document.
double GetYieldmat(sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nIssue, double fRate, double fPrice, sal_Int32 nBase)
double Erfc(double x)
double GetPmt(double fRate, double fNper, double fPv, double fFv, sal_Int32 nPayType)
double GetCoupdaysnc(sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase)
double GetCouppcd(sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase)
sal_Int32 GetDaysInYear(sal_Int32 nNullDate, sal_Int32 nDate, sal_Int32 nMode)
double GetAmordegrc(sal_Int32 nNullDate, double fCost, sal_Int32 nDate, sal_Int32 nFirstPer, double fRestVal, double fPer, double fRate, sal_Int32 nBase)
double GetCoupnum(sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase)
double GetGcd(double f1, double f2)
OUString GetString(double f, bool bLeadingSign, sal_uInt16 nMaxDig)
OUString ConvertFromDec(double fNum, double fMin, double fMax, sal_uInt16 nBase, sal_Int32 nPlaces, sal_Int32 nMaxPlaces, bool bUsePlaces)
bool ParseDouble(const sal_Unicode *&rp, double &rRet)
sal_Int32 GetDiffDate(sal_Int32 nNullDate, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode, sal_Int32 *pOptDaysIn1stYear)
double getPrice_(sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, double fRate, double fYield, double fRedemp, sal_Int32 nFreq, sal_Int32 nBase)
double GetCoupdays(sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase)
double GetOddlyield(sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nLastCoup, double fRate, double fPrice, double fRedemp, sal_Int32 nFreq, sal_Int32 nBase)
double ConvertToDec(const OUString &aStr, sal_uInt16 nBase, sal_uInt16 nCharLim)
sal_Int32 GetDiffDate360(sal_uInt16 nDay1, sal_uInt16 nMonth1, sal_uInt16 nYear1, bool bLeapYear1, sal_uInt16 nDay2, sal_uInt16 nMonth2, sal_uInt16 nYear2, bool bUSAMethod)
sal_Int32 DateToDays(sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear)
Convert a date to a count of days starting from 01/01/0001.
void DaysToDate(sal_Int32 nDays, sal_uInt16 &rDay, sal_uInt16 &rMonth, sal_uInt16 &rYear)
Convert a count of days starting from 01/01/0001 to a date.
double GetYearFrac(sal_Int32 nNullDate, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode)
Function GetYearFrac implements YEARFRAC as defined in: Open Document Format for Office Applications ...
sal_uInt16 DaysInMonth(sal_uInt16 nMonth, sal_uInt16 nYear)
sal_Int32 GetDaysInYears(sal_uInt16 nYear1, sal_uInt16 nYear2)
double GetCoupdaybs(sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase)
double GetOddlprice(sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nLastCoup, double fRate, double fYield, double fRedemp, sal_Int32 nFreq, sal_Int32 nBase)
double GetFv(double fRate, double fNper, double fPmt, double fPv, sal_Int32 nPayType)
bool IsLeapYear(sal_uInt16 nYear)
double GetAmorlinc(sal_Int32 nNullDate, double fCost, sal_Int32 nDate, sal_Int32 nFirstPer, double fRestVal, double fPer, double fRate, sal_Int32 nBase)
double GetCoupncd(sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, sal_Int32 nBase)
double GetDuration(sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, double fCoup, double fYield, sal_Int32 nFreq, sal_Int32 nBase)
sal_Int16 GetDayOfWeek(sal_Int32 nDate)
double Erf(double x)
std::vector< FuncData > FuncDataList
bool operator()(FuncData const &rCandidate) const
FindFuncData(const OUString &rId)
const TranslateId * pDescrID
sal_uInt16 sal_Unicode