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/lang/XServiceName.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <com/sun/star/util/Date.hpp>
28 #include <com/sun/star/util/XNumberFormatter2.hpp>
29 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
30 #include <com/sun/star/sheet/XAddIn.hpp>
31 #include <com/sun/star/sheet/addin/XAnalysis.hpp>
35 #include <tools/resid.hxx>
36 #include <tools/rc.hxx>
38 #include "analysisdefs.hxx"
43 namespace sca
{ namespace analysis
{
45 class SortedIndividualInt32List
;
46 class ScaAnyConverter
;
49 #define PI 3.1415926535897932
50 #define EOL ( ( const sal_Char* ) 1 )
51 #define EOE ( ( const sal_Char* ) 2 )
54 inline bool IsLeapYear( sal_uInt16 nYear
);
56 #ifdef DISABLE_DYNLOADING
58 // Avoid clash with the functions with same name in
59 // scaddins/source/datefunc/datefunc.cxx. I am not sure if each pair
60 // have identical semantics, but if yes, one copy should be enough,
61 // but what would be a suitable library where such functions could go?
62 // Or can the analysis library depend on the date library or the other
65 #define DaysInMonth analysishelper_DaysInMonth
66 #define DateToDays analysishelper_DateToDays
67 #define DaysToDate analysishelper_DaysToDate
68 #define GetNullDate analysishelper_GetNullDate
72 sal_uInt16
DaysInMonth( sal_uInt16 nMonth
, sal_uInt16 nYear
);
73 sal_Int32
DateToDays( sal_uInt16 nDay
, sal_uInt16 nMonth
, sal_uInt16 nYear
);
74 void DaysToDate( sal_Int32 nDays
, sal_uInt16
& rDay
, sal_uInt16
& rMonth
, sal_uInt16
& rYear
) throw( css::lang::IllegalArgumentException
);
75 sal_Int32
GetNullDate( const css::uno::Reference
< css::beans::XPropertySet
>& xOptions
) throw( css::uno::RuntimeException
);
76 sal_Int32
GetDiffDate360(
77 sal_uInt16 nDay1
, sal_uInt16 nMonth1
, sal_uInt16 nYear1
, bool bLeapYear1
,
78 sal_uInt16 nDay2
, sal_uInt16 nMonth2
, sal_uInt16 nYear2
,
80 inline sal_Int32
GetDiffDate360( const css::uno::Reference
< css::beans::XPropertySet
>& xOpt
, sal_Int32 nDate1
, sal_Int32 nDate2
, bool bUSAMethod
);
81 sal_Int32
GetDiffDate360( sal_Int32 nNullDate
, sal_Int32 nDate1
, sal_Int32 nDate2
, bool bUSAMethod
);
83 sal_Int32
GetDaysInYears( sal_uInt16 nYear1
, sal_uInt16 nYear2
);
84 inline sal_Int16
GetDayOfWeek( sal_Int32 nDate
);
85 sal_Int32
GetDiffDate( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
,
86 sal_Int32
* pOptDaysIn1stYear
= nullptr ) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
87 double GetYearDiff( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
)
88 throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
89 sal_Int32
GetDaysInYear( sal_Int32 nNullDate
, sal_Int32 nDate
, sal_Int32 nMode
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
90 double GetYearFrac( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
)
91 throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
92 inline double GetYearFrac( const css::uno::Reference
< css::beans::XPropertySet
>& xOpt
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
)
93 throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
95 double BinomialCoefficient( double n
, double k
);
96 double GetGcd( double f1
, double f2
);
97 double ConvertToDec( const OUString
& rFromNum
, sal_uInt16 nBaseFrom
, sal_uInt16 nCharLim
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
98 OUString
ConvertFromDec(
99 double fNum
, double fMin
, double fMax
, sal_uInt16 nBase
,
100 sal_Int32 nPlaces
, sal_Int32 nMaxPlaces
, bool bUsePlaces
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
101 double Erf( double fX
);
102 double Erfc( double fX
);
103 bool ParseDouble( const sal_Unicode
*& rpDoubleAsString
, double& rReturn
);
104 OUString
GetString( double fNumber
, bool bLeadingSign
= false, sal_uInt16 nMaxNumOfDigits
= 15 );
106 double GetAmordegrc( sal_Int32 nNullDate
, double fCost
, sal_Int32 nDate
, sal_Int32 nFirstPer
,
107 double fRestVal
, double fPer
, double fRate
, sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
108 double GetAmorlinc( sal_Int32 nNullDate
, double fCost
, sal_Int32 nDate
, sal_Int32 nFirstPer
,
109 double fRestVal
, double fPer
, double fRate
, sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
110 double GetDuration( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, double fCoup
,
111 double fYield
, sal_Int32 nFreq
, sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
112 double GetYieldmat( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nIssue
,
113 double fRate
, double fPrice
, sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
114 double GetOddfprice( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nIssue
,
115 sal_Int32 nFirstCoup
, double fRate
, double fYield
, double fRedemp
,
116 sal_Int32 nFreq
, sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
117 double getYield_( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, double fCoup
, double fPrice
,
118 double fRedemp
, sal_Int32 nFreq
, sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
119 double getPrice_( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, double fRate
, double fYield
,
120 double fRedemp
, sal_Int32 nFreq
, sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
121 double GetOddfyield( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nIssue
,
122 sal_Int32 nFirstCoup
, double fRate
, double fPrice
, double fRedemp
,
123 sal_Int32 nFreq
, sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
124 double GetOddlprice( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nLastInterest
,
125 double fRate
, double fYield
, double fRedemp
, sal_Int32 nFreq
, sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
126 double GetOddlyield( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nLastInterest
,
127 double fRate
, double fPrice
, double fRedemp
, sal_Int32 nFreq
, sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
128 double GetRmz( double fZins
, double fZzr
, double fBw
, double fZw
, sal_Int32 nF
);
129 double GetZw( double fZins
, double fZzr
, double fRmz
, double fBw
, sal_Int32 nF
);
131 double GetCouppcd( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
132 sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
133 double GetCoupncd( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
134 sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
135 double GetCoupdaybs( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
136 sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
137 double GetCoupdaysnc( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
138 sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
140 double GetCoupnum( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
,
141 sal_Int32 nFreq
, sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
142 double GetCoupdays( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
143 sal_Int32 nBase
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
159 const sal_Char
* pIntName
;
160 sal_uInt16 nUINameID
; // resource ID to UI name
161 sal_uInt16 nDescrID
; // resource ID to description, parameter names and ~ description
162 bool bDouble
; // name already exist in Calc
163 bool bWithOpt
; // first parameter is internal
164 sal_uInt16 nCompListID
; // resource ID to list of valid names
165 sal_uInt16 nNumOfParams
; // number of named / described parameters
166 FDCategory eCat
; // function category
167 const char* pSuffix
; // if bDouble, append a suffix other than "_ADD" for UI
175 sal_uInt16 nUINameID
;
176 sal_uInt16 nDescrID
; // leads also to parameter descriptions!
177 bool bDouble
; // flag for names that already exist in Calc
178 bool bWithOpt
; // has internal parameter on first position
180 sal_uInt16 nParam
; // num of parameters
182 std::vector
<OUString
> aCompList
; // list of all valid names
183 FDCategory eCat
; // function category
184 OUString aSuffix
; // if bDouble and not empty, append a suffix other than "_ADD" for UI
187 FuncData( const FuncDataBase
& rBaseData
, ResMgr
& );
190 inline sal_uInt16
GetUINameID() const;
191 inline sal_uInt16
GetDescrID() const;
192 inline bool IsDouble() const;
193 inline const OUString
& GetSuffix() const;
195 sal_uInt16
GetStrIndex( sal_uInt16 nParamNum
) const;
196 inline bool Is( const OUString
& rCompareTo
) const;
198 inline const std::vector
<OUString
> &
199 GetCompNameList() const;
201 inline FDCategory
GetCategory() const;
204 typedef std::vector
< FuncData
> FuncDataList
;
206 void InitFuncDataList ( FuncDataList
& rList
, ResMgr
& rResMgr
);
208 // Predicate for use with std::find_if
211 const OUString
& m_rId
;
212 explicit FindFuncData( const OUString
& rId
) : m_rId(rId
) {}
213 bool operator() ( FuncData
& rCandidate
) const { return rCandidate
.Is(m_rId
); }
216 class AnalysisResId
: public ResId
219 AnalysisResId( sal_uInt16 nId
, ResMgr
& rResMgr
);
223 class AnalysisRscStrLoader
: public Resource
228 AnalysisRscStrLoader( sal_uInt16 nRsc
, sal_uInt16 nStrId
, ResMgr
& rResMgr
) :
229 Resource( AnalysisResId( nRsc
, rResMgr
) ),
230 aStr( AnalysisResId( nStrId
, rResMgr
) )
235 const OUString
& GetString() const { return aStr
; }
240 /// sorted list with unique sal_Int32 values
241 class SortedIndividualInt32List
244 std::vector
<sal_Int32
> maVector
;
246 void Insert( sal_Int32 nDay
);
247 void Insert( sal_Int32 nDay
, sal_Int32 nNullDate
, bool bInsertOnWeekend
);
248 void Insert( double fDay
, sal_Int32 nNullDate
, bool bInsertOnWeekend
)
249 throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
251 /** @param rAnyConv must be an initialized ScaAnyConmverter
252 @param bInsertOnWeekend insertion mode: false = holidays on weekend are omitted */
253 void InsertHolidayList(
254 const ScaAnyConverter
& rAnyConv
,
255 const css::uno::Any
& rHolAny
,
257 bool bInsertOnWeekend
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
260 SortedIndividualInt32List();
261 virtual ~SortedIndividualInt32List();
263 inline sal_uInt32
Count() const
264 { return maVector
.size(); }
266 /// @return element on position nIndex or 0 on invalid index
267 inline sal_Int32
Get( sal_uInt32 n
) const
268 { return maVector
[n
]; }
270 /// @return true if nVal (internal date representation) is contained
271 bool Find( sal_Int32 nVal
) const;
273 /** @param rAnyConv is an initialized or uninitialized ScaAnyConverter
274 holidays on weekend are omitted */
275 void InsertHolidayList(
276 ScaAnyConverter
& rAnyConv
,
277 const css::uno::Reference
< css::beans::XPropertySet
>& xOptions
,
278 const css::uno::Any
& rHolAny
,
279 sal_Int32 nNullDate
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
286 std::vector
<double> maVector
;
288 inline void ListAppend( double fValue
) { maVector
.push_back(fValue
); }
290 inline void Append( double fValue
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
)
291 { if( CheckInsert( fValue
) ) ListAppend( fValue
); }
293 /** @param rAnyConv must be an initialized ScaAnyConmverter
294 @param bIgnoreEmpty handling of empty Any's/strings: false = inserted as 0.0; true = omitted */
296 const ScaAnyConverter
& rAnyConv
,
297 const css::uno::Any
& rAny
,
298 bool bIgnoreEmpty
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
300 /** @param rAnyConv must be an initialized ScaAnyConmverter
301 @param bIgnoreEmpty handling of empty Any's/strings: false = inserted as 0.0; true = omitted */
303 const ScaAnyConverter
& rAnyConv
,
304 const css::uno::Sequence
< css::uno::Any
>& rAnySeq
,
305 bool bIgnoreEmpty
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
307 /** @param rAnyConv must be an initialized ScaAnyConmverter
308 @param bIgnoreEmpty handling of empty Any's/strings: false = inserted as 0.0; true = omitted */
310 const ScaAnyConverter
& rAnyConv
,
311 const css::uno::Sequence
< css::uno::Sequence
< css::uno::Any
> >& rAnySeq
,
312 bool bIgnoreEmpty
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
315 virtual ~ScaDoubleList() {}
317 inline sal_uInt32
Count() const
318 { return maVector
.size(); }
319 inline double Get( sal_uInt32 n
) const
320 { return maVector
[n
]; }
322 void Append( const css::uno::Sequence
< css::uno::Sequence
< double > >& rValueArr
)
323 throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
324 void Append( const css::uno::Sequence
< css::uno::Sequence
< sal_Int32
> >& rValueArr
)
325 throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
327 /** @param rAnyConv is an initialized or uninitialized ScaAnyConverter
328 @param bIgnoreEmpty handling of empty Any's/strings: false = inserted as 0.0; true = omitted */
330 ScaAnyConverter
& rAnyConv
,
331 const css::uno::Reference
< css::beans::XPropertySet
>& xOpt
,
332 const css::uno::Sequence
< css::uno::Any
>& rAnySeq
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
334 virtual bool CheckInsert( double fValue
) const
335 throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
339 /// stores double values >0.0, throws exception for double values <0.0, does nothing for 0.0
340 class ScaDoubleListGT0
: public ScaDoubleList
343 virtual bool CheckInsert( double fValue
) const
344 throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
) override
;
348 /// stores double values >=0.0, throws exception for double values <0.0
349 class ScaDoubleListGE0
: public ScaDoubleList
352 virtual bool CheckInsert( double fValue
) const
353 throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
) override
;
364 inline Complex( double fReal
, double fImag
= 0.0, sal_Unicode cC
= '\0' );
365 explicit Complex( const OUString
& rComplexAsString
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
367 inline static bool IsImagUnit( sal_Unicode c
);
368 static bool ParseString( const OUString
& rComplexAsString
, Complex
& rReturn
);
369 OUString
GetString() const throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
371 inline double Real() const;
372 inline double Imag() const;
374 double Arg() const throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
375 inline double Abs() const;
377 // following functions change the complex number itself to avoid unnecessary copy actions!
378 void Power( double fPower
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
380 void Sin() throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
381 void Cos() throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
382 void Div( const Complex
& rDivisor
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
384 inline void Conjugate();
385 void Ln() throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
386 void Log10() throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
387 void Log2() throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
388 inline void Mult( double fFact
);
389 inline void Mult( const Complex
& rMult
);
390 inline void Sub( const Complex
& rMult
);
391 inline void Add( const Complex
& rAdd
);
392 void Tan() throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
393 void Sec() throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
394 void Csc() throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
395 void Cot() throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
396 void Sinh() throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
397 void Cosh() throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
398 void Sech() throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
399 void Csch() throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
404 enum ComplListAppendHandl
415 std::vector
<Complex
*> maVector
;
417 virtual ~ComplexList();
419 inline const Complex
* Get( sal_uInt32 nIndex
) const;
421 inline bool empty() const
422 { return maVector
.empty(); }
423 inline sal_uInt32
Count() const
424 { return maVector
.size(); }
426 inline void Append( Complex
* pNew
);
427 void Append( const css::uno::Sequence
< css::uno::Sequence
< OUString
> >& rComplexNumList
, ComplListAppendHandl eAH
= AH_EmpyAs0
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
428 void Append( const css::uno::Sequence
< css::uno::Any
>& aMultPars
,ComplListAppendHandl eAH
= AH_EmpyAs0
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
432 enum ConvertDataClass
434 CDC_Mass
, CDC_Length
, CDC_Time
, CDC_Pressure
, CDC_Force
, CDC_Energy
, CDC_Power
, CDC_Magnetism
,
435 CDC_Temperature
, CDC_Volume
, CDC_Area
, CDC_Speed
, CDC_Information
439 #define INV_MATCHLEV 1764 // guess, what this is... :-)
442 class ConvertDataList
;
447 friend class ConvertDataList
;
450 ConvertDataClass eClass
;
454 const sal_Char pUnitName
[],
455 double fConvertConstant
,
456 ConvertDataClass eClass
,
457 bool bPrefSupport
= false );
459 virtual ~ConvertData();
461 sal_Int16
GetMatchingLevel( const OUString
& rRef
) const;
463 // 1.0 = matches exact
464 // rest = matches without an assumed prefix of one character
465 // rest gives power for 10 represented by the prefix (e.g. 3 for k or -9 for n
467 virtual double Convert( double fVal
, const ConvertData
& rTo
,
468 sal_Int16 nMatchLevelFrom
, sal_Int16 nMatchLevelTo
) const throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
469 // converts fVal from this unit to rFrom unit
470 // throws exception if not from same class
471 // this implementation is for proportional cases only
472 virtual double ConvertToBase( double fVal
, sal_Int16 nMatchLevel
) const;
473 virtual double ConvertFromBase( double fVal
, sal_Int16 nMatchLevel
) const;
475 inline ConvertDataClass
Class() const;
476 inline bool IsPrefixSupport() const;
479 class ConvertDataLinear
: public ConvertData
484 inline ConvertDataLinear(
485 const sal_Char pUnitName
[],
486 double fConvertConstant
,
487 double fConvertOffset
,
488 ConvertDataClass eClass
,
489 bool bPrefSupport
= false );
491 virtual ~ConvertDataLinear();
493 virtual double Convert( double fVal
, const ConvertData
& rTo
,
494 sal_Int16 nMatchLevelFrom
, sal_Int16 nMatchLevelTo
) const throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
) override
;
495 // for cases where f(x) = a + bx applies (e.g. Temperatures)
497 virtual double ConvertToBase( double fVal
, sal_Int16 nMatchLevel
) const override
;
498 virtual double ConvertFromBase( double fVal
, sal_Int16 nMatchLevel
) const override
;
502 class ConvertDataList
505 std::vector
<ConvertData
*> maVector
;
508 virtual ~ConvertDataList();
510 double Convert( double fVal
, const OUString
& rFrom
, const OUString
& rTo
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
514 inline bool IsLeapYear( sal_uInt16 n
)
516 return ( (( ( n
% 4 ) == 0 ) && ( ( n
% 100 ) != 0)) || ( ( n
% 400 ) == 0 ) );
520 inline sal_Int32
GetDiffDate360( const css::uno::Reference
< css::beans::XPropertySet
>& xOpt
, sal_Int32 nDate1
, sal_Int32 nDate2
, bool bUSAMethod
)
522 return GetDiffDate360( GetNullDate( xOpt
), nDate1
, nDate2
, bUSAMethod
);
526 inline sal_Int16
GetDayOfWeek( sal_Int32 n
)
527 { // monday = 0, ..., sunday = 6
528 return static_cast< sal_Int16
>( ( n
- 1 ) % 7 );
532 inline double GetYearFrac( const css::uno::Reference
< css::beans::XPropertySet
>& xOpt
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
)
534 return GetYearFrac( GetNullDate( xOpt
), nStartDate
, nEndDate
, nMode
);
538 inline sal_uInt16
FuncData::GetUINameID() const
544 inline sal_uInt16
FuncData::GetDescrID() const
550 inline bool FuncData::IsDouble() const
556 inline const OUString
& FuncData::GetSuffix() const
562 inline bool FuncData::Is( const OUString
& r
) const
564 return aIntName
== r
;
568 inline const std::vector
<OUString
> & FuncData::GetCompNameList() const
574 inline FDCategory
FuncData::GetCategory() const
580 inline Complex::Complex( double fReal
, double fImag
, sal_Unicode cC
) :
581 r( fReal
), i( fImag
), c( cC
)
586 inline double Complex::Real() const
592 inline double Complex::Imag() const
598 inline double Complex::Abs() const
600 return sqrt( r
* r
+ i
* i
);
604 void Complex::Conjugate()
610 inline void Complex::Mult( double f
)
617 inline void Complex::Mult( const Complex
& rM
)
622 r
= r_
* rM
.r
- i_
* rM
.i
;
623 i
= r_
* rM
.i
+ i_
* rM
.r
;
629 inline void Complex::Sub( const Complex
& rC
)
637 inline void Complex::Add( const Complex
& rAdd
)
645 inline const Complex
* ComplexList::Get( sal_uInt32 n
) const
651 inline void ComplexList::Append( Complex
* p
)
653 maVector
.push_back(p
);
657 inline ConvertDataClass
ConvertData::Class() const
662 inline bool ConvertData::IsPrefixSupport() const
664 return bPrefixSupport
;
667 inline ConvertDataLinear::ConvertDataLinear( const sal_Char
* p
, double fC
, double fO
, ConvertDataClass e
,
668 bool bPrefSupport
) :
669 ConvertData( p
, fC
, e
, bPrefSupport
),
675 /// Helper class for date calculation for various financial functions
679 sal_uInt16 nOrigDay
; /// is the day of the original date.
680 sal_uInt16 nDay
; /// is the calculated day depending on the current month/year.
681 sal_uInt16 nMonth
; /// is the current month (one-based).
682 sal_uInt16 nYear
; /// is the current year.
683 bool bLastDayMode
: 1; /// if true, recalculate nDay after every calculation.
684 bool bLastDay
: 1; /// is true, if original date was the last day in month.
685 bool b30Days
: 1; /// is true, if every month has 30 days in calculations.
686 bool bUSMode
: 1; /// is true, if the US method of 30-day-calculations is used.
688 /// Calculates nDay from nOrigDay and current date.
691 /// @return count of days in current month
692 inline sal_uInt16
getDaysInMonth() const;
693 /// @return count of days in given month
694 inline sal_uInt16
getDaysInMonth( sal_uInt16 _nMon
) const;
696 /// @ return count of days in the given month range
697 sal_Int32
getDaysInMonthRange( sal_uInt16 nFrom
, sal_uInt16 nTo
) const;
698 /// @ return count of days in the given year range
699 sal_Int32
getDaysInYearRange( sal_uInt16 nFrom
, sal_uInt16 nTo
) const;
701 /// Adds/subtracts the given count of years, does not adjust day.
702 void doAddYears( sal_Int32 nYearCount
) throw( css::lang::IllegalArgumentException
);
707 date handling mode (days in month / days in year):
708 0 = 30 days / 360 days (US NASD)
712 4 = 30 days / 360 days (Europe)
713 5 = exact / exact (no last day adjustment) */
714 ScaDate( sal_Int32 nNullDate
, sal_Int32 nDate
, sal_Int32 nBase
);
715 ScaDate( const ScaDate
& rCopy
);
716 ScaDate
& operator=( const ScaDate
& rCopy
);
718 /// @return the current month.
719 inline sal_uInt16
getMonth() const { return nMonth
; };
720 /// @return the current year.
721 inline sal_uInt16
getYear() const { return nYear
; };
723 /// adds/subtracts the given count of months, adjusts day
724 void addMonths( sal_Int32 nMonthCount
) throw( css::lang::IllegalArgumentException
);
726 /// sets the given year, adjusts day
727 inline void setYear( sal_uInt16 nNewYear
);
728 /// adds/subtracts the given count of years, adjusts day
729 inline void addYears( sal_Int32 nYearCount
) throw( css::lang::IllegalArgumentException
);
731 /// @return the internal number of the current date
732 sal_Int32
getDate( sal_Int32 nNullDate
) const;
733 /// @return the number of days between the two dates
734 static sal_Int32
getDiff( const ScaDate
& rFrom
, const ScaDate
& rTo
) throw( css::lang::IllegalArgumentException
);
736 bool operator<( const ScaDate
& rCmp
) const;
737 inline bool operator<=( const ScaDate
& rCmp
) const { return !(rCmp
< *this); }
738 inline bool operator>( const ScaDate
& rCmp
) const { return rCmp
< *this; }
739 inline bool operator>=( const ScaDate
& rCmp
) const { return !(*this < rCmp
); }
742 inline sal_uInt16
ScaDate::getDaysInMonth() const
744 return getDaysInMonth( nMonth
);
747 inline sal_uInt16
ScaDate::getDaysInMonth( sal_uInt16 _nMon
) const
749 return b30Days
? 30 : DaysInMonth( _nMon
, nYear
);
752 inline void ScaDate::setYear( sal_uInt16 nNewYear
)
758 inline void ScaDate::addYears( sal_Int32 nYearCount
) throw( css::lang::IllegalArgumentException
)
760 doAddYears( nYearCount
);
765 /// Helper class for Any->double conversion, using current language settings
766 class ScaAnyConverter
769 css::uno::Reference
< css::util::XNumberFormatter2
> xFormatter
;
770 sal_Int32 nDefaultFormat
;
771 bool bHasValidFormat
;
773 /** Converts a string to double using the number formatter. If the formatter is not
774 valid, ::rtl::math::stringToDouble() with english separators will be used.
775 @throws css::lang::IllegalArgumentException
776 on strings not representing any double value.
777 @return the converted double value. */
778 double convertToDouble(
779 const OUString
& rString
) const
780 throw( css::lang::IllegalArgumentException
);
783 explicit ScaAnyConverter(
784 const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
787 /// Initializing with current language settings
789 const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
)
790 throw( css::uno::RuntimeException
);
792 /** Converts an Any to double (without initialization).
793 The Any can be empty or contain a double or string.
794 @throws css::lang::IllegalArgumentException
795 on other Any types or on invalid strings.
796 @return true if the Any contains a double or a non-empty valid string,
797 false if the Any is empty or the string is empty */
800 const css::uno::Any
& rAny
) const
801 throw( css::lang::IllegalArgumentException
);
803 /** Converts an Any to double (with initialization).
804 The Any can be empty or contain a double or string.
805 @throws css::lang::IllegalArgumentException
806 on other Any types or on invalid strings.
807 @return true if the Any contains a double or a non-empty valid string,
808 false if the Any is empty or the string is empty */
811 const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
,
812 const css::uno::Any
& rAny
)
813 throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
815 /** Converts an Any to double (with initialization).
816 The Any can be empty or contain a double or string.
817 @throws css::lang::IllegalArgumentException
818 on other Any types or on invalid strings.
819 @return the value of the double or string or fDefault if the Any or string is empty */
821 const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
,
822 const css::uno::Any
& rAny
,
824 throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
826 /** Converts an Any to sal_Int32 (with initialization).
827 The Any can be empty or contain a double or string.
828 @throws css::lang::IllegalArgumentException
829 on other Any types or on invalid values or strings.
830 @return true if the Any contains a double or a non-empty valid string,
831 false if the Any is empty or the string is empty */
834 const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
,
835 const css::uno::Any
& rAny
)
836 throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
838 /** Converts an Any to sal_Int32 (with initialization).
839 The Any can be empty or contain a double or string.
840 @throws css::lang::IllegalArgumentException
841 on other Any types or on invalid values or strings.
842 @return the truncated value of the double or string or nDefault if the Any or string is empty */
844 const css::uno::Reference
< css::beans::XPropertySet
>& xPropSet
,
845 const css::uno::Any
& rAny
,
847 throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
);
854 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */