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/.
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 .
22 #include <com/sun/star/uno/Reference.hxx>
23 #include <unotools/resmgr.hxx>
30 namespace com::sun::star::beans
{ class XPropertySet
; }
31 namespace com::sun::star::uno
{ class XComponentContext
; }
32 namespace com::sun::star::util
{ class XNumberFormatter2
; }
34 namespace sca::analysis
{
36 class ScaAnyConverter
;
38 inline bool IsLeapYear( sal_uInt16 nYear
);
40 #ifdef DISABLE_DYNLOADING
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
49 #define DaysInMonth analysishelper_DaysInMonth
50 #define DateToDays analysishelper_DateToDays
51 #define DaysToDate analysishelper_DaysToDate
52 #define GetNullDate analysishelper_GetNullDate
56 sal_uInt16
DaysInMonth( sal_uInt16 nMonth
, sal_uInt16 nYear
);
57 sal_Int32
DateToDays( sal_uInt16 nDay
, sal_uInt16 nMonth
, sal_uInt16 nYear
);
58 /// @throws css::lang::IllegalArgumentException
59 void DaysToDate( sal_Int32 nDays
, sal_uInt16
& rDay
, sal_uInt16
& rMonth
, sal_uInt16
& rYear
);
60 /// @throws css::uno::RuntimeException
61 sal_Int32
GetNullDate( const css::uno::Reference
< css::beans::XPropertySet
>& xOptions
);
62 sal_Int32
GetDiffDate360(
63 sal_uInt16 nDay1
, sal_uInt16 nMonth1
, sal_uInt16 nYear1
, bool bLeapYear1
,
64 sal_uInt16 nDay2
, sal_uInt16 nMonth2
, sal_uInt16 nYear2
,
66 inline sal_Int32
GetDiffDate360( const css::uno::Reference
< css::beans::XPropertySet
>& xOpt
, sal_Int32 nDate1
, sal_Int32 nDate2
, bool bUSAMethod
);
67 sal_Int32
GetDiffDate360( sal_Int32 nNullDate
, sal_Int32 nDate1
, sal_Int32 nDate2
, bool bUSAMethod
);
69 sal_Int32
GetDaysInYears( sal_uInt16 nYear1
, sal_uInt16 nYear2
);
70 inline sal_Int16
GetDayOfWeek( sal_Int32 nDate
);
71 /// @throws css::uno::RuntimeException
72 /// @throws css::lang::IllegalArgumentException
73 sal_Int32
GetDiffDate( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
,
74 sal_Int32
* pOptDaysIn1stYear
);
75 /// @throws css::uno::RuntimeException
76 /// @throws css::lang::IllegalArgumentException
77 double GetYearDiff( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
);
78 /// @throws css::uno::RuntimeException
79 /// @throws css::lang::IllegalArgumentException
80 sal_Int32
GetDaysInYear( sal_Int32 nNullDate
, sal_Int32 nDate
, sal_Int32 nMode
);
81 /// @throws css::uno::RuntimeException
82 /// @throws css::lang::IllegalArgumentException
83 double GetYearFrac( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
);
84 /// @throws css::uno::RuntimeException
85 /// @throws css::lang::IllegalArgumentException
86 inline double GetYearFrac( const css::uno::Reference
< css::beans::XPropertySet
>& xOpt
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
);
88 double BinomialCoefficient( double n
, double k
);
89 double GetGcd( double f1
, double f2
);
90 /// @throws css::uno::RuntimeException
91 /// @throws css::lang::IllegalArgumentException
92 double ConvertToDec( const OUString
& rFromNum
, sal_uInt16 nBaseFrom
, sal_uInt16 nCharLim
);
93 /// @throws css::uno::RuntimeException
94 /// @throws css::lang::IllegalArgumentException
95 OUString
ConvertFromDec(
96 double fNum
, double fMin
, double fMax
, sal_uInt16 nBase
,
97 sal_Int32 nPlaces
, sal_Int32 nMaxPlaces
, bool bUsePlaces
);
98 double Erf( double fX
);
99 double Erfc( double fX
);
100 bool ParseDouble( const sal_Unicode
*& rpDoubleAsString
, double& rReturn
);
101 OUString
GetString( double fNumber
, bool bLeadingSign
, sal_uInt16 nMaxNumOfDigits
= 15 );
103 /// @throws css::uno::RuntimeException
104 /// @throws css::lang::IllegalArgumentException
105 double GetAmordegrc( sal_Int32 nNullDate
, double fCost
, sal_Int32 nDate
, sal_Int32 nFirstPer
,
106 double fRestVal
, double fPer
, double fRate
, sal_Int32 nBase
);
107 /// @throws css::uno::RuntimeException
108 /// @throws css::lang::IllegalArgumentException
109 double GetAmorlinc( sal_Int32 nNullDate
, double fCost
, sal_Int32 nDate
, sal_Int32 nFirstPer
,
110 double fRestVal
, double fPer
, double fRate
, sal_Int32 nBase
);
111 /// @throws css::uno::RuntimeException
112 /// @throws css::lang::IllegalArgumentException
113 double GetDuration( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, double fCoup
,
114 double fYield
, sal_Int32 nFreq
, sal_Int32 nBase
);
115 /// @throws css::uno::RuntimeException
116 /// @throws css::lang::IllegalArgumentException
117 double GetYieldmat( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nIssue
,
118 double fRate
, double fPrice
, sal_Int32 nBase
);
119 /// @throws css::uno::RuntimeException
120 /// @throws css::lang::IllegalArgumentException
121 double 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
);
124 /// @throws css::uno::RuntimeException
125 /// @throws css::lang::IllegalArgumentException
126 double getYield_( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, double fCoup
, double fPrice
,
127 double fRedemp
, sal_Int32 nFreq
, sal_Int32 nBase
);
128 /// @throws css::uno::RuntimeException
129 /// @throws css::lang::IllegalArgumentException
130 double getPrice_( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, double fRate
, double fYield
,
131 double fRedemp
, sal_Int32 nFreq
, sal_Int32 nBase
);
132 /// @throws css::uno::RuntimeException
133 /// @throws css::lang::IllegalArgumentException
134 double 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
);
137 /// @throws css::uno::RuntimeException
138 /// @throws css::lang::IllegalArgumentException
139 double 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
);
141 /// @throws css::uno::RuntimeException
142 /// @throws css::lang::IllegalArgumentException
143 double 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
);
145 double GetPmt( double fRate
, double fNper
, double fPv
, double fFv
, sal_Int32 nPayType
);
146 double GetFv( double fRate
, double fNper
, double fPmt
, double fPv
, sal_Int32 nPayType
);
148 /// @throws css::uno::RuntimeException
149 /// @throws css::lang::IllegalArgumentException
150 double GetCouppcd( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
152 /// @throws css::uno::RuntimeException
153 /// @throws css::lang::IllegalArgumentException
154 double GetCoupncd( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
156 /// @throws css::uno::RuntimeException
157 /// @throws css::lang::IllegalArgumentException
158 double GetCoupdaybs( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
160 /// @throws css::uno::RuntimeException
161 /// @throws css::lang::IllegalArgumentException
162 double GetCoupdaysnc( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
165 /// @throws css::uno::RuntimeException
166 /// @throws css::lang::IllegalArgumentException
167 double GetCoupnum( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
,
168 sal_Int32 nFreq
, sal_Int32 nBase
);
169 /// @throws css::uno::RuntimeException
170 /// @throws css::lang::IllegalArgumentException
171 double GetCoupdays( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
175 enum class FDCategory
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
203 TranslateId pUINameID
;
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
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
214 FuncData(const FuncDataBase
& rBaseData
);
216 inline const TranslateId
& GetUINameID() const;
217 inline const TranslateId
* GetDescrID() const;
218 inline bool IsDouble() const;
219 inline const OUString
& GetSuffix() const;
221 sal_uInt16
GetStrIndex( sal_uInt16 nParamNum
) const;
222 inline bool Is( std::u16string_view rCompareTo
) const;
224 inline const std::vector
<OUString
> &
225 GetCompNameList() const;
227 inline FDCategory
GetCategory() const;
230 typedef std::vector
< FuncData
> FuncDataList
;
232 void InitFuncDataList(FuncDataList
& rList
);
234 // Predicate for use with std::find_if
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
); }
242 /// sorted list with unique sal_Int32 values
243 class SortedIndividualInt32List final
246 std::vector
<sal_Int32
> maVector
;
248 void Insert( sal_Int32 nDay
);
249 void Insert( sal_Int32 nDay
, sal_Int32 nNullDate
, bool bInsertOnWeekend
);
250 /// @throws css::uno::RuntimeException
251 /// @throws css::lang::IllegalArgumentException
252 void Insert( double fDay
, sal_Int32 nNullDate
, bool bInsertOnWeekend
);
254 /** @param rAnyConv must be an initialized ScaAnyConmverter
255 @param bInsertOnWeekend insertion mode: false = holidays on weekend are omitted
256 @throws css::uno::RuntimeException
257 @throws css::lang::IllegalArgumentException
259 void InsertHolidayList(
260 const ScaAnyConverter
& rAnyConv
,
261 const css::uno::Any
& rHolAny
,
263 bool bInsertOnWeekend
);
266 SortedIndividualInt32List();
267 ~SortedIndividualInt32List();
269 sal_uInt32
Count() const
270 { return maVector
.size(); }
272 /// @return element on position nIndex or 0 on invalid index
273 sal_Int32
Get( sal_uInt32 n
) const
274 { return maVector
[n
]; }
276 /// @return true if nVal (internal date representation) is contained
277 bool Find( sal_Int32 nVal
) const;
279 /** @param rAnyConv is an initialized or uninitialized ScaAnyConverter
280 holidays on weekend are omitted
281 @throws css::uno::RuntimeException
282 @throws css::lang::IllegalArgumentException
284 void InsertHolidayList(
285 ScaAnyConverter
& rAnyConv
,
286 const css::uno::Reference
< css::beans::XPropertySet
>& xOptions
,
287 const css::uno::Any
& rHolAny
,
288 sal_Int32 nNullDate
);
295 std::vector
<double> maVector
;
297 void ListAppend( double fValue
) { maVector
.push_back(fValue
); }
299 /// @throws css::uno::RuntimeException
300 /// @throws css::lang::IllegalArgumentException
301 void Append( double fValue
)
302 { if( CheckInsert( fValue
) ) ListAppend( fValue
); }
304 /** @param rAnyConv must be an initialized ScaAnyConmverter
305 @param bIgnoreEmpty handling of empty Any's/strings: false = inserted as 0.0; true = omitted
306 @throws css::uno::RuntimeException
307 @throws css::lang::IllegalArgumentException
310 const ScaAnyConverter
& rAnyConv
,
311 const css::uno::Any
& rAny
,
314 /** @param rAnyConv must be an initialized ScaAnyConmverter
315 @param bIgnoreEmpty handling of empty Any's/strings: false = inserted as 0.0; true = omitted
316 @throws css::uno::RuntimeException
317 @throws css::lang::IllegalArgumentException
320 const ScaAnyConverter
& rAnyConv
,
321 const css::uno::Sequence
< css::uno::Any
>& rAnySeq
,
324 /** @param rAnyConv must be an initialized ScaAnyConmverter
325 @param bIgnoreEmpty handling of empty Any's/strings: false = inserted as 0.0; true = omitted
326 @throws css::uno::RuntimeException
327 @throws css::lang::IllegalArgumentException
330 const ScaAnyConverter
& rAnyConv
,
331 const css::uno::Sequence
< css::uno::Sequence
< css::uno::Any
> >& rAnySeq
,
335 virtual ~ScaDoubleList() {}
337 sal_uInt32
Count() const
338 { return maVector
.size(); }
339 double Get( sal_uInt32 n
) const
340 { return maVector
[n
]; }
342 /// @throws css::uno::RuntimeException
343 /// @throws css::lang::IllegalArgumentException
344 void Append( const css::uno::Sequence
< css::uno::Sequence
< double > >& rValueArr
);
345 /// @throws css::uno::RuntimeException
346 /// @throws css::lang::IllegalArgumentException
347 void Append( const css::uno::Sequence
< css::uno::Sequence
< sal_Int32
> >& rValueArr
);
349 /** @param rAnyConv is an initialized or uninitialized ScaAnyConverter
350 @param bIgnoreEmpty handling of empty Any's/strings: false = inserted as 0.0; true = omitted
351 @throws css::uno::RuntimeException
352 @throws css::lang::IllegalArgumentException
355 ScaAnyConverter
& rAnyConv
,
356 const css::uno::Reference
< css::beans::XPropertySet
>& xOpt
,
357 const css::uno::Sequence
< css::uno::Any
>& rAnySeq
);
359 /// @throws css::uno::RuntimeException
360 /// @throws css::lang::IllegalArgumentException
361 virtual bool CheckInsert( double fValue
) const;
365 /// stores double values >0.0, throws exception for double values <0.0, does nothing for 0.0
366 class ScaDoubleListGT0
: public ScaDoubleList
369 virtual bool CheckInsert( double fValue
) const override
;
373 /// stores double values >=0.0, throws exception for double values <0.0
374 class ScaDoubleListGE0
: public ScaDoubleList
377 virtual bool CheckInsert( double fValue
) const override
;
388 inline Complex( double fReal
, double fImag
= 0.0, sal_Unicode cC
= '\0' );
389 /// @throws css::uno::RuntimeException
390 /// @throws css::lang::IllegalArgumentException
391 explicit Complex( const OUString
& rComplexAsString
);
393 inline static bool IsImagUnit( sal_Unicode c
);
394 static bool ParseString( const OUString
& rComplexAsString
, Complex
& rReturn
);
395 /// @throws css::uno::RuntimeException
396 /// @throws css::lang::IllegalArgumentException
397 OUString
GetString() const;
399 inline double Real() const;
400 inline double Imag() const;
402 /// @throws css::uno::RuntimeException
403 /// @throws css::lang::IllegalArgumentException
405 inline double Abs() const;
407 // following functions change the complex number itself to avoid unnecessary copy actions!
408 /// @throws css::uno::RuntimeException
409 /// @throws css::lang::IllegalArgumentException
410 void Power( double fPower
);
412 /// @throws css::uno::RuntimeException
413 /// @throws css::lang::IllegalArgumentException
415 /// @throws css::uno::RuntimeException
416 /// @throws css::lang::IllegalArgumentException
418 /// @throws css::uno::RuntimeException
419 /// @throws css::lang::IllegalArgumentException
420 void Div( const Complex
& rDivisor
);
422 inline void Conjugate();
423 /// @throws css::uno::RuntimeException
424 /// @throws css::lang::IllegalArgumentException
426 /// @throws css::uno::RuntimeException
427 /// @throws css::lang::IllegalArgumentException
429 /// @throws css::uno::RuntimeException
430 /// @throws css::lang::IllegalArgumentException
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
);
436 /// @throws css::uno::RuntimeException
437 /// @throws css::lang::IllegalArgumentException
439 /// @throws css::uno::RuntimeException
440 /// @throws css::lang::IllegalArgumentException
442 /// @throws css::uno::RuntimeException
443 /// @throws css::lang::IllegalArgumentException
445 /// @throws css::uno::RuntimeException
446 /// @throws css::lang::IllegalArgumentException
448 /// @throws css::uno::RuntimeException
449 /// @throws css::lang::IllegalArgumentException
451 /// @throws css::uno::RuntimeException
452 /// @throws css::lang::IllegalArgumentException
454 /// @throws css::uno::RuntimeException
455 /// @throws css::lang::IllegalArgumentException
457 /// @throws css::uno::RuntimeException
458 /// @throws css::lang::IllegalArgumentException
464 class ComplexList final
467 std::vector
<Complex
> maVector
;
471 inline const Complex
& Get( sal_uInt32 nIndex
) const;
474 { return maVector
.empty(); }
475 sal_uInt32
Count() const
476 { return maVector
.size(); }
478 inline void Append( Complex
&& pNew
);
479 /// @throws css::uno::RuntimeException
480 /// @throws css::lang::IllegalArgumentException
481 void Append( const css::uno::Sequence
< css::uno::Sequence
< OUString
> >& rComplexNumList
);
482 /// @throws css::uno::RuntimeException
483 /// @throws css::lang::IllegalArgumentException
484 void Append( const css::uno::Sequence
< css::uno::Any
>& aMultPars
);
488 enum ConvertDataClass
490 CDC_Mass
, CDC_Length
, CDC_Time
, CDC_Pressure
, CDC_Force
, CDC_Energy
, CDC_Power
, CDC_Magnetism
,
491 CDC_Temperature
, CDC_Volume
, CDC_Area
, CDC_Speed
, CDC_Information
495 #define INV_MATCHLEV 1764 // guess, what this is... :-)
501 friend class ConvertDataList
;
504 ConvertDataClass eClass
;
508 const char pUnitName
[],
509 double fConvertConstant
,
510 ConvertDataClass eClass
,
511 bool bPrefSupport
= false );
513 virtual ~ConvertData();
515 sal_Int16
GetMatchingLevel( const OUString
& rRef
) const;
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
521 /// @throws css::uno::RuntimeException
522 /// @throws css::lang::IllegalArgumentException
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;
527 inline ConvertDataClass
Class() const;
530 class ConvertDataLinear final
: public ConvertData
534 inline ConvertDataLinear(
535 const char pUnitName
[],
536 double fConvertConstant
,
537 double fConvertOffset
,
538 ConvertDataClass eClass
,
539 bool bPrefSupport
= false );
541 virtual ~ConvertDataLinear() override
;
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)
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
;
555 class ConvertDataList
558 std::vector
<std::unique_ptr
<ConvertData
>> maVector
;
563 /// @throws css::uno::RuntimeException
564 /// @throws css::lang::IllegalArgumentException
565 double Convert( double fVal
, const OUString
& rFrom
, const OUString
& rTo
);
569 inline bool IsLeapYear( sal_uInt16 n
)
571 return ( (( ( n
% 4 ) == 0 ) && ( ( n
% 100 ) != 0)) || ( ( n
% 400 ) == 0 ) );
575 inline sal_Int32
GetDiffDate360( const css::uno::Reference
< css::beans::XPropertySet
>& xOpt
, sal_Int32 nDate1
, sal_Int32 nDate2
, bool bUSAMethod
)
577 return GetDiffDate360( GetNullDate( xOpt
), nDate1
, nDate2
, bUSAMethod
);
581 inline sal_Int16
GetDayOfWeek( sal_Int32 n
)
582 { // monday = 0, ..., sunday = 6
583 return static_cast< sal_Int16
>( ( n
- 1 ) % 7 );
587 inline double GetYearFrac( const css::uno::Reference
< css::beans::XPropertySet
>& xOpt
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
)
589 return GetYearFrac( GetNullDate( xOpt
), nStartDate
, nEndDate
, nMode
);
593 inline const TranslateId
& FuncData::GetUINameID() const
599 inline const TranslateId
* FuncData::GetDescrID() const
605 inline bool FuncData::IsDouble() const
611 inline const OUString
& FuncData::GetSuffix() const
617 inline bool FuncData::Is( std::u16string_view r
) const
619 return aIntName
== r
;
623 inline const std::vector
<OUString
> & FuncData::GetCompNameList() const
629 inline FDCategory
FuncData::GetCategory() const
635 inline Complex::Complex( double fReal
, double fImag
, sal_Unicode cC
) :
636 r( fReal
), i( fImag
), c( cC
)
641 inline double Complex::Real() const
647 inline double Complex::Imag() const
653 inline double Complex::Abs() const
655 return std::hypot(r
, i
);
659 void Complex::Conjugate()
665 inline void Complex::Mult( double f
)
672 inline void Complex::Mult( const Complex
& rM
)
677 r
= r_
* rM
.r
- i_
* rM
.i
;
678 i
= r_
* rM
.i
+ i_
* rM
.r
;
684 inline void Complex::Sub( const Complex
& rC
)
692 inline void Complex::Add( const Complex
& rAdd
)
700 inline const Complex
& ComplexList::Get( sal_uInt32 n
) const
706 inline void ComplexList::Append( Complex
&& p
)
708 maVector
.emplace_back(p
);
712 inline ConvertDataClass
ConvertData::Class() const
717 inline ConvertDataLinear::ConvertDataLinear( const char p
[], double fC
, double fO
, ConvertDataClass e
,
718 bool bPrefSupport
) :
719 ConvertData( p
, fC
, e
, bPrefSupport
),
725 /// Helper class for date calculation for various financial functions
729 sal_uInt16 nOrigDay
; /// is the day of the original date.
730 sal_uInt16 nDay
; /// is the calculated day depending on the current month/year.
731 sal_uInt16 nMonth
; /// is the current month (one-based).
732 sal_uInt16 nYear
; /// is the current year.
733 bool bLastDayMode
: 1; /// if true, recalculate nDay after every calculation.
734 bool bLastDay
: 1; /// is true, if original date was the last day in month.
735 bool b30Days
: 1; /// is true, if every month has 30 days in calculations.
736 bool bUSMode
: 1; /// is true, if the US method of 30-day-calculations is used.
738 /// Calculates nDay from nOrigDay and current date.
741 /// @return count of days in current month
742 inline sal_uInt16
getDaysInMonth() const;
743 /// @return count of days in given month
744 inline sal_uInt16
getDaysInMonth( sal_uInt16 _nMon
) const;
746 /// @ return count of days in the given month range
747 sal_Int32
getDaysInMonthRange( sal_uInt16 nFrom
, sal_uInt16 nTo
) const;
748 /// @ return count of days in the given year range
749 sal_Int32
getDaysInYearRange( sal_uInt16 nFrom
, sal_uInt16 nTo
) const;
751 /// Adds/subtracts the given count of years, does not adjust day.
753 /// @throws css::lang::IllegalArgumentException
754 void doAddYears( sal_Int32 nYearCount
);
759 date handling mode (days in month / days in year):
760 0 = 30 days / 360 days (US NASD)
764 4 = 30 days / 360 days (Europe)
765 5 = exact / exact (no last day adjustment) */
766 ScaDate( sal_Int32 nNullDate
, sal_Int32 nDate
, sal_Int32 nBase
);
767 ScaDate( const ScaDate
& rCopy
);
768 ScaDate
& operator=( const ScaDate
& rCopy
);
770 /// @return the current month.
771 sal_uInt16
getMonth() const { return nMonth
; };
772 /// @return the current year.
773 sal_uInt16
getYear() const { return nYear
; };
775 /// adds/subtracts the given count of months, adjusts day
777 /// @throws css::lang::IllegalArgumentException
778 void addMonths( sal_Int32 nMonthCount
);
780 /// sets the given year, adjusts day
781 inline void setYear( sal_uInt16 nNewYear
);
782 /// adds/subtracts the given count of years, adjusts day
784 /// @throws css::lang::IllegalArgumentException
785 inline void addYears( sal_Int32 nYearCount
);
787 /// @return the internal number of the current date
788 sal_Int32
getDate( sal_Int32 nNullDate
) const;
789 /// @return the number of days between the two dates
791 /// @throws css::lang::IllegalArgumentException
792 static sal_Int32
getDiff( const ScaDate
& rFrom
, const ScaDate
& rTo
);
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
); }
800 inline sal_uInt16
ScaDate::getDaysInMonth() const
802 return getDaysInMonth( nMonth
);
805 inline sal_uInt16
ScaDate::getDaysInMonth( sal_uInt16 _nMon
) const
807 return b30Days
? 30 : DaysInMonth( _nMon
, nYear
);
810 inline void ScaDate::setYear( sal_uInt16 nNewYear
)
816 inline void ScaDate::addYears( sal_Int32 nYearCount
)
818 doAddYears( nYearCount
);
823 /// Helper class for Any->double conversion, using the current locale
824 class ScaAnyConverter
827 css::uno::Reference
< css::util::XNumberFormatter2
> xFormatter
;
828 sal_Int32 nDefaultFormat
;
829 bool bHasValidFormat
;
831 /** Converts a string to double using the number formatter. If the formatter is not
832 valid, ::rtl::math::stringToDouble() with english separators will be used.
833 @throws css::lang::IllegalArgumentException
834 on strings not representing any double value.
835 @return the converted double value. */
836 double convertToDouble(
837 const OUString
& rString
) const;
840 explicit ScaAnyConverter(
841 const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
844 /// Initializing with the current locale
846 /// @throws css::uno::RuntimeException
848 const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
);
850 /** Converts an Any to double (without initialization).
851 The Any can be empty or contain a double or string.
852 @throws css::lang::IllegalArgumentException
853 on other Any types or on invalid strings.
854 @return true if the Any contains a double or a non-empty valid string,
855 false if the Any is empty or the string is empty */
858 const css::uno::Any
& rAny
) const;
860 /** Converts an Any to double (with initialization).
861 The Any can be empty or contain a double or string.
862 @throws css::lang::IllegalArgumentException
863 on other Any types or on invalid strings.
864 @return true if the Any contains a double or a non-empty valid string,
865 false if the Any is empty or the string is empty */
868 const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
,
869 const css::uno::Any
& rAny
);
871 /** Converts an Any to double (with initialization).
872 The Any can be empty or contain a double or string.
873 @throws css::lang::IllegalArgumentException
874 on other Any types or on invalid strings.
875 @return the value of the double or string or fDefault if the Any or string is empty */
877 const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
,
878 const css::uno::Any
& rAny
,
881 /** Converts an Any to sal_Int32 (with initialization).
882 The Any can be empty or contain a double or string.
883 @throws css::lang::IllegalArgumentException
884 on other Any types or on invalid values or strings.
885 @return true if the Any contains a double or a non-empty valid string,
886 false if the Any is empty or the string is empty */
889 const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
,
890 const css::uno::Any
& rAny
);
892 /** Converts an Any to sal_Int32 (with initialization).
893 The Any can be empty or contain a double or string.
894 @throws css::lang::IllegalArgumentException
895 on other Any types or on invalid values or strings.
896 @return the truncated value of the double or string or nDefault if the Any or string is empty */
898 const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
,
899 const css::uno::Any
& rAny
,
900 sal_Int32 nDefault
);
905 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */