1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: analysishelper.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef ANALYSISHELPER_HXX
31 #define ANALYSISHELPER_HXX
34 #include <com/sun/star/lang/XServiceName.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/util/Date.hpp>
38 #include <com/sun/star/util/XNumberFormatter.hpp>
39 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
40 #include <com/sun/star/sheet/XAddIn.hpp>
41 #include <com/sun/star/sheet/addin/XAnalysis.hpp>
45 #include <tools/resid.hxx>
46 #include <tools/rc.hxx>
48 #include "analysisdefs.hxx"
52 class SortedIndividualInt32List
;
53 class ScaAnyConverter
;
56 #define PI 3.1415926535897932
58 //#define EULER 2.7182818284590452
59 #define EOL ( ( const sal_Char* ) 1 )
60 #define EOE ( ( const sal_Char* ) 2 )
63 //double _Test( sal_Int32 nMode, double f1, double f2, double f3 );
64 inline sal_Bool
IsLeapYear( sal_uInt16 nYear
);
65 sal_uInt16
DaysInMonth( sal_uInt16 nMonth
, sal_uInt16 nYear
);
66 sal_Int32
DateToDays( sal_uInt16 nDay
, sal_uInt16 nMonth
, sal_uInt16 nYear
);
67 void DaysToDate( sal_Int32 nDays
, sal_uInt16
& rDay
, sal_uInt16
& rMonth
, sal_uInt16
& rYear
) throw( ::com::sun::star::lang::IllegalArgumentException
);
68 sal_Int32
GetNullDate( const REF( CSS::beans::XPropertySet
)& xOptions
) THROWDEF_RTE
;
69 sal_Int32
GetDiffDate360(
70 sal_uInt16 nDay1
, sal_uInt16 nMonth1
, sal_uInt16 nYear1
, sal_Bool bLeapYear1
,
71 sal_uInt16 nDay2
, sal_uInt16 nMonth2
, sal_uInt16 nYear2
,
72 sal_Bool bUSAMethod
);
73 inline sal_Int32
GetDiffDate360( constREFXPS
& xOpt
, sal_Int32 nDate1
, sal_Int32 nDate2
, sal_Bool bUSAMethod
);
74 sal_Int32
GetDiffDate360( sal_Int32 nNullDate
, sal_Int32 nDate1
, sal_Int32 nDate2
, sal_Bool bUSAMethod
);
76 sal_Int32
GetDaysInYears( sal_uInt16 nYear1
, sal_uInt16 nYear2
);
77 inline sal_Int16
GetDayOfWeek( sal_Int32 nDate
);
78 void GetDiffParam( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
,
79 sal_uInt16
& rYears
, sal_Int32
& rDayDiffPart
, sal_Int32
& rDaysInYear
) THROWDEF_RTE_IAE
;
80 // rYears = full num of years
81 // rDayDiffPart = num of days for last year
82 // rDaysInYear = num of days in first year
83 sal_Int32
GetDiffDate( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
,
84 sal_Int32
* pOptDaysIn1stYear
= NULL
) THROWDEF_RTE_IAE
;
85 double GetYearDiff( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
)
87 sal_Int32
GetDaysInYear( sal_Int32 nNullDate
, sal_Int32 nDate
, sal_Int32 nMode
) THROWDEF_RTE_IAE
;
88 double GetYearFrac( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
)
90 inline double GetYearFrac( constREFXPS
& xOpt
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
)
92 inline void AlignDate( sal_uInt16
& rDay
, sal_uInt16 nMonth
, sal_uInt16 nYear
);
94 double Fak( sal_Int32 n
);
95 double GetGcd( double f1
, double f2
);
96 double ConvertToDec( const STRING
& rFromNum
, sal_uInt16 nBaseFrom
, sal_uInt16 nCharLim
) THROWDEF_RTE_IAE
;
97 STRING
ConvertFromDec(
98 double fNum
, double fMin
, double fMax
, sal_uInt16 nBase
,
99 sal_Int32 nPlaces
, sal_Int32 nMaxPlaces
, sal_Bool bUsePlaces
) THROWDEF_RTE_IAE
;
100 double Erf( double fX
);
101 double Erfc( double fX
);
102 sal_Bool
ParseDouble( const sal_Unicode
*& rpDoubleAsString
, double& rReturn
);
103 STRING
GetString( double fNumber
, sal_Bool bLeadingSign
= sal_False
, sal_uInt16 nMaxNumOfDigits
= 15 );
104 inline double Exp10( sal_Int16 nPower
); // 10 ^ nPower
106 double GetAmordegrc( sal_Int32 nNullDate
, double fCost
, sal_Int32 nDate
, sal_Int32 nFirstPer
,
107 double fRestVal
, double fPer
, double fRate
, sal_Int32 nBase
) THROWDEF_RTE_IAE
;
108 double GetAmorlinc( sal_Int32 nNullDate
, double fCost
, sal_Int32 nDate
, sal_Int32 nFirstPer
,
109 double fRestVal
, double fPer
, double fRate
, sal_Int32 nBase
) THROWDEF_RTE_IAE
;
110 double GetDuration( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, double fCoup
,
111 double fYield
, sal_Int32 nFreq
, sal_Int32 nBase
) THROWDEF_RTE_IAE
;
112 double GetYieldmat( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nIssue
,
113 double fRate
, double fPrice
, sal_Int32 nBase
) THROWDEF_RTE_IAE
;
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
) THROWDEF_RTE_IAE
;
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
) THROWDEF_RTE_IAE
;
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
) THROWDEF_RTE_IAE
;
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
) THROWDEF_RTE_IAE
;
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
) THROWDEF_RTE_IAE
;
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
) THROWDEF_RTE_IAE
;
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
);
130 //double TBillYield( constREFXPS& xOpt, sal_Int32 nSettle, sal_Int32 nMat, double fPrice )THROWDEF_RTE_IAE;
132 double GetCouppcd( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
133 sal_Int32 nBase
) THROWDEF_RTE_IAE
;
134 double GetCoupncd( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
135 sal_Int32 nBase
) THROWDEF_RTE_IAE
;
136 double GetCoupdaybs( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
137 sal_Int32 nBase
) THROWDEF_RTE_IAE
;
138 double GetCoupdaysnc( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
139 sal_Int32 nBase
) THROWDEF_RTE_IAE
;
141 double GetCoupnum( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
,
142 sal_Int32 nFreq
, sal_Int32 nBase
) THROWDEF_RTE_IAE
;
143 double GetCoupdays( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
144 sal_Int32 nBase
) THROWDEF_RTE_IAE
;
149 //-----------------------------------------------------------------------------
156 static const sal_uInt32 nStartSize
;
157 static const sal_uInt32 nIncrSize
;
159 void** pData
; // pointer array
160 sal_uInt32 nSize
; // array size
161 sal_uInt32 nNew
; // next index to be inserted at
162 sal_uInt32 nAct
; // actual for iterations
165 inline void Grow( void );
171 inline const void* GetObject( sal_uInt32 nIndex
) const;
172 inline const void* First( void );
173 inline const void* Next( void );
175 inline void Append( void* pNewElement
);
176 void Insert( void* pNewLement
, sal_uInt32 nPlace
);
178 inline sal_uInt32
Count( void ) const;
184 class StringList
: protected MyList
187 virtual ~StringList();
189 inline const STRING
* First( void );
190 inline const STRING
* Next( void );
191 inline const STRING
* Get( sal_uInt32 nIndex
) const;
193 using MyList::Append
;
194 inline void Append( STRING
* pNew
);
195 inline void Append( const STRING
& rNew
);
216 const sal_Char
* pIntName
;
217 sal_uInt16 nUINameID
; // resource ID to UI name
218 sal_uInt16 nDescrID
; // resource ID to description, parameter names and ~ description
219 sal_Bool bDouble
; // name already exist in Calc
220 sal_Bool bWithOpt
; // first parameter is internal
221 sal_uInt16 nCompListID
; // resource ID to list of valid names
222 sal_uInt16 nNumOfParams
; // number of named / described parameters
223 FDCategory eCat
; // function category
232 ::rtl::OUString aIntName
;
233 sal_uInt16 nUINameID
;
234 sal_uInt16 nDescrID
; // leads also to parameter descriptions!
235 sal_Bool bDouble
; // flag for names, wich already exist in Calc
236 sal_Bool bWithOpt
; // has internal parameter on first position
238 sal_uInt16 nParam
; // num of parameters
240 StringList aCompList
; // list of all valid names
241 FDCategory eCat
; // function category
243 FuncData( const FuncDataBase
& rBaseData
, ResMgr
& );
246 inline sal_uInt16
GetUINameID( void ) const;
247 inline sal_uInt16
GetDescrID( void ) const;
248 inline sal_Bool
IsDouble( void ) const;
249 inline sal_Bool
HasIntParam( void ) const;
251 sal_uInt16
GetStrIndex( sal_uInt16 nParamNum
) const;
252 inline sal_Bool
Is( const ::rtl::OUString
& rCompareTo
) const;
254 inline const StringList
& GetCompNameList( void ) const;
256 inline FDCategory
GetCategory( void ) const;
262 class CStrList
: private MyList
265 using MyList::Append
;
266 inline void Append( const sal_Char
* pNew
);
267 inline const sal_Char
* Get( sal_uInt32 nIndex
) const;
274 class FuncDataList
: private MyList
276 ::rtl::OUString aLastName
;
279 FuncDataList( ResMgr
& );
280 virtual ~FuncDataList();
281 using MyList::Append
;
282 inline void Append( FuncData
* pNew
);
283 inline const FuncData
* Get( sal_uInt32 nIndex
) const;
286 const FuncData
* Get( const ::rtl::OUString
& aProgrammaticName
) const;
291 class AnalysisResId
: public ResId
294 AnalysisResId( sal_uInt16 nId
, ResMgr
& rResMgr
);
300 class AnalysisRscStrLoader
: public Resource
305 AnalysisRscStrLoader( sal_uInt16 nRsc
, sal_uInt16 nStrId
, ResMgr
& rResMgr
) :
306 Resource( AnalysisResId( nRsc
, rResMgr
) ),
307 aStr( AnalysisResId( nStrId
, rResMgr
) )
312 const String
& GetString() const { return aStr
; }
318 //-----------------------------------------------------------------------------
320 /// sorted list with unique sal_Int32 values
321 class SortedIndividualInt32List
: private MyList
324 using MyList::Insert
;
325 void Insert( sal_Int32 nDay
);
326 void Insert( sal_Int32 nDay
, sal_Int32 nNullDate
, sal_Bool bInsertOnWeekend
);
327 void Insert( double fDay
, sal_Int32 nNullDate
, sal_Bool bInsertOnWeekend
)
328 throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
330 /** @param rAnyConv must be an initialized ScaAnyConmverter
331 @param bInsertOnWeekend insertion mode: sal_False = holidays on weekend are omitted */
332 void InsertHolidayList(
333 const ScaAnyConverter
& rAnyConv
,
334 const CSS::uno::Any
& rHolAny
,
336 sal_Bool bInsertOnWeekend
) throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
339 SortedIndividualInt32List();
340 virtual ~SortedIndividualInt32List();
344 /// @return element on position nIndex or 0 on invalid index
345 inline sal_Int32
Get( sal_uInt32 nIndex
) const
346 { return (sal_Int32
)(sal_IntPtr
) MyList::GetObject( nIndex
); }
348 /// @return sal_True if nVal (internal date representation) is contained
349 sal_Bool
Find( sal_Int32 nVal
) const;
351 /** @param rAnyConv is an initialized or uninitialized ScaAnyConverter
352 @param bInsertOnWeekend insertion mode: sal_False = holidays on weekend are omitted */
353 void InsertHolidayList(
354 ScaAnyConverter
& rAnyConv
,
355 const CSS::uno::Reference
< CSS::beans::XPropertySet
>& xOptions
,
356 const CSS::uno::Any
& rHolAny
,
358 sal_Bool bInsertOnWeekend
) throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
362 //-----------------------------------------------------------------------------
364 class ScaDoubleList
: protected MyList
367 inline void ListAppend( double fValue
) { MyList::Append( new double( fValue
) ); }
369 using MyList::Append
;
370 inline void Append( double fValue
) throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
)
371 { if( CheckInsert( fValue
) ) ListAppend( fValue
); }
373 /** @param rAnyConv must be an initialized ScaAnyConmverter
374 @param bIgnoreEmpty handling of empty Any's/strings: sal_False = inserted as 0.0; sal_True = omitted */
376 const ScaAnyConverter
& rAnyConv
,
377 const CSS::uno::Any
& rAny
,
378 sal_Bool bIgnoreEmpty
) throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
380 /** @param rAnyConv must be an initialized ScaAnyConmverter
381 @param bIgnoreEmpty handling of empty Any's/strings: sal_False = inserted as 0.0; sal_True = omitted */
383 const ScaAnyConverter
& rAnyConv
,
384 const CSS::uno::Sequence
< CSS::uno::Any
>& rAnySeq
,
385 sal_Bool bIgnoreEmpty
) throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
387 /** @param rAnyConv must be an initialized ScaAnyConmverter
388 @param bIgnoreEmpty handling of empty Any's/strings: sal_False = inserted as 0.0; sal_True = omitted */
390 const ScaAnyConverter
& rAnyConv
,
391 const CSS::uno::Sequence
< CSS::uno::Sequence
< CSS::uno::Any
> >& rAnySeq
,
392 sal_Bool bIgnoreEmpty
) throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
395 virtual ~ScaDoubleList();
398 inline const double* Get( sal_uInt32 nIndex
) const
399 { return static_cast< const double* >( MyList::GetObject( nIndex
) ); }
401 inline const double* First() { return static_cast< const double* >( MyList::First() ); }
402 inline const double* Next() { return static_cast< const double* >( MyList::Next() ); }
404 void Append( const CSS::uno::Sequence
< CSS::uno::Sequence
< double > >& rValueArr
)
405 throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
406 void Append( const CSS::uno::Sequence
< CSS::uno::Sequence
< sal_Int32
> >& rValueArr
)
407 throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
409 /** @param rAnyConv is an initialized or uninitialized ScaAnyConverter
410 @param bIgnoreEmpty handling of empty Any's/strings: sal_False = inserted as 0.0; sal_True = omitted */
412 ScaAnyConverter
& rAnyConv
,
413 const CSS::uno::Reference
< CSS::beans::XPropertySet
>& xOpt
,
414 const CSS::uno::Sequence
< CSS::uno::Any
>& rAnySeq
,
415 sal_Bool bIgnoreEmpty
= sal_True
) throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
417 virtual sal_Bool
CheckInsert( double fValue
) const
418 throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
422 //-----------------------------------------------------------------------------
424 /// stores double values >0.0, throws exception for double values <0.0, does nothing for 0.0
425 class ScaDoubleListGT0
: public ScaDoubleList
428 virtual sal_Bool
CheckInsert( double fValue
) const
429 throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
433 //-----------------------------------------------------------------------------
435 /// stores double values >=0.0, throws exception for double values <0.0
436 class ScaDoubleListGE0
: public ScaDoubleList
439 virtual sal_Bool
CheckInsert( double fValue
) const
440 throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
444 //-----------------------------------------------------------------------------
453 inline Complex( double fReal
, double fImag
= 0.0, sal_Char cC
= '\0' );
454 Complex( const STRING
& rComplexAsString
) THROWDEF_RTE_IAE
;
456 inline static sal_Bool
IsImagUnit( sal_Unicode c
);
457 static sal_Bool
ParseString( const STRING
& rComplexAsString
, Complex
& rReturn
);
458 STRING
GetString() const THROWDEF_RTE_IAE
;
460 inline double Real( void ) const;
461 inline double Imag( void ) const;
463 double Arg( void ) const THROWDEF_RTE_IAE
;
464 inline double Abs( void ) const;
466 // following functions change the complex number itself to avoid unnecessary copy actions!
467 void Power( double fPower
) THROWDEF_RTE_IAE
;
469 void Sin( void ) THROWDEF_RTE_IAE
;
470 void Cos( void ) THROWDEF_RTE_IAE
;
471 void Div( const Complex
& rDivisor
) THROWDEF_RTE_IAE
;
473 inline void Conjugate( void );
474 void Ln( void ) THROWDEF_RTE_IAE
;
475 void Log10( void ) THROWDEF_RTE_IAE
;
476 void Log2( void ) THROWDEF_RTE_IAE
;
477 inline void Mult( double fFact
);
478 inline void Mult( const Complex
& rMult
);
479 inline void Sub( const Complex
& rMult
);
480 inline void Add( const Complex
& rAdd
);
486 enum ComplListAppendHandl
494 class ComplexList
: protected MyList
497 virtual ~ComplexList();
499 inline const Complex
* Get( sal_uInt32 nIndex
) const;
500 inline const Complex
* First( void );
501 inline const Complex
* Next( void );
505 using MyList::Append
;
506 inline void Append( Complex
* pNew
);
507 void Append( const SEQSEQ( STRING
)& rComplexNumList
, ComplListAppendHandl eAH
= AH_EmpyAs0
) THROWDEF_RTE_IAE
;
508 void Append( const SEQ( ANY
)& aMultPars
,ComplListAppendHandl eAH
= AH_EmpyAs0
) THROWDEF_RTE_IAE
;
514 enum ConvertDataClass
516 CDC_Mass
, CDC_Length
, CDC_Time
, CDC_Pressure
, CDC_Force
, CDC_Energy
, CDC_Power
, CDC_Magnetism
,
517 CDC_Temperature
, CDC_Volume
, CDC_Area
, CDC_Speed
521 #define INV_MATCHLEV 1764 // guess, what this is... :-)
524 class ConvertDataList
;
532 friend class ConvertDataList
;
535 ConvertDataClass eClass
;
538 const sal_Char pUnitName
[],
539 double fConvertConstant
,
540 ConvertDataClass eClass
);
542 virtual ~ConvertData();
544 sal_Int16
GetMatchingLevel( const STRING
& rRef
) const;
546 // 1.0 = matches exact
547 // rest = matches without an assumed prefix of one character
548 // rest gives power for 10 represented by the prefix (e.g. 3 for k or -9 for n
550 virtual double Convert( double fVal
, const ConvertData
& rTo
,
551 sal_Int16 nMatchLevelFrom
, sal_Int16 nMatchLevelTo
) const THROWDEF_RTE_IAE
;
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 virtual double ConvertToBase( double fVal
, sal_Int16 nMatchLevel
) const;
556 virtual double ConvertFromBase( double fVal
, sal_Int16 nMatchLevel
) const;
558 inline ConvertDataClass
Class( void ) const;
564 class ConvertDataLinear
: public ConvertData
569 inline ConvertDataLinear(
570 const sal_Char pUnitName
[],
571 double fConvertConstant
,
572 double fConvertOffset
,
573 ConvertDataClass eClass
);
575 virtual ~ConvertDataLinear();
577 virtual double Convert( double fVal
, const ConvertData
& rTo
,
578 sal_Int16 nMatchLevelFrom
, sal_Int16 nMatchLevelTo
) const THROWDEF_RTE_IAE
;
579 // for cases where f(x) = a + bx applies (e.g. Temperatures)
581 virtual double ConvertToBase( double fVal
, sal_Int16 nMatchLevel
) const;
582 virtual double ConvertFromBase( double fVal
, sal_Int16 nMatchLevel
) const;
588 class ConvertDataList
: protected MyList
592 inline ConvertData
* First( void );
593 inline ConvertData
* Next( void );
595 ConvertDataList( void );
596 virtual ~ConvertDataList();
598 double Convert( double fVal
, const STRING
& rFrom
, const STRING
& rTo
) THROWDEF_RTE_IAE
;
604 inline sal_Bool
IsLeapYear( sal_uInt16 n
)
606 return ( (( ( n
% 4 ) == 0 ) && ( ( n
% 100 ) != 0)) || ( ( n
% 400 ) == 0 ) );
610 inline sal_Int32
GetDiffDate360( constREFXPS
& xOpt
, sal_Int32 nDate1
, sal_Int32 nDate2
, sal_Bool bUSAMethod
)
612 return GetDiffDate360( GetNullDate( xOpt
), nDate1
, nDate2
, bUSAMethod
);
616 inline sal_Int16
GetDayOfWeek( sal_Int32 n
)
617 { // monday = 0, ..., sunday = 6
618 return static_cast< sal_Int16
>( ( n
- 1 ) % 7 );
622 inline double GetYearFrac( constREFXPS
& xOpt
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
) THROWDEF_RTE_IAE
624 return GetYearFrac( GetNullDate( xOpt
), nStartDate
, nEndDate
, nMode
);
628 inline void AlignDate( sal_uInt16
& rD
, sal_uInt16 nM
, sal_uInt16 nY
)
630 sal_uInt16 nMax
= DaysInMonth( nM
, nY
);
637 inline void MyList::Grow( void )
644 inline const void* MyList::GetObject( sal_uInt32 n
) const
653 inline const void* MyList::First( void )
663 inline const void* MyList::Next( void )
667 return pData
[ nAct
];
676 inline void MyList::Append( void* p
)
684 inline sal_uInt32
MyList::Count( void ) const
692 inline const STRING
* StringList::First( void )
694 return ( const STRING
* ) MyList::First();
698 inline const STRING
* StringList::Next( void )
700 return ( const STRING
* ) MyList::Next();
704 inline const STRING
* StringList::Get( sal_uInt32 n
) const
706 return ( const STRING
* ) MyList::GetObject( n
);
710 inline void StringList::Append( STRING
* p
)
716 inline void StringList::Append( const STRING
& r
)
718 MyList::Append( new STRING( r
) );
724 inline sal_uInt16
FuncData::GetUINameID( void ) const
730 inline sal_uInt16
FuncData::GetDescrID( void ) const
736 inline sal_Bool
FuncData::IsDouble( void ) const
742 inline sal_Bool
FuncData::HasIntParam( void ) const
748 inline sal_Bool
FuncData::Is( const ::rtl::OUString
& r
) const
750 return aIntName
== r
;
754 inline const StringList
& FuncData::GetCompNameList( void ) const
760 inline FDCategory
FuncData::GetCategory( void ) const
768 inline void CStrList::Append( const sal_Char
* p
)
770 MyList::Append( ( void* ) p
);
774 inline const sal_Char
* CStrList::Get( sal_uInt32 n
) const
776 return ( const sal_Char
* ) MyList::GetObject( n
);
782 inline void FuncDataList::Append( FuncData
* p
)
788 inline const FuncData
* FuncDataList::Get( sal_uInt32 n
) const
790 return ( const FuncData
* ) MyList::GetObject( n
);
794 inline Complex::Complex( double fReal
, double fImag
, sal_Char cC
) :
795 r( fReal
), i( fImag
), c( cC
)
800 inline double Complex::Real( void ) const
806 inline double Complex::Imag( void ) const
812 inline double Complex::Abs( void ) const
814 return sqrt( r
* r
+ i
* i
);
818 void Complex::Conjugate( void )
824 inline void Complex::Mult( double f
)
831 inline void Complex::Mult( const Complex
& rM
)
836 r
= r_
* rM
.r
- i_
* rM
.i
;
837 i
= r_
* rM
.i
+ i_
* rM
.r
;
843 inline void Complex::Sub( const Complex
& rC
)
851 inline void Complex::Add( const Complex
& rAdd
)
861 inline const Complex
* ComplexList::Get( sal_uInt32 n
) const
863 return ( const Complex
* ) MyList::GetObject( n
);
867 inline const Complex
* ComplexList::First( void )
869 return ( const Complex
* ) MyList::First();
873 inline const Complex
* ComplexList::Next( void )
875 return ( const Complex
* ) MyList::Next();
879 inline void ComplexList::Append( Complex
* p
)
887 inline ConvertDataClass
ConvertData::Class( void ) const
895 inline ConvertDataLinear::ConvertDataLinear( const sal_Char
* p
, double fC
, double fO
, ConvertDataClass e
) :
896 ConvertData( p
, fC
, e
),
904 inline ConvertData
* ConvertDataList::First( void )
906 return ( ConvertData
* ) MyList::First();
910 inline ConvertData
* ConvertDataList::Next( void )
912 return ( ConvertData
* ) MyList::Next();
915 //-----------------------------------------------------------------------------
917 /// Helper class for date calculation for various financial functions
921 sal_uInt16 nOrigDay
; /// is the day of the original date.
922 sal_uInt16 nDay
; /// is the calculated day depending on the current month/year.
923 sal_uInt16 nMonth
; /// is the current month (one-based).
924 sal_uInt16 nYear
; /// is the current year.
925 sal_Bool bLastDayMode
: 1; /// if sal_True, recalculate nDay after every calculation.
926 sal_Bool bLastDay
: 1; /// is sal_True, if original date was the last day in month.
927 sal_Bool b30Days
: 1; /// is sal_True, if every month has 30 days in calculations.
928 sal_Bool bUSMode
: 1; /// is sal_True, if the US method of 30-day-calculations is used.
930 /// Calculates nDay from nOrigDay and current date.
933 /// @return count of days in current month
934 inline sal_uInt16
getDaysInMonth() const;
935 /// @return count of days in given month
936 inline sal_uInt16
getDaysInMonth( sal_uInt16 _nMon
) const;
938 /// @ return count of days in the given month range
939 sal_Int32
getDaysInMonthRange( sal_uInt16 nFrom
, sal_uInt16 nTo
) const;
940 /// @ return count of days in the given year range
941 sal_Int32
getDaysInYearRange( sal_uInt16 nFrom
, sal_uInt16 nTo
) const;
943 /// Adds/subtracts the given count of years, does not adjust day.
944 void doAddYears( sal_Int32 nYearCount
) throw( CSS::lang::IllegalArgumentException
);
949 date handling mode (days in month / days in year):
950 0 = 30 days / 360 days (US NASD)
954 4 = 30 days / 360 days (Europe)
955 5 = exact / exact (no last day adjustment) */
956 ScaDate( sal_Int32 nNullDate
, sal_Int32 nDate
, sal_Int32 nBase
);
957 ScaDate( const ScaDate
& rCopy
);
958 ScaDate
& operator=( const ScaDate
& rCopy
);
960 /// @return the current month.
961 inline sal_uInt16
getMonth() const { return nMonth
; };
962 /// @return the current year.
963 inline sal_uInt16
getYear() const { return nYear
; };
965 /// adds/subtracts the given count of months, adjusts day
966 void addMonths( sal_Int32 nMonthCount
) throw( CSS::lang::IllegalArgumentException
);
968 /// sets the given year, adjusts day
969 inline void setYear( sal_uInt16 nNewYear
);
970 /// adds/subtracts the given count of years, adjusts day
971 inline void addYears( sal_Int32 nYearCount
) throw( CSS::lang::IllegalArgumentException
);
973 /// @return the internal number of the current date
974 sal_Int32
getDate( sal_Int32 nNullDate
) const;
975 /// @return the number of days between the two dates
976 static sal_Int32
getDiff( const ScaDate
& rFrom
, const ScaDate
& rTo
) throw( CSS::lang::IllegalArgumentException
);
978 sal_Bool
operator<( const ScaDate
& rCmp
) const;
979 inline sal_Bool
operator<=( const ScaDate
& rCmp
) const { return !(rCmp
< *this); }
980 inline sal_Bool
operator>( const ScaDate
& rCmp
) const { return rCmp
< *this; }
981 inline sal_Bool
operator>=( const ScaDate
& rCmp
) const { return !(*this < rCmp
); }
984 inline sal_uInt16
ScaDate::getDaysInMonth() const
986 return getDaysInMonth( nMonth
);
989 inline sal_uInt16
ScaDate::getDaysInMonth( sal_uInt16 _nMon
) const
991 return b30Days
? 30 : DaysInMonth( _nMon
, nYear
);
994 inline void ScaDate::setYear( sal_uInt16 nNewYear
)
1000 inline void ScaDate::addYears( sal_Int32 nYearCount
) throw( CSS::lang::IllegalArgumentException
)
1002 doAddYears( nYearCount
);
1007 //-----------------------------------------------------------------------------
1009 /// Helper class for Any->double conversion, using current language settings
1010 class ScaAnyConverter
1013 CSS::uno::Reference
< CSS::util::XNumberFormatter
> xFormatter
;
1014 sal_Int32 nDefaultFormat
;
1015 sal_Bool bHasValidFormat
;
1017 /** Converts a string to double using the number formatter. If the formatter is not
1018 valid, ::rtl::math::stringToDouble() with english separators will be used.
1019 @throws com::sun::star::lang::IllegalArgumentException
1020 on strings not representing any double value.
1021 @return the converted double value. */
1022 double convertToDouble(
1023 const ::rtl::OUString
& rString
) const
1024 throw( CSS::lang::IllegalArgumentException
);
1028 const CSS::uno::Reference
< CSS::lang::XMultiServiceFactory
>& xServiceFact
);
1031 /// Initializing with current language settings
1033 const CSS::uno::Reference
< CSS::beans::XPropertySet
>& xPropSet
)
1034 throw( CSS::uno::RuntimeException
);
1036 /** Converts an Any to double (without initialization).
1037 The Any can be empty or contain a double or string.
1038 @throws com::sun::star::lang::IllegalArgumentException
1039 on other Any types or on invalid strings.
1040 @return sal_True if the Any contains a double or a non-empty valid string,
1041 sal_False if the Any is empty or the string is empty */
1044 const CSS::uno::Any
& rAny
) const
1045 throw( CSS::lang::IllegalArgumentException
);
1047 /** Converts an Any to double (with initialization).
1048 The Any can be empty or contain a double or string.
1049 @throws com::sun::star::lang::IllegalArgumentException
1050 on other Any types or on invalid strings.
1051 @return sal_True if the Any contains a double or a non-empty valid string,
1052 sal_False if the Any is empty or the string is empty */
1055 const CSS::uno::Reference
< CSS::beans::XPropertySet
>& xPropSet
,
1056 const CSS::uno::Any
& rAny
)
1057 throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
1059 /** Converts an Any to double (with initialization).
1060 The Any can be empty or contain a double or string.
1061 @throws com::sun::star::lang::IllegalArgumentException
1062 on other Any types or on invalid strings.
1063 @return the value of the double or string or fDefault if the Any or string is empty */
1065 const CSS::uno::Reference
< CSS::beans::XPropertySet
>& xPropSet
,
1066 const CSS::uno::Any
& rAny
,
1068 throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
1070 /** Converts an Any to sal_Int32 (with initialization).
1071 The Any can be empty or contain a double or string.
1072 @throws com::sun::star::lang::IllegalArgumentException
1073 on other Any types or on invalid values or strings.
1074 @return sal_True if the Any contains a double or a non-empty valid string,
1075 sal_False if the Any is empty or the string is empty */
1077 sal_Int32
& rnResult
,
1078 const CSS::uno::Reference
< CSS::beans::XPropertySet
>& xPropSet
,
1079 const CSS::uno::Any
& rAny
)
1080 throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
1082 /** Converts an Any to sal_Int32 (with initialization).
1083 The Any can be empty or contain a double or string.
1084 @throws com::sun::star::lang::IllegalArgumentException
1085 on other Any types or on invalid values or strings.
1086 @return the truncated value of the double or string or nDefault if the Any or string is empty */
1088 const CSS::uno::Reference
< CSS::beans::XPropertySet
>& xPropSet
,
1089 const CSS::uno::Any
& rAny
,
1090 sal_Int32 nDefault
)
1091 throw( CSS::uno::RuntimeException
, CSS::lang::IllegalArgumentException
);
1095 //-----------------------------------------------------------------------------