1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
28 #ifndef ANALYSISHELPER_HXX
29 #define ANALYSISHELPER_HXX
32 #include <com/sun/star/lang/XServiceName.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/util/Date.hpp>
36 #include <com/sun/star/util/XNumberFormatter.hpp>
37 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
38 #include <com/sun/star/sheet/XAddIn.hpp>
39 #include <com/sun/star/sheet/addin/XAnalysis.hpp>
43 #include <tools/resid.hxx>
44 #include <tools/rc.hxx>
46 #include "analysisdefs.hxx"
50 class SortedIndividualInt32List
;
51 class ScaAnyConverter
;
54 #define PI 3.1415926535897932
56 #define EOL ( ( const sal_Char* ) 1 )
57 #define EOE ( ( const sal_Char* ) 2 )
60 inline sal_Bool
IsLeapYear( sal_uInt16 nYear
);
62 #ifdef DISABLE_DYNLOADING
64 // Avoid clash with the functions with same name in
65 // scaddins/source/datefunc/datefunc.cxx. I am not sure if each pair
66 // have identical semantics, but if yes, one copy should be enough,
67 // but what would be a suitable library where such functions could go?
68 // Or can the analysis library depend on the date library or the other
71 #define DaysInMonth analysishelper_DaysInMonth
72 #define DateToDays analysishelper_DateToDays
73 #define DaysToDate analysishelper_DaysToDate
74 #define GetNullDate analysishelper_GetNullDate
78 sal_uInt16
DaysInMonth( sal_uInt16 nMonth
, sal_uInt16 nYear
);
79 sal_Int32
DateToDays( sal_uInt16 nDay
, sal_uInt16 nMonth
, sal_uInt16 nYear
);
80 void DaysToDate( sal_Int32 nDays
, sal_uInt16
& rDay
, sal_uInt16
& rMonth
, sal_uInt16
& rYear
) throw( ::com::sun::star::lang::IllegalArgumentException
);
81 sal_Int32
GetNullDate( const REF( ::com::sun::star::beans::XPropertySet
)& xOptions
) THROWDEF_RTE
;
82 sal_Int32
GetDiffDate360(
83 sal_uInt16 nDay1
, sal_uInt16 nMonth1
, sal_uInt16 nYear1
, sal_Bool bLeapYear1
,
84 sal_uInt16 nDay2
, sal_uInt16 nMonth2
, sal_uInt16 nYear2
,
85 sal_Bool bUSAMethod
);
86 inline sal_Int32
GetDiffDate360( constREFXPS
& xOpt
, sal_Int32 nDate1
, sal_Int32 nDate2
, sal_Bool bUSAMethod
);
87 sal_Int32
GetDiffDate360( sal_Int32 nNullDate
, sal_Int32 nDate1
, sal_Int32 nDate2
, sal_Bool bUSAMethod
);
89 sal_Int32
GetDaysInYears( sal_uInt16 nYear1
, sal_uInt16 nYear2
);
90 inline sal_Int16
GetDayOfWeek( sal_Int32 nDate
);
91 void GetDiffParam( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
,
92 sal_uInt16
& rYears
, sal_Int32
& rDayDiffPart
, sal_Int32
& rDaysInYear
) THROWDEF_RTE_IAE
;
93 // rYears = full num of years
94 // rDayDiffPart = num of days for last year
95 // rDaysInYear = num of days in first year
96 sal_Int32
GetDiffDate( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
,
97 sal_Int32
* pOptDaysIn1stYear
= NULL
) THROWDEF_RTE_IAE
;
98 double GetYearDiff( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
)
100 sal_Int32
GetDaysInYear( sal_Int32 nNullDate
, sal_Int32 nDate
, sal_Int32 nMode
) THROWDEF_RTE_IAE
;
101 double GetYearFrac( sal_Int32 nNullDate
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
)
103 inline double GetYearFrac( constREFXPS
& xOpt
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
)
105 inline void AlignDate( sal_uInt16
& rDay
, sal_uInt16 nMonth
, sal_uInt16 nYear
);
107 double Fak( sal_Int32 n
);
108 double GetGcd( double f1
, double f2
);
109 double ConvertToDec( const STRING
& rFromNum
, sal_uInt16 nBaseFrom
, sal_uInt16 nCharLim
) THROWDEF_RTE_IAE
;
110 STRING
ConvertFromDec(
111 double fNum
, double fMin
, double fMax
, sal_uInt16 nBase
,
112 sal_Int32 nPlaces
, sal_Int32 nMaxPlaces
, sal_Bool bUsePlaces
) THROWDEF_RTE_IAE
;
113 double Erf( double fX
);
114 double Erfc( double fX
);
115 sal_Bool
ParseDouble( const sal_Unicode
*& rpDoubleAsString
, double& rReturn
);
116 STRING
GetString( double fNumber
, sal_Bool bLeadingSign
= sal_False
, sal_uInt16 nMaxNumOfDigits
= 15 );
117 inline double Exp10( sal_Int16 nPower
); // 10 ^ nPower
119 double GetAmordegrc( sal_Int32 nNullDate
, double fCost
, sal_Int32 nDate
, sal_Int32 nFirstPer
,
120 double fRestVal
, double fPer
, double fRate
, sal_Int32 nBase
) THROWDEF_RTE_IAE
;
121 double GetAmorlinc( sal_Int32 nNullDate
, double fCost
, sal_Int32 nDate
, sal_Int32 nFirstPer
,
122 double fRestVal
, double fPer
, double fRate
, sal_Int32 nBase
) THROWDEF_RTE_IAE
;
123 double GetDuration( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, double fCoup
,
124 double fYield
, sal_Int32 nFreq
, sal_Int32 nBase
) THROWDEF_RTE_IAE
;
125 double GetYieldmat( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nIssue
,
126 double fRate
, double fPrice
, sal_Int32 nBase
) THROWDEF_RTE_IAE
;
127 double GetOddfprice( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nIssue
,
128 sal_Int32 nFirstCoup
, double fRate
, double fYield
, double fRedemp
,
129 sal_Int32 nFreq
, sal_Int32 nBase
) THROWDEF_RTE_IAE
;
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
) THROWDEF_RTE_IAE
;
132 double getPrice_( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, double fRate
, double fYield
,
133 double fRedemp
, sal_Int32 nFreq
, sal_Int32 nBase
) THROWDEF_RTE_IAE
;
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
) THROWDEF_RTE_IAE
;
137 double GetOddlprice( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nLastInterest
,
138 double fRate
, double fYield
, double fRedemp
, sal_Int32 nFreq
, sal_Int32 nBase
) THROWDEF_RTE_IAE
;
139 double GetOddlyield( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nLastInterest
,
140 double fRate
, double fPrice
, double fRedemp
, sal_Int32 nFreq
, sal_Int32 nBase
) THROWDEF_RTE_IAE
;
141 double GetRmz( double fZins
, double fZzr
, double fBw
, double fZw
, sal_Int32 nF
);
142 double GetZw( double fZins
, double fZzr
, double fRmz
, double fBw
, sal_Int32 nF
);
144 double GetCouppcd( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
145 sal_Int32 nBase
) THROWDEF_RTE_IAE
;
146 double GetCoupncd( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
147 sal_Int32 nBase
) THROWDEF_RTE_IAE
;
148 double GetCoupdaybs( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
149 sal_Int32 nBase
) THROWDEF_RTE_IAE
;
150 double GetCoupdaysnc( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
151 sal_Int32 nBase
) THROWDEF_RTE_IAE
;
153 double GetCoupnum( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
,
154 sal_Int32 nFreq
, sal_Int32 nBase
) THROWDEF_RTE_IAE
;
155 double GetCoupdays( sal_Int32 nNullDate
, sal_Int32 nSettle
, sal_Int32 nMat
, sal_Int32 nFreq
,
156 sal_Int32 nBase
) THROWDEF_RTE_IAE
;
161 //-----------------------------------------------------------------------------
168 static const sal_uInt32 nStartSize
;
169 static const sal_uInt32 nIncrSize
;
171 void** pData
; // pointer array
172 sal_uInt32 nSize
; // array size
173 sal_uInt32 nNew
; // next index to be inserted at
174 sal_uInt32 nAct
; // actual for iterations
177 inline void Grow( void );
183 inline const void* GetObject( sal_uInt32 nIndex
) const;
184 inline const void* First( void );
185 inline const void* Next( void );
187 inline void Append( void* pNewElement
);
188 void Insert( void* pNewLement
, sal_uInt32 nPlace
);
190 inline sal_uInt32
Count( void ) const;
196 class StringList
: protected MyList
199 virtual ~StringList();
201 inline const STRING
* First( void );
202 inline const STRING
* Next( void );
203 inline const STRING
* Get( sal_uInt32 nIndex
) const;
205 using MyList::Append
;
206 inline void Append( STRING
* pNew
);
207 inline void Append( const STRING
& rNew
);
228 const sal_Char
* pIntName
;
229 sal_uInt16 nUINameID
; // resource ID to UI name
230 sal_uInt16 nDescrID
; // resource ID to description, parameter names and ~ description
231 sal_Bool bDouble
; // name already exist in Calc
232 sal_Bool bWithOpt
; // first parameter is internal
233 sal_uInt16 nCompListID
; // resource ID to list of valid names
234 sal_uInt16 nNumOfParams
; // number of named / described parameters
235 FDCategory eCat
; // function category
244 ::rtl::OUString aIntName
;
245 sal_uInt16 nUINameID
;
246 sal_uInt16 nDescrID
; // leads also to parameter descriptions!
247 sal_Bool bDouble
; // flag for names, wich already exist in Calc
248 sal_Bool bWithOpt
; // has internal parameter on first position
250 sal_uInt16 nParam
; // num of parameters
252 StringList aCompList
; // list of all valid names
253 FDCategory eCat
; // function category
255 FuncData( const FuncDataBase
& rBaseData
, ResMgr
& );
258 inline sal_uInt16
GetUINameID( void ) const;
259 inline sal_uInt16
GetDescrID( void ) const;
260 inline sal_Bool
IsDouble( void ) const;
261 inline sal_Bool
HasIntParam( void ) const;
263 sal_uInt16
GetStrIndex( sal_uInt16 nParamNum
) const;
264 inline sal_Bool
Is( const ::rtl::OUString
& rCompareTo
) const;
266 inline const StringList
& GetCompNameList( void ) const;
268 inline FDCategory
GetCategory( void ) const;
274 class CStrList
: private MyList
277 using MyList::Append
;
278 inline void Append( const sal_Char
* pNew
);
279 inline const sal_Char
* Get( sal_uInt32 nIndex
) const;
286 class FuncDataList
: private MyList
288 ::rtl::OUString aLastName
;
291 FuncDataList( ResMgr
& );
292 virtual ~FuncDataList();
293 using MyList::Append
;
294 inline void Append( FuncData
* pNew
);
295 inline const FuncData
* Get( sal_uInt32 nIndex
) const;
298 const FuncData
* Get( const ::rtl::OUString
& aProgrammaticName
) const;
303 class AnalysisResId
: public ResId
306 AnalysisResId( sal_uInt16 nId
, ResMgr
& rResMgr
);
312 class AnalysisRscStrLoader
: public Resource
317 AnalysisRscStrLoader( sal_uInt16 nRsc
, sal_uInt16 nStrId
, ResMgr
& rResMgr
) :
318 Resource( AnalysisResId( nRsc
, rResMgr
) ),
319 aStr( AnalysisResId( nStrId
, rResMgr
) )
324 const String
& GetString() const { return aStr
; }
330 //-----------------------------------------------------------------------------
332 /// sorted list with unique sal_Int32 values
333 class SortedIndividualInt32List
: private MyList
336 using MyList::Insert
;
337 void Insert( sal_Int32 nDay
);
338 void Insert( sal_Int32 nDay
, sal_Int32 nNullDate
, sal_Bool bInsertOnWeekend
);
339 void Insert( double fDay
, sal_Int32 nNullDate
, sal_Bool bInsertOnWeekend
)
340 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
342 /** @param rAnyConv must be an initialized ScaAnyConmverter
343 @param bInsertOnWeekend insertion mode: sal_False = holidays on weekend are omitted */
344 void InsertHolidayList(
345 const ScaAnyConverter
& rAnyConv
,
346 const ::com::sun::star::uno::Any
& rHolAny
,
348 sal_Bool bInsertOnWeekend
) throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
351 SortedIndividualInt32List();
352 virtual ~SortedIndividualInt32List();
356 /// @return element on position nIndex or 0 on invalid index
357 inline sal_Int32
Get( sal_uInt32 nIndex
) const
358 { return (sal_Int32
)(sal_IntPtr
) MyList::GetObject( nIndex
); }
360 /// @return sal_True if nVal (internal date representation) is contained
361 sal_Bool
Find( sal_Int32 nVal
) const;
363 /** @param rAnyConv is an initialized or uninitialized ScaAnyConverter
364 @param bInsertOnWeekend insertion mode: sal_False = holidays on weekend are omitted */
365 void InsertHolidayList(
366 ScaAnyConverter
& rAnyConv
,
367 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xOptions
,
368 const ::com::sun::star::uno::Any
& rHolAny
,
370 sal_Bool bInsertOnWeekend
) throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
374 //-----------------------------------------------------------------------------
376 class ScaDoubleList
: protected MyList
379 inline void ListAppend( double fValue
) { MyList::Append( new double( fValue
) ); }
381 using MyList::Append
;
382 inline void Append( double fValue
) throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
)
383 { if( CheckInsert( fValue
) ) ListAppend( fValue
); }
385 /** @param rAnyConv must be an initialized ScaAnyConmverter
386 @param bIgnoreEmpty handling of empty Any's/strings: sal_False = inserted as 0.0; sal_True = omitted */
388 const ScaAnyConverter
& rAnyConv
,
389 const ::com::sun::star::uno::Any
& rAny
,
390 sal_Bool bIgnoreEmpty
) throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
392 /** @param rAnyConv must be an initialized ScaAnyConmverter
393 @param bIgnoreEmpty handling of empty Any's/strings: sal_False = inserted as 0.0; sal_True = omitted */
395 const ScaAnyConverter
& rAnyConv
,
396 const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& rAnySeq
,
397 sal_Bool bIgnoreEmpty
) throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
399 /** @param rAnyConv must be an initialized ScaAnyConmverter
400 @param bIgnoreEmpty handling of empty Any's/strings: sal_False = inserted as 0.0; sal_True = omitted */
402 const ScaAnyConverter
& rAnyConv
,
403 const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
> >& rAnySeq
,
404 sal_Bool bIgnoreEmpty
) throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
407 virtual ~ScaDoubleList();
410 inline const double* Get( sal_uInt32 nIndex
) const
411 { return static_cast< const double* >( MyList::GetObject( nIndex
) ); }
413 inline const double* First() { return static_cast< const double* >( MyList::First() ); }
414 inline const double* Next() { return static_cast< const double* >( MyList::Next() ); }
416 void Append( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< double > >& rValueArr
)
417 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
418 void Append( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< sal_Int32
> >& rValueArr
)
419 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
421 /** @param rAnyConv is an initialized or uninitialized ScaAnyConverter
422 @param bIgnoreEmpty handling of empty Any's/strings: sal_False = inserted as 0.0; sal_True = omitted */
424 ScaAnyConverter
& rAnyConv
,
425 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xOpt
,
426 const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& rAnySeq
,
427 sal_Bool bIgnoreEmpty
= sal_True
) throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
429 virtual sal_Bool
CheckInsert( double fValue
) const
430 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
434 //-----------------------------------------------------------------------------
436 /// stores double values >0.0, throws exception for double values <0.0, does nothing for 0.0
437 class ScaDoubleListGT0
: public ScaDoubleList
440 virtual sal_Bool
CheckInsert( double fValue
) const
441 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
445 //-----------------------------------------------------------------------------
447 /// stores double values >=0.0, throws exception for double values <0.0
448 class ScaDoubleListGE0
: public ScaDoubleList
451 virtual sal_Bool
CheckInsert( double fValue
) const
452 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
456 //-----------------------------------------------------------------------------
465 inline Complex( double fReal
, double fImag
= 0.0, sal_Unicode cC
= '\0' );
466 Complex( const STRING
& rComplexAsString
) THROWDEF_RTE_IAE
;
468 inline static sal_Bool
IsImagUnit( sal_Unicode c
);
469 static sal_Bool
ParseString( const STRING
& rComplexAsString
, Complex
& rReturn
);
470 STRING
GetString() const THROWDEF_RTE_IAE
;
472 inline double Real( void ) const;
473 inline double Imag( void ) const;
475 double Arg( void ) const THROWDEF_RTE_IAE
;
476 inline double Abs( void ) const;
478 // following functions change the complex number itself to avoid unnecessary copy actions!
479 void Power( double fPower
) THROWDEF_RTE_IAE
;
481 void Sin( void ) THROWDEF_RTE_IAE
;
482 void Cos( void ) THROWDEF_RTE_IAE
;
483 void Div( const Complex
& rDivisor
) THROWDEF_RTE_IAE
;
485 inline void Conjugate( void );
486 void Ln( void ) THROWDEF_RTE_IAE
;
487 void Log10( void ) THROWDEF_RTE_IAE
;
488 void Log2( void ) THROWDEF_RTE_IAE
;
489 inline void Mult( double fFact
);
490 inline void Mult( const Complex
& rMult
);
491 inline void Sub( const Complex
& rMult
);
492 inline void Add( const Complex
& rAdd
);
493 void Tan( void ) THROWDEF_RTE_IAE
;
494 void Sec( void ) THROWDEF_RTE_IAE
;
495 void Csc( void ) THROWDEF_RTE_IAE
;
496 void Cot( void ) THROWDEF_RTE_IAE
;
497 void Sinh( void ) THROWDEF_RTE_IAE
;
498 void Cosh( void ) THROWDEF_RTE_IAE
;
499 void Sech( void ) THROWDEF_RTE_IAE
;
500 void Csch( void ) THROWDEF_RTE_IAE
;
507 enum ComplListAppendHandl
515 class ComplexList
: protected MyList
518 virtual ~ComplexList();
520 inline const Complex
* Get( sal_uInt32 nIndex
) const;
521 inline const Complex
* First( void );
522 inline const Complex
* Next( void );
526 using MyList::Append
;
527 inline void Append( Complex
* pNew
);
528 void Append( const SEQSEQ( STRING
)& rComplexNumList
, ComplListAppendHandl eAH
= AH_EmpyAs0
) THROWDEF_RTE_IAE
;
529 void Append( const SEQ( ANY
)& aMultPars
,ComplListAppendHandl eAH
= AH_EmpyAs0
) THROWDEF_RTE_IAE
;
535 enum ConvertDataClass
537 CDC_Mass
, CDC_Length
, CDC_Time
, CDC_Pressure
, CDC_Force
, CDC_Energy
, CDC_Power
, CDC_Magnetism
,
538 CDC_Temperature
, CDC_Volume
, CDC_Area
, CDC_Speed
, CDC_Information
542 #define INV_MATCHLEV 1764 // guess, what this is... :-)
545 class ConvertDataList
;
553 friend class ConvertDataList
;
556 ConvertDataClass eClass
;
557 sal_Bool bPrefixSupport
;
560 const sal_Char pUnitName
[],
561 double fConvertConstant
,
562 ConvertDataClass eClass
,
563 sal_Bool bPrefSupport
= sal_False
);
565 virtual ~ConvertData();
567 sal_Int16
GetMatchingLevel( const STRING
& rRef
) const;
569 // 1.0 = matches exact
570 // rest = matches without an assumed prefix of one character
571 // rest gives power for 10 represented by the prefix (e.g. 3 for k or -9 for n
573 virtual double Convert( double fVal
, const ConvertData
& rTo
,
574 sal_Int16 nMatchLevelFrom
, sal_Int16 nMatchLevelTo
) const THROWDEF_RTE_IAE
;
575 // converts fVal from this unit to rFrom unit
576 // throws exception if not from same class
577 // this implementation is for proportional cases only
578 virtual double ConvertToBase( double fVal
, sal_Int16 nMatchLevel
) const;
579 virtual double ConvertFromBase( double fVal
, sal_Int16 nMatchLevel
) const;
581 inline ConvertDataClass
Class( void ) const;
582 inline sal_Bool
IsPrefixSupport( void ) const;
588 class ConvertDataLinear
: public ConvertData
593 inline ConvertDataLinear(
594 const sal_Char pUnitName
[],
595 double fConvertConstant
,
596 double fConvertOffset
,
597 ConvertDataClass eClass
,
598 sal_Bool bPrefSupport
= sal_False
);
600 virtual ~ConvertDataLinear();
602 virtual double Convert( double fVal
, const ConvertData
& rTo
,
603 sal_Int16 nMatchLevelFrom
, sal_Int16 nMatchLevelTo
) const THROWDEF_RTE_IAE
;
604 // for cases where f(x) = a + bx applies (e.g. Temperatures)
606 virtual double ConvertToBase( double fVal
, sal_Int16 nMatchLevel
) const;
607 virtual double ConvertFromBase( double fVal
, sal_Int16 nMatchLevel
) const;
613 class ConvertDataList
: protected MyList
617 inline ConvertData
* First( void );
618 inline ConvertData
* Next( void );
620 ConvertDataList( void );
621 virtual ~ConvertDataList();
623 double Convert( double fVal
, const STRING
& rFrom
, const STRING
& rTo
) THROWDEF_RTE_IAE
;
629 inline sal_Bool
IsLeapYear( sal_uInt16 n
)
631 return ( (( ( n
% 4 ) == 0 ) && ( ( n
% 100 ) != 0)) || ( ( n
% 400 ) == 0 ) );
635 inline sal_Int32
GetDiffDate360( constREFXPS
& xOpt
, sal_Int32 nDate1
, sal_Int32 nDate2
, sal_Bool bUSAMethod
)
637 return GetDiffDate360( GetNullDate( xOpt
), nDate1
, nDate2
, bUSAMethod
);
641 inline sal_Int16
GetDayOfWeek( sal_Int32 n
)
642 { // monday = 0, ..., sunday = 6
643 return static_cast< sal_Int16
>( ( n
- 1 ) % 7 );
647 inline double GetYearFrac( constREFXPS
& xOpt
, sal_Int32 nStartDate
, sal_Int32 nEndDate
, sal_Int32 nMode
) THROWDEF_RTE_IAE
649 return GetYearFrac( GetNullDate( xOpt
), nStartDate
, nEndDate
, nMode
);
653 inline void AlignDate( sal_uInt16
& rD
, sal_uInt16 nM
, sal_uInt16 nY
)
655 sal_uInt16 nMax
= DaysInMonth( nM
, nY
);
662 inline void MyList::Grow( void )
669 inline const void* MyList::GetObject( sal_uInt32 n
) const
678 inline const void* MyList::First( void )
688 inline const void* MyList::Next( void )
692 return pData
[ nAct
];
701 inline void MyList::Append( void* p
)
709 inline sal_uInt32
MyList::Count( void ) const
717 inline const STRING
* StringList::First( void )
719 return ( const STRING
* ) MyList::First();
723 inline const STRING
* StringList::Next( void )
725 return ( const STRING
* ) MyList::Next();
729 inline const STRING
* StringList::Get( sal_uInt32 n
) const
731 return ( const STRING
* ) MyList::GetObject( n
);
735 inline void StringList::Append( STRING
* p
)
741 inline void StringList::Append( const STRING
& r
)
743 MyList::Append( new STRING( r
) );
749 inline sal_uInt16
FuncData::GetUINameID( void ) const
755 inline sal_uInt16
FuncData::GetDescrID( void ) const
761 inline sal_Bool
FuncData::IsDouble( void ) const
767 inline sal_Bool
FuncData::HasIntParam( void ) const
773 inline sal_Bool
FuncData::Is( const ::rtl::OUString
& r
) const
775 return aIntName
== r
;
779 inline const StringList
& FuncData::GetCompNameList( void ) const
785 inline FDCategory
FuncData::GetCategory( void ) const
793 inline void CStrList::Append( const sal_Char
* p
)
795 MyList::Append( ( void* ) p
);
799 inline const sal_Char
* CStrList::Get( sal_uInt32 n
) const
801 return ( const sal_Char
* ) MyList::GetObject( n
);
807 inline void FuncDataList::Append( FuncData
* p
)
813 inline const FuncData
* FuncDataList::Get( sal_uInt32 n
) const
815 return ( const FuncData
* ) MyList::GetObject( n
);
819 inline Complex::Complex( double fReal
, double fImag
, sal_Unicode cC
) :
820 r( fReal
), i( fImag
), c( cC
)
825 inline double Complex::Real( void ) const
831 inline double Complex::Imag( void ) const
837 inline double Complex::Abs( void ) const
839 return sqrt( r
* r
+ i
* i
);
843 void Complex::Conjugate( void )
849 inline void Complex::Mult( double f
)
856 inline void Complex::Mult( const Complex
& rM
)
861 r
= r_
* rM
.r
- i_
* rM
.i
;
862 i
= r_
* rM
.i
+ i_
* rM
.r
;
868 inline void Complex::Sub( const Complex
& rC
)
876 inline void Complex::Add( const Complex
& rAdd
)
886 inline const Complex
* ComplexList::Get( sal_uInt32 n
) const
888 return ( const Complex
* ) MyList::GetObject( n
);
892 inline const Complex
* ComplexList::First( void )
894 return ( const Complex
* ) MyList::First();
898 inline const Complex
* ComplexList::Next( void )
900 return ( const Complex
* ) MyList::Next();
904 inline void ComplexList::Append( Complex
* p
)
912 inline ConvertDataClass
ConvertData::Class( void ) const
919 inline sal_Bool
ConvertData::IsPrefixSupport( void ) const
921 return bPrefixSupport
;
924 inline ConvertDataLinear::ConvertDataLinear( const sal_Char
* p
, double fC
, double fO
, ConvertDataClass e
,
925 sal_Bool bPrefSupport
) :
926 ConvertData( p
, fC
, e
, bPrefSupport
),
934 inline ConvertData
* ConvertDataList::First( void )
936 return ( ConvertData
* ) MyList::First();
940 inline ConvertData
* ConvertDataList::Next( void )
942 return ( ConvertData
* ) MyList::Next();
945 //-----------------------------------------------------------------------------
947 /// Helper class for date calculation for various financial functions
951 sal_uInt16 nOrigDay
; /// is the day of the original date.
952 sal_uInt16 nDay
; /// is the calculated day depending on the current month/year.
953 sal_uInt16 nMonth
; /// is the current month (one-based).
954 sal_uInt16 nYear
; /// is the current year.
955 sal_Bool bLastDayMode
: 1; /// if sal_True, recalculate nDay after every calculation.
956 sal_Bool bLastDay
: 1; /// is sal_True, if original date was the last day in month.
957 sal_Bool b30Days
: 1; /// is sal_True, if every month has 30 days in calculations.
958 sal_Bool bUSMode
: 1; /// is sal_True, if the US method of 30-day-calculations is used.
960 /// Calculates nDay from nOrigDay and current date.
963 /// @return count of days in current month
964 inline sal_uInt16
getDaysInMonth() const;
965 /// @return count of days in given month
966 inline sal_uInt16
getDaysInMonth( sal_uInt16 _nMon
) const;
968 /// @ return count of days in the given month range
969 sal_Int32
getDaysInMonthRange( sal_uInt16 nFrom
, sal_uInt16 nTo
) const;
970 /// @ return count of days in the given year range
971 sal_Int32
getDaysInYearRange( sal_uInt16 nFrom
, sal_uInt16 nTo
) const;
973 /// Adds/subtracts the given count of years, does not adjust day.
974 void doAddYears( sal_Int32 nYearCount
) throw( ::com::sun::star::lang::IllegalArgumentException
);
979 date handling mode (days in month / days in year):
980 0 = 30 days / 360 days (US NASD)
984 4 = 30 days / 360 days (Europe)
985 5 = exact / exact (no last day adjustment) */
986 ScaDate( sal_Int32 nNullDate
, sal_Int32 nDate
, sal_Int32 nBase
);
987 ScaDate( const ScaDate
& rCopy
);
988 ScaDate
& operator=( const ScaDate
& rCopy
);
990 /// @return the current month.
991 inline sal_uInt16
getMonth() const { return nMonth
; };
992 /// @return the current year.
993 inline sal_uInt16
getYear() const { return nYear
; };
995 /// adds/subtracts the given count of months, adjusts day
996 void addMonths( sal_Int32 nMonthCount
) throw( ::com::sun::star::lang::IllegalArgumentException
);
998 /// sets the given year, adjusts day
999 inline void setYear( sal_uInt16 nNewYear
);
1000 /// adds/subtracts the given count of years, adjusts day
1001 inline void addYears( sal_Int32 nYearCount
) throw( ::com::sun::star::lang::IllegalArgumentException
);
1003 /// @return the internal number of the current date
1004 sal_Int32
getDate( sal_Int32 nNullDate
) const;
1005 /// @return the number of days between the two dates
1006 static sal_Int32
getDiff( const ScaDate
& rFrom
, const ScaDate
& rTo
) throw( ::com::sun::star::lang::IllegalArgumentException
);
1008 sal_Bool
operator<( const ScaDate
& rCmp
) const;
1009 inline sal_Bool
operator<=( const ScaDate
& rCmp
) const { return !(rCmp
< *this); }
1010 inline sal_Bool
operator>( const ScaDate
& rCmp
) const { return rCmp
< *this; }
1011 inline sal_Bool
operator>=( const ScaDate
& rCmp
) const { return !(*this < rCmp
); }
1014 inline sal_uInt16
ScaDate::getDaysInMonth() const
1016 return getDaysInMonth( nMonth
);
1019 inline sal_uInt16
ScaDate::getDaysInMonth( sal_uInt16 _nMon
) const
1021 return b30Days
? 30 : DaysInMonth( _nMon
, nYear
);
1024 inline void ScaDate::setYear( sal_uInt16 nNewYear
)
1030 inline void ScaDate::addYears( sal_Int32 nYearCount
) throw( ::com::sun::star::lang::IllegalArgumentException
)
1032 doAddYears( nYearCount
);
1037 //-----------------------------------------------------------------------------
1039 /// Helper class for Any->double conversion, using current language settings
1040 class ScaAnyConverter
1043 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XNumberFormatter
> xFormatter
;
1044 sal_Int32 nDefaultFormat
;
1045 sal_Bool bHasValidFormat
;
1047 /** Converts a string to double using the number formatter. If the formatter is not
1048 valid, ::rtl::math::stringToDouble() with english separators will be used.
1049 @throws com::sun::star::lang::IllegalArgumentException
1050 on strings not representing any double value.
1051 @return the converted double value. */
1052 double convertToDouble(
1053 const ::rtl::OUString
& rString
) const
1054 throw( ::com::sun::star::lang::IllegalArgumentException
);
1058 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xServiceFact
);
1061 /// Initializing with current language settings
1063 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xPropSet
)
1064 throw( ::com::sun::star::uno::RuntimeException
);
1066 /** Converts an Any to double (without initialization).
1067 The Any can be empty or contain a double or string.
1068 @throws com::sun::star::lang::IllegalArgumentException
1069 on other Any types or on invalid strings.
1070 @return sal_True if the Any contains a double or a non-empty valid string,
1071 sal_False if the Any is empty or the string is empty */
1074 const ::com::sun::star::uno::Any
& rAny
) const
1075 throw( ::com::sun::star::lang::IllegalArgumentException
);
1077 /** Converts an Any to double (with initialization).
1078 The Any can be empty or contain a double or string.
1079 @throws com::sun::star::lang::IllegalArgumentException
1080 on other Any types or on invalid strings.
1081 @return sal_True if the Any contains a double or a non-empty valid string,
1082 sal_False if the Any is empty or the string is empty */
1085 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xPropSet
,
1086 const ::com::sun::star::uno::Any
& rAny
)
1087 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
1089 /** Converts an Any to double (with initialization).
1090 The Any can be empty or contain a double or string.
1091 @throws com::sun::star::lang::IllegalArgumentException
1092 on other Any types or on invalid strings.
1093 @return the value of the double or string or fDefault if the Any or string is empty */
1095 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xPropSet
,
1096 const ::com::sun::star::uno::Any
& rAny
,
1098 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
1100 /** Converts an Any to sal_Int32 (with initialization).
1101 The Any can be empty or contain a double or string.
1102 @throws com::sun::star::lang::IllegalArgumentException
1103 on other Any types or on invalid values or strings.
1104 @return sal_True if the Any contains a double or a non-empty valid string,
1105 sal_False if the Any is empty or the string is empty */
1107 sal_Int32
& rnResult
,
1108 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xPropSet
,
1109 const ::com::sun::star::uno::Any
& rAny
)
1110 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
1112 /** Converts an Any to sal_Int32 (with initialization).
1113 The Any can be empty or contain a double or string.
1114 @throws com::sun::star::lang::IllegalArgumentException
1115 on other Any types or on invalid values or strings.
1116 @return the truncated value of the double or string or nDefault if the Any or string is empty */
1118 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& xPropSet
,
1119 const ::com::sun::star::uno::Any
& rAny
,
1120 sal_Int32 nDefault
)
1121 throw( ::com::sun::star::uno::RuntimeException
, ::com::sun::star::lang::IllegalArgumentException
);
1125 //-----------------------------------------------------------------------------
1130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */