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 .
19 #ifndef INCLUDED_SCADDINS_SOURCE_ANALYSIS_ANALYSISHELPER_HXX
20 #define INCLUDED_SCADDINS_SOURCE_ANALYSIS_ANALYSISHELPER_HXX
23 #include <com/sun/star/uno/Reference.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
{ namespace analysis
{
36 class ScaAnyConverter
;
39 #define PI 3.1415926535897932
42 inline bool IsLeapYear( sal_uInt16 nYear
);
44 #ifdef DISABLE_DYNLOADING
46 // Avoid clash with the functions with same name in
47 // scaddins/source/datefunc/datefunc.cxx. I am not sure if each pair
48 // have identical semantics, but if yes, one copy should be enough,
49 // but what would be a suitable library where such functions could go?
50 // Or can the analysis library depend on the date library or the other
53 #define DaysInMonth analysishelper_DaysInMonth
54 #define DateToDays analysishelper_DateToDays
55 #define DaysToDate analysishelper_DaysToDate
56 #define GetNullDate analysishelper_GetNullDate
60 sal_uInt16
DaysInMonth( sal_uInt16 nMonth
, sal_uInt16 nYear
);
61 sal_Int32
DateToDays( sal_uInt16 nDay
, sal_uInt16 nMonth
, sal_uInt16 nYear
);
62 /// @throws css::lang::IllegalArgumentException
63 void DaysToDate( sal_Int32 nDays
, sal_uInt16
& rDay
, sal_uInt16
& rMonth
, sal_uInt16
& rYear
);
64 /// @throws css::uno::RuntimeException
65 sal_Int32
GetNullDate( const css::uno::Reference
< css::beans::XPropertySet
>& xOptions
);
66 sal_Int32
GetDiffDate360(
67 sal_uInt16 nDay1
, sal_uInt16 nMonth1
, sal_uInt16 nYear1
, bool bLeapYear1
,
68 sal_uInt16 nDay2
, sal_uInt16 nMonth2
, sal_uInt16 nYear2
,
70 inline sal_Int32
GetDiffDate360( const css::uno::Reference
< css::beans::XPropertySet
>& xOpt
, sal_Int32 nDate1
, sal_Int32 nDate2
, bool bUSAMethod
);
71 sal_Int32
GetDiffDate360( sal_Int32 nNullDate
, sal_Int32 nDate1
, sal_Int32 nDate2
, bool bUSAMethod
);
73 sal_Int32
GetDaysInYears( sal_uInt16 nYear1
, sal_uInt16 nYear2
);
74 inline sal_Int16
GetDayOfWeek( sal_Int32 nDate
);
75 /// @throws css::uno::RuntimeException
76 /// @throws css::lang::IllegalArgumentException
77 sal_Int32
GetDiffDate( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
,
78 sal_Int32
* pOptDaysIn1stYear
);
79 /// @throws css::uno::RuntimeException
80 /// @throws css::lang::IllegalArgumentException
81 double GetYearDiff( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
);
82 /// @throws css::uno::RuntimeException
83 /// @throws css::lang::IllegalArgumentException
84 sal_Int32
GetDaysInYear( sal_Int32 nNullDate
, sal_Int32 nDate
, sal_Int32 nMode
);
85 /// @throws css::uno::RuntimeException
86 /// @throws css::lang::IllegalArgumentException
87 double GetYearFrac( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
);
88 /// @throws css::uno::RuntimeException
89 /// @throws css::lang::IllegalArgumentException
90 inline double GetYearFrac( const css::uno::Reference
< css::beans::XPropertySet
>& xOpt
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
);
92 double BinomialCoefficient( double n
, double k
);
93 double GetGcd( double f1
, double f2
);
94 /// @throws css::uno::RuntimeException
95 /// @throws css::lang::IllegalArgumentException
96 double ConvertToDec( const OUString
& rFromNum
, sal_uInt16 nBaseFrom
, sal_uInt16 nCharLim
);
97 /// @throws css::uno::RuntimeException
98 /// @throws css::lang::IllegalArgumentException
99 OUString
ConvertFromDec(
100 double fNum
, double fMin
, double fMax
, sal_uInt16 nBase
,
101 sal_Int32 nPlaces
, sal_Int32 nMaxPlaces
, bool bUsePlaces
);
102 double Erf( double fX
);
103 double Erfc( double fX
);
104 bool ParseDouble( const sal_Unicode
*& rpDoubleAsString
, double& rReturn
);
105 OUString
GetString( double fNumber
, bool bLeadingSign
, sal_uInt16 nMaxNumOfDigits
= 15 );
107 /// @throws css::uno::RuntimeException
108 /// @throws css::lang::IllegalArgumentException
109 double GetAmordegrc( 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 GetAmorlinc( sal_Int32 nNullDate
, double fCost
, sal_Int32 nDate
, sal_Int32 nFirstPer
,
114 double fRestVal
, double fPer
, double fRate
, sal_Int32 nBase
);
115 /// @throws css::uno::RuntimeException
116 /// @throws css::lang::IllegalArgumentException
117 double GetDuration( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, double fCoup
,
118 double fYield
, sal_Int32 nFreq
, sal_Int32 nBase
);
119 /// @throws css::uno::RuntimeException
120 /// @throws css::lang::IllegalArgumentException
121 double GetYieldmat( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nIssue
,
122 double fRate
, double fPrice
, sal_Int32 nBase
);
123 /// @throws css::uno::RuntimeException
124 /// @throws css::lang::IllegalArgumentException
125 double GetOddfprice( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nIssue
,
126 sal_Int32 nFirstCoup
, double fRate
, double fYield
, double fRedemp
,
127 sal_Int32 nFreq
, sal_Int32 nBase
);
128 /// @throws css::uno::RuntimeException
129 /// @throws css::lang::IllegalArgumentException
130 double getYield_( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, double fCoup
, double fPrice
,
131 double fRedemp
, sal_Int32 nFreq
, sal_Int32 nBase
);
132 /// @throws css::uno::RuntimeException
133 /// @throws css::lang::IllegalArgumentException
134 double getPrice_( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, double fRate
, double fYield
,
135 double fRedemp
, sal_Int32 nFreq
, sal_Int32 nBase
);
136 /// @throws css::uno::RuntimeException
137 /// @throws css::lang::IllegalArgumentException
138 double GetOddfyield( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nIssue
,
139 sal_Int32 nFirstCoup
, double fRate
, double fPrice
, double fRedemp
,
140 sal_Int32 nFreq
, sal_Int32 nBase
);
141 /// @throws css::uno::RuntimeException
142 /// @throws css::lang::IllegalArgumentException
143 double GetOddlprice( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nLastInterest
,
144 double fRate
, double fYield
, double fRedemp
, sal_Int32 nFreq
, sal_Int32 nBase
);
145 /// @throws css::uno::RuntimeException
146 /// @throws css::lang::IllegalArgumentException
147 double GetOddlyield( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nLastInterest
,
148 double fRate
, double fPrice
, double fRedemp
, sal_Int32 nFreq
, sal_Int32 nBase
);
149 double GetPmt( double fRate
, double fNper
, double fPv
, double fFv
, sal_Int32 nPayType
);
150 double GetFv( double fRate
, double fNper
, double fPmt
, double fPv
, sal_Int32 nPayType
);
152 /// @throws css::uno::RuntimeException
153 /// @throws css::lang::IllegalArgumentException
154 double GetCouppcd( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
156 /// @throws css::uno::RuntimeException
157 /// @throws css::lang::IllegalArgumentException
158 double GetCoupncd( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
160 /// @throws css::uno::RuntimeException
161 /// @throws css::lang::IllegalArgumentException
162 double GetCoupdaybs( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
164 /// @throws css::uno::RuntimeException
165 /// @throws css::lang::IllegalArgumentException
166 double GetCoupdaysnc( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
169 /// @throws css::uno::RuntimeException
170 /// @throws css::lang::IllegalArgumentException
171 double GetCoupnum( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
,
172 sal_Int32 nFreq
, sal_Int32 nBase
);
173 /// @throws css::uno::RuntimeException
174 /// @throws css::lang::IllegalArgumentException
175 double GetCoupdays( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
179 enum class FDCategory
191 const sal_Char
* pIntName
;
192 const char* pUINameID
; // resource ID to UI name
193 const char** pDescrID
; // resource ID to description, parameter names and ~ description
194 bool const bDouble
; // name already exist in Calc
195 bool const bWithOpt
; // first parameter is internal
196 const char** pCompListID
; // list of valid names
197 sal_uInt16
const nNumOfParams
; // number of named / described parameters
198 FDCategory
const eCat
; // function category
199 const char* pSuffix
; // if bDouble, append a suffix other than "_ADD" for UI
206 OUString
const aIntName
;
207 const char* pUINameID
;
208 const char** pDescrID
; // leads also to parameter descriptions!
209 bool const bDouble
; // flag for names that already exist in Calc
210 bool const bWithOpt
; // has internal parameter on first position
212 sal_uInt16
const nParam
; // num of parameters
213 std::vector
<OUString
> aCompList
; // list of all valid names
214 FDCategory
const eCat
; // function category
215 OUString aSuffix
; // if bDouble and not empty, append a suffix other than "_ADD" for UI
218 FuncData(const FuncDataBase
& rBaseData
);
221 inline const char* GetUINameID() const;
222 inline const char** GetDescrID() const;
223 inline bool IsDouble() const;
224 inline const OUString
& GetSuffix() const;
226 sal_uInt16
GetStrIndex( sal_uInt16 nParamNum
) const;
227 inline bool Is( const OUString
& rCompareTo
) const;
229 inline const std::vector
<OUString
> &
230 GetCompNameList() const;
232 inline FDCategory
GetCategory() const;
235 typedef std::vector
< FuncData
> FuncDataList
;
237 void InitFuncDataList(FuncDataList
& rList
);
239 // Predicate for use with std::find_if
242 const OUString
& m_rId
;
243 explicit FindFuncData( const OUString
& rId
) : m_rId(rId
) {}
244 bool operator() ( FuncData
const & rCandidate
) const { return rCandidate
.Is(m_rId
); }
247 /// sorted list with unique sal_Int32 values
248 class SortedIndividualInt32List final
251 std::vector
<sal_Int32
> maVector
;
253 void Insert( sal_Int32 nDay
);
254 void Insert( sal_Int32 nDay
, sal_Int32 nNullDate
, bool bInsertOnWeekend
);
255 /// @throws css::uno::RuntimeException
256 /// @throws css::lang::IllegalArgumentException
257 void Insert( double fDay
, sal_Int32 nNullDate
, bool bInsertOnWeekend
);
259 /** @param rAnyConv must be an initialized ScaAnyConmverter
260 @param bInsertOnWeekend insertion mode: false = holidays on weekend are omitted
261 @throws css::uno::RuntimeException
262 @throws css::lang::IllegalArgumentException
264 void InsertHolidayList(
265 const ScaAnyConverter
& rAnyConv
,
266 const css::uno::Any
& rHolAny
,
268 bool bInsertOnWeekend
);
271 SortedIndividualInt32List();
272 ~SortedIndividualInt32List();
274 sal_uInt32
Count() const
275 { return maVector
.size(); }
277 /// @return element on position nIndex or 0 on invalid index
278 sal_Int32
Get( sal_uInt32 n
) const
279 { return maVector
[n
]; }
281 /// @return true if nVal (internal date representation) is contained
282 bool Find( sal_Int32 nVal
) const;
284 /** @param rAnyConv is an initialized or uninitialized ScaAnyConverter
285 holidays on weekend are omitted
286 @throws css::uno::RuntimeException
287 @throws css::lang::IllegalArgumentException
289 void InsertHolidayList(
290 ScaAnyConverter
& rAnyConv
,
291 const css::uno::Reference
< css::beans::XPropertySet
>& xOptions
,
292 const css::uno::Any
& rHolAny
,
293 sal_Int32 nNullDate
);
300 std::vector
<double> maVector
;
302 void ListAppend( double fValue
) { maVector
.push_back(fValue
); }
304 /// @throws css::uno::RuntimeException
305 /// @throws css::lang::IllegalArgumentException
306 void Append( double fValue
)
307 { if( CheckInsert( fValue
) ) ListAppend( fValue
); }
309 /** @param rAnyConv must be an initialized ScaAnyConmverter
310 @param bIgnoreEmpty handling of empty Any's/strings: false = inserted as 0.0; true = omitted
311 @throws css::uno::RuntimeException
312 @throws css::lang::IllegalArgumentException
315 const ScaAnyConverter
& rAnyConv
,
316 const css::uno::Any
& rAny
,
319 /** @param rAnyConv must be an initialized ScaAnyConmverter
320 @param bIgnoreEmpty handling of empty Any's/strings: false = inserted as 0.0; true = omitted
321 @throws css::uno::RuntimeException
322 @throws css::lang::IllegalArgumentException
325 const ScaAnyConverter
& rAnyConv
,
326 const css::uno::Sequence
< css::uno::Any
>& rAnySeq
,
329 /** @param rAnyConv must be an initialized ScaAnyConmverter
330 @param bIgnoreEmpty handling of empty Any's/strings: false = inserted as 0.0; true = omitted
331 @throws css::uno::RuntimeException
332 @throws css::lang::IllegalArgumentException
335 const ScaAnyConverter
& rAnyConv
,
336 const css::uno::Sequence
< css::uno::Sequence
< css::uno::Any
> >& rAnySeq
,
340 virtual ~ScaDoubleList() {}
342 sal_uInt32
Count() const
343 { return maVector
.size(); }
344 double Get( sal_uInt32 n
) const
345 { return maVector
[n
]; }
347 /// @throws css::uno::RuntimeException
348 /// @throws css::lang::IllegalArgumentException
349 void Append( const css::uno::Sequence
< css::uno::Sequence
< double > >& rValueArr
);
350 /// @throws css::uno::RuntimeException
351 /// @throws css::lang::IllegalArgumentException
352 void Append( const css::uno::Sequence
< css::uno::Sequence
< sal_Int32
> >& rValueArr
);
354 /** @param rAnyConv is an initialized or uninitialized ScaAnyConverter
355 @param bIgnoreEmpty handling of empty Any's/strings: false = inserted as 0.0; true = omitted
356 @throws css::uno::RuntimeException
357 @throws css::lang::IllegalArgumentException
360 ScaAnyConverter
& rAnyConv
,
361 const css::uno::Reference
< css::beans::XPropertySet
>& xOpt
,
362 const css::uno::Sequence
< css::uno::Any
>& rAnySeq
);
364 /// @throws css::uno::RuntimeException
365 /// @throws css::lang::IllegalArgumentException
366 virtual bool CheckInsert( double fValue
) const;
370 /// stores double values >0.0, throws exception for double values <0.0, does nothing for 0.0
371 class ScaDoubleListGT0
: public ScaDoubleList
374 virtual bool CheckInsert( double fValue
) const override
;
378 /// stores double values >=0.0, throws exception for double values <0.0
379 class ScaDoubleListGE0
: public ScaDoubleList
382 virtual bool CheckInsert( double fValue
) const override
;
393 inline Complex( double fReal
, double fImag
= 0.0, sal_Unicode cC
= '\0' );
394 /// @throws css::uno::RuntimeException
395 /// @throws css::lang::IllegalArgumentException
396 explicit Complex( const OUString
& rComplexAsString
);
398 inline static bool IsImagUnit( sal_Unicode c
);
399 static bool ParseString( const OUString
& rComplexAsString
, Complex
& rReturn
);
400 /// @throws css::uno::RuntimeException
401 /// @throws css::lang::IllegalArgumentException
402 OUString
GetString() const;
404 inline double Real() const;
405 inline double Imag() const;
407 /// @throws css::uno::RuntimeException
408 /// @throws css::lang::IllegalArgumentException
410 inline double Abs() const;
412 // following functions change the complex number itself to avoid unnecessary copy actions!
413 /// @throws css::uno::RuntimeException
414 /// @throws css::lang::IllegalArgumentException
415 void Power( double fPower
);
417 /// @throws css::uno::RuntimeException
418 /// @throws css::lang::IllegalArgumentException
420 /// @throws css::uno::RuntimeException
421 /// @throws css::lang::IllegalArgumentException
423 /// @throws css::uno::RuntimeException
424 /// @throws css::lang::IllegalArgumentException
425 void Div( const Complex
& rDivisor
);
427 inline void Conjugate();
428 /// @throws css::uno::RuntimeException
429 /// @throws css::lang::IllegalArgumentException
431 /// @throws css::uno::RuntimeException
432 /// @throws css::lang::IllegalArgumentException
434 /// @throws css::uno::RuntimeException
435 /// @throws css::lang::IllegalArgumentException
437 inline void Mult( double fFact
);
438 inline void Mult( const Complex
& rMult
);
439 inline void Sub( const Complex
& rMult
);
440 inline void Add( const Complex
& rAdd
);
441 /// @throws css::uno::RuntimeException
442 /// @throws css::lang::IllegalArgumentException
444 /// @throws css::uno::RuntimeException
445 /// @throws css::lang::IllegalArgumentException
447 /// @throws css::uno::RuntimeException
448 /// @throws css::lang::IllegalArgumentException
450 /// @throws css::uno::RuntimeException
451 /// @throws css::lang::IllegalArgumentException
453 /// @throws css::uno::RuntimeException
454 /// @throws css::lang::IllegalArgumentException
456 /// @throws css::uno::RuntimeException
457 /// @throws css::lang::IllegalArgumentException
459 /// @throws css::uno::RuntimeException
460 /// @throws css::lang::IllegalArgumentException
462 /// @throws css::uno::RuntimeException
463 /// @throws css::lang::IllegalArgumentException
469 class ComplexList final
472 std::vector
<Complex
> maVector
;
476 inline const Complex
& Get( sal_uInt32 nIndex
) const;
479 { return maVector
.empty(); }
480 sal_uInt32
Count() const
481 { return maVector
.size(); }
483 inline void Append( Complex
&& pNew
);
484 /// @throws css::uno::RuntimeException
485 /// @throws css::lang::IllegalArgumentException
486 void Append( const css::uno::Sequence
< css::uno::Sequence
< OUString
> >& rComplexNumList
);
487 /// @throws css::uno::RuntimeException
488 /// @throws css::lang::IllegalArgumentException
489 void Append( const css::uno::Sequence
< css::uno::Any
>& aMultPars
);
493 enum ConvertDataClass
495 CDC_Mass
, CDC_Length
, CDC_Time
, CDC_Pressure
, CDC_Force
, CDC_Energy
, CDC_Power
, CDC_Magnetism
,
496 CDC_Temperature
, CDC_Volume
, CDC_Area
, CDC_Speed
, CDC_Information
500 #define INV_MATCHLEV 1764 // guess, what this is... :-)
506 friend class ConvertDataList
;
508 OUString
const aName
;
509 ConvertDataClass
const eClass
;
510 bool const bPrefixSupport
;
513 const sal_Char pUnitName
[],
514 double fConvertConstant
,
515 ConvertDataClass eClass
,
516 bool bPrefSupport
= false );
518 virtual ~ConvertData();
520 sal_Int16
GetMatchingLevel( const OUString
& rRef
) const;
522 // 1.0 = matches exact
523 // rest = matches without an assumed prefix of one character
524 // rest gives power for 10 represented by the prefix (e.g. 3 for k or -9 for n
526 /// @throws css::uno::RuntimeException
527 /// @throws css::lang::IllegalArgumentException
528 virtual double Convert( double fVal
, const ConvertData
& rTo
,
529 sal_Int16 nMatchLevelFrom
, sal_Int16 nMatchLevelTo
) const;
530 virtual double ConvertFromBase( double fVal
, sal_Int16 nMatchLevel
) const;
532 inline ConvertDataClass
Class() const;
535 class ConvertDataLinear final
: public ConvertData
539 inline ConvertDataLinear(
540 const sal_Char pUnitName
[],
541 double fConvertConstant
,
542 double fConvertOffset
,
543 ConvertDataClass eClass
,
544 bool bPrefSupport
= false );
546 virtual ~ConvertDataLinear() override
;
548 virtual double Convert( double fVal
, const ConvertData
& rTo
,
549 sal_Int16 nMatchLevelFrom
, sal_Int16 nMatchLevelTo
) const override
;
550 // for cases where f(x) = a + bx applies (e.g. Temperatures)
552 // converts fVal from this unit to rFrom unit
553 // throws exception if not from same class
554 // this implementation is for proportional cases only
555 double ConvertToBase( double fVal
, sal_Int16 nMatchLevel
) const;
556 virtual double ConvertFromBase( double fVal
, sal_Int16 nMatchLevel
) const override
;
560 class ConvertDataList
563 std::vector
<std::unique_ptr
<ConvertData
>> maVector
;
568 /// @throws css::uno::RuntimeException
569 /// @throws css::lang::IllegalArgumentException
570 double Convert( double fVal
, const OUString
& rFrom
, const OUString
& rTo
);
574 inline bool IsLeapYear( sal_uInt16 n
)
576 return ( (( ( n
% 4 ) == 0 ) && ( ( n
% 100 ) != 0)) || ( ( n
% 400 ) == 0 ) );
580 inline sal_Int32
GetDiffDate360( const css::uno::Reference
< css::beans::XPropertySet
>& xOpt
, sal_Int32 nDate1
, sal_Int32 nDate2
, bool bUSAMethod
)
582 return GetDiffDate360( GetNullDate( xOpt
), nDate1
, nDate2
, bUSAMethod
);
586 inline sal_Int16
GetDayOfWeek( sal_Int32 n
)
587 { // monday = 0, ..., sunday = 6
588 return static_cast< sal_Int16
>( ( n
- 1 ) % 7 );
592 inline double GetYearFrac( const css::uno::Reference
< css::beans::XPropertySet
>& xOpt
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
)
594 return GetYearFrac( GetNullDate( xOpt
), nStartDate
, nEndDate
, nMode
);
598 inline const char* FuncData::GetUINameID() const
604 inline const char** FuncData::GetDescrID() const
610 inline bool FuncData::IsDouble() const
616 inline const OUString
& FuncData::GetSuffix() const
622 inline bool FuncData::Is( const OUString
& r
) const
624 return aIntName
== r
;
628 inline const std::vector
<OUString
> & FuncData::GetCompNameList() const
634 inline FDCategory
FuncData::GetCategory() const
640 inline Complex::Complex( double fReal
, double fImag
, sal_Unicode cC
) :
641 r( fReal
), i( fImag
), c( cC
)
646 inline double Complex::Real() const
652 inline double Complex::Imag() const
658 inline double Complex::Abs() const
660 return sqrt( r
* r
+ i
* i
);
664 void Complex::Conjugate()
670 inline void Complex::Mult( double f
)
677 inline void Complex::Mult( const Complex
& rM
)
682 r
= r_
* rM
.r
- i_
* rM
.i
;
683 i
= r_
* rM
.i
+ i_
* rM
.r
;
689 inline void Complex::Sub( const Complex
& rC
)
697 inline void Complex::Add( const Complex
& rAdd
)
705 inline const Complex
& ComplexList::Get( sal_uInt32 n
) const
711 inline void ComplexList::Append( Complex
&& p
)
713 maVector
.emplace_back(p
);
717 inline ConvertDataClass
ConvertData::Class() const
722 inline ConvertDataLinear::ConvertDataLinear( const sal_Char p
[], double fC
, double fO
, ConvertDataClass e
,
723 bool bPrefSupport
) :
724 ConvertData( p
, fC
, e
, bPrefSupport
),
730 /// Helper class for date calculation for various financial functions
734 sal_uInt16 nOrigDay
; /// is the day of the original date.
735 sal_uInt16 nDay
; /// is the calculated day depending on the current month/year.
736 sal_uInt16 nMonth
; /// is the current month (one-based).
737 sal_uInt16 nYear
; /// is the current year.
738 bool bLastDayMode
: 1; /// if true, recalculate nDay after every calculation.
739 bool bLastDay
: 1; /// is true, if original date was the last day in month.
740 bool b30Days
: 1; /// is true, if every month has 30 days in calculations.
741 bool bUSMode
: 1; /// is true, if the US method of 30-day-calculations is used.
743 /// Calculates nDay from nOrigDay and current date.
746 /// @return count of days in current month
747 inline sal_uInt16
getDaysInMonth() const;
748 /// @return count of days in given month
749 inline sal_uInt16
getDaysInMonth( sal_uInt16 _nMon
) const;
751 /// @ return count of days in the given month range
752 sal_Int32
getDaysInMonthRange( sal_uInt16 nFrom
, sal_uInt16 nTo
) const;
753 /// @ return count of days in the given year range
754 sal_Int32
getDaysInYearRange( sal_uInt16 nFrom
, sal_uInt16 nTo
) const;
756 /// Adds/subtracts the given count of years, does not adjust day.
758 /// @throws css::lang::IllegalArgumentException
759 void doAddYears( sal_Int32 nYearCount
);
764 date handling mode (days in month / days in year):
765 0 = 30 days / 360 days (US NASD)
769 4 = 30 days / 360 days (Europe)
770 5 = exact / exact (no last day adjustment) */
771 ScaDate( sal_Int32 nNullDate
, sal_Int32 nDate
, sal_Int32 nBase
);
772 ScaDate( const ScaDate
& rCopy
);
773 ScaDate
& operator=( const ScaDate
& rCopy
);
775 /// @return the current month.
776 sal_uInt16
getMonth() const { return nMonth
; };
777 /// @return the current year.
778 sal_uInt16
getYear() const { return nYear
; };
780 /// adds/subtracts the given count of months, adjusts day
782 /// @throws css::lang::IllegalArgumentException
783 void addMonths( sal_Int32 nMonthCount
);
785 /// sets the given year, adjusts day
786 inline void setYear( sal_uInt16 nNewYear
);
787 /// adds/subtracts the given count of years, adjusts day
789 /// @throws css::lang::IllegalArgumentException
790 inline void addYears( sal_Int32 nYearCount
);
792 /// @return the internal number of the current date
793 sal_Int32
getDate( sal_Int32 nNullDate
) const;
794 /// @return the number of days between the two dates
796 /// @throws css::lang::IllegalArgumentException
797 static sal_Int32
getDiff( const ScaDate
& rFrom
, const ScaDate
& rTo
);
799 bool operator<( const ScaDate
& rCmp
) const;
800 bool operator<=( const ScaDate
& rCmp
) const { return !(rCmp
< *this); }
801 bool operator>( const ScaDate
& rCmp
) const { return rCmp
< *this; }
802 bool operator>=( const ScaDate
& rCmp
) const { return !(*this < rCmp
); }
805 inline sal_uInt16
ScaDate::getDaysInMonth() const
807 return getDaysInMonth( nMonth
);
810 inline sal_uInt16
ScaDate::getDaysInMonth( sal_uInt16 _nMon
) const
812 return b30Days
? 30 : DaysInMonth( _nMon
, nYear
);
815 inline void ScaDate::setYear( sal_uInt16 nNewYear
)
821 inline void ScaDate::addYears( sal_Int32 nYearCount
)
823 doAddYears( nYearCount
);
828 /// Helper class for Any->double conversion, using current language settings
829 class ScaAnyConverter
832 css::uno::Reference
< css::util::XNumberFormatter2
> xFormatter
;
833 sal_Int32 nDefaultFormat
;
834 bool bHasValidFormat
;
836 /** Converts a string to double using the number formatter. If the formatter is not
837 valid, ::rtl::math::stringToDouble() with english separators will be used.
838 @throws css::lang::IllegalArgumentException
839 on strings not representing any double value.
840 @return the converted double value. */
841 double convertToDouble(
842 const OUString
& rString
) const;
845 explicit ScaAnyConverter(
846 const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
849 /// Initializing with current language settings
851 /// @throws css::uno::RuntimeException
853 const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
);
855 /** Converts an Any to double (without initialization).
856 The Any can be empty or contain a double or string.
857 @throws css::lang::IllegalArgumentException
858 on other Any types or on invalid strings.
859 @return true if the Any contains a double or a non-empty valid string,
860 false if the Any is empty or the string is empty */
863 const css::uno::Any
& rAny
) const;
865 /** Converts an Any to double (with initialization).
866 The Any can be empty or contain a double or string.
867 @throws css::lang::IllegalArgumentException
868 on other Any types or on invalid strings.
869 @return true if the Any contains a double or a non-empty valid string,
870 false if the Any is empty or the string is empty */
873 const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
,
874 const css::uno::Any
& rAny
);
876 /** Converts an Any to double (with initialization).
877 The Any can be empty or contain a double or string.
878 @throws css::lang::IllegalArgumentException
879 on other Any types or on invalid strings.
880 @return the value of the double or string or fDefault if the Any or string is empty */
882 const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
,
883 const css::uno::Any
& rAny
,
886 /** Converts an Any to sal_Int32 (with initialization).
887 The Any can be empty or contain a double or string.
888 @throws css::lang::IllegalArgumentException
889 on other Any types or on invalid values or strings.
890 @return true if the Any contains a double or a non-empty valid string,
891 false if the Any is empty or the string is empty */
894 const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
,
895 const css::uno::Any
& rAny
);
897 /** Converts an Any to sal_Int32 (with initialization).
898 The Any can be empty or contain a double or string.
899 @throws css::lang::IllegalArgumentException
900 on other Any types or on invalid values or strings.
901 @return the truncated value of the double or string or nDefault if the Any or string is empty */
903 const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
,
904 const css::uno::Any
& rAny
,
905 sal_Int32 nDefault
);
912 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */