1f6a6b25fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3f6a6b25fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4f6a6b25fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5f6a6b25fSAndrew Rist * distributed with this work for additional information 6f6a6b25fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7f6a6b25fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8f6a6b25fSAndrew Rist * "License"); you may not use this file except in compliance 9f6a6b25fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11f6a6b25fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13f6a6b25fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14f6a6b25fSAndrew Rist * software distributed under the License is distributed on an 15f6a6b25fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16f6a6b25fSAndrew Rist * KIND, either express or implied. See the License for the 17f6a6b25fSAndrew Rist * specific language governing permissions and limitations 18f6a6b25fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20f6a6b25fSAndrew Rist *************************************************************/ 21f6a6b25fSAndrew Rist 22f6a6b25fSAndrew Rist 23cdf0e10cSrcweir #ifndef ANALYSISHELPER_HXX 24cdf0e10cSrcweir #define ANALYSISHELPER_HXX 25cdf0e10cSrcweir 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/lang/XServiceName.hpp> 28cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 29cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 30cdf0e10cSrcweir #include <com/sun/star/util/Date.hpp> 31cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatter.hpp> 32cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatsSupplier.hpp> 33cdf0e10cSrcweir #include <com/sun/star/sheet/XAddIn.hpp> 34cdf0e10cSrcweir #include <com/sun/star/sheet/addin/XAnalysis.hpp> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <math.h> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <tools/resid.hxx> 39cdf0e10cSrcweir #include <tools/rc.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir #include "analysisdefs.hxx" 42cdf0e10cSrcweir 43cdf0e10cSrcweir 44cdf0e10cSrcweir class ResMgr; 45cdf0e10cSrcweir class SortedIndividualInt32List; 46cdf0e10cSrcweir class ScaAnyConverter; 47cdf0e10cSrcweir 48cdf0e10cSrcweir 49cdf0e10cSrcweir #define PI 3.1415926535897932 50cdf0e10cSrcweir #define PI_2 (PI/2.0) 51cdf0e10cSrcweir //#define EULER 2.7182818284590452 52cdf0e10cSrcweir #define EOL ( ( const sal_Char* ) 1 ) 53cdf0e10cSrcweir #define EOE ( ( const sal_Char* ) 2 ) 54cdf0e10cSrcweir 55cdf0e10cSrcweir 56cdf0e10cSrcweir //double _Test( sal_Int32 nMode, double f1, double f2, double f3 ); 57cdf0e10cSrcweir inline sal_Bool IsLeapYear( sal_uInt16 nYear ); 58cdf0e10cSrcweir sal_uInt16 DaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear ); 59cdf0e10cSrcweir sal_Int32 DateToDays( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear ); 60cdf0e10cSrcweir void DaysToDate( sal_Int32 nDays, sal_uInt16& rDay, sal_uInt16& rMonth, sal_uInt16& rYear ) throw( ::com::sun::star::lang::IllegalArgumentException ); 61cdf0e10cSrcweir sal_Int32 GetNullDate( const REF( CSS::beans::XPropertySet )& xOptions ) THROWDEF_RTE; 62cdf0e10cSrcweir sal_Int32 GetDiffDate360( 63cdf0e10cSrcweir sal_uInt16 nDay1, sal_uInt16 nMonth1, sal_uInt16 nYear1, sal_Bool bLeapYear1, 64cdf0e10cSrcweir sal_uInt16 nDay2, sal_uInt16 nMonth2, sal_uInt16 nYear2, 65cdf0e10cSrcweir sal_Bool bUSAMethod ); 66cdf0e10cSrcweir inline sal_Int32 GetDiffDate360( constREFXPS& xOpt, sal_Int32 nDate1, sal_Int32 nDate2, sal_Bool bUSAMethod ); 67cdf0e10cSrcweir sal_Int32 GetDiffDate360( sal_Int32 nNullDate, sal_Int32 nDate1, sal_Int32 nDate2, sal_Bool bUSAMethod ); 68cdf0e10cSrcweir 69cdf0e10cSrcweir sal_Int32 GetDaysInYears( sal_uInt16 nYear1, sal_uInt16 nYear2 ); 70cdf0e10cSrcweir inline sal_Int16 GetDayOfWeek( sal_Int32 nDate ); 71cdf0e10cSrcweir void GetDiffParam( sal_Int32 nNullDate, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode, 72cdf0e10cSrcweir sal_uInt16& rYears, sal_Int32& rDayDiffPart, sal_Int32& rDaysInYear ) THROWDEF_RTE_IAE; 73cdf0e10cSrcweir // rYears = full num of years 74cdf0e10cSrcweir // rDayDiffPart = num of days for last year 75cdf0e10cSrcweir // rDaysInYear = num of days in first year 76cdf0e10cSrcweir sal_Int32 GetDiffDate( sal_Int32 nNullDate, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode, 77cdf0e10cSrcweir sal_Int32* pOptDaysIn1stYear = NULL ) THROWDEF_RTE_IAE; 78cdf0e10cSrcweir double GetYearDiff( sal_Int32 nNullDate, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode ) 79cdf0e10cSrcweir THROWDEF_RTE_IAE; 80cdf0e10cSrcweir sal_Int32 GetDaysInYear( sal_Int32 nNullDate, sal_Int32 nDate, sal_Int32 nMode ) THROWDEF_RTE_IAE; 81cdf0e10cSrcweir double GetYearFrac( sal_Int32 nNullDate, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode ) 82cdf0e10cSrcweir THROWDEF_RTE_IAE; 83cdf0e10cSrcweir inline double GetYearFrac( constREFXPS& xOpt, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode ) 84cdf0e10cSrcweir THROWDEF_RTE_IAE; 85cdf0e10cSrcweir inline void AlignDate( sal_uInt16& rDay, sal_uInt16 nMonth, sal_uInt16 nYear ); 86cdf0e10cSrcweir 87cdf0e10cSrcweir double Fak( sal_Int32 n ); 88cdf0e10cSrcweir double GetGcd( double f1, double f2 ); 89cdf0e10cSrcweir double ConvertToDec( const STRING& rFromNum, sal_uInt16 nBaseFrom, sal_uInt16 nCharLim ) THROWDEF_RTE_IAE; 90cdf0e10cSrcweir STRING ConvertFromDec( 91cdf0e10cSrcweir double fNum, double fMin, double fMax, sal_uInt16 nBase, 92cdf0e10cSrcweir sal_Int32 nPlaces, sal_Int32 nMaxPlaces, sal_Bool bUsePlaces ) THROWDEF_RTE_IAE; 93cdf0e10cSrcweir double Erf( double fX ); 94cdf0e10cSrcweir double Erfc( double fX ); 95cdf0e10cSrcweir sal_Bool ParseDouble( const sal_Unicode*& rpDoubleAsString, double& rReturn ); 96cdf0e10cSrcweir STRING GetString( double fNumber, sal_Bool bLeadingSign = sal_False, sal_uInt16 nMaxNumOfDigits = 15 ); 97cdf0e10cSrcweir inline double Exp10( sal_Int16 nPower ); // 10 ^ nPower 98cdf0e10cSrcweir 99cdf0e10cSrcweir double GetAmordegrc( sal_Int32 nNullDate, double fCost, sal_Int32 nDate, sal_Int32 nFirstPer, 100cdf0e10cSrcweir double fRestVal, double fPer, double fRate, sal_Int32 nBase ) THROWDEF_RTE_IAE; 101cdf0e10cSrcweir double GetAmorlinc( sal_Int32 nNullDate, double fCost, sal_Int32 nDate, sal_Int32 nFirstPer, 102cdf0e10cSrcweir double fRestVal, double fPer, double fRate, sal_Int32 nBase ) THROWDEF_RTE_IAE; 103cdf0e10cSrcweir double GetDuration( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, double fCoup, 104cdf0e10cSrcweir double fYield, sal_Int32 nFreq, sal_Int32 nBase ) THROWDEF_RTE_IAE; 105cdf0e10cSrcweir double GetYieldmat( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nIssue, 106cdf0e10cSrcweir double fRate, double fPrice, sal_Int32 nBase ) THROWDEF_RTE_IAE; 107cdf0e10cSrcweir double GetOddfprice( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nIssue, 108cdf0e10cSrcweir sal_Int32 nFirstCoup, double fRate, double fYield, double fRedemp, 109cdf0e10cSrcweir sal_Int32 nFreq, sal_Int32 nBase ) THROWDEF_RTE_IAE; 110cdf0e10cSrcweir double getYield_( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, double fCoup, double fPrice, 111cdf0e10cSrcweir double fRedemp, sal_Int32 nFreq, sal_Int32 nBase ) THROWDEF_RTE_IAE; 112cdf0e10cSrcweir double getPrice_( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, double fRate, double fYield, 113cdf0e10cSrcweir double fRedemp, sal_Int32 nFreq, sal_Int32 nBase ) THROWDEF_RTE_IAE; 114cdf0e10cSrcweir double GetOddfyield( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nIssue, 115cdf0e10cSrcweir sal_Int32 nFirstCoup, double fRate, double fPrice, double fRedemp, 116cdf0e10cSrcweir sal_Int32 nFreq, sal_Int32 nBase ) THROWDEF_RTE_IAE; 117cdf0e10cSrcweir double GetOddlprice( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nLastInterest, 118cdf0e10cSrcweir double fRate, double fYield, double fRedemp, sal_Int32 nFreq, sal_Int32 nBase ) THROWDEF_RTE_IAE; 119cdf0e10cSrcweir double GetOddlyield( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nLastInterest, 120cdf0e10cSrcweir double fRate, double fPrice, double fRedemp, sal_Int32 nFreq, sal_Int32 nBase ) THROWDEF_RTE_IAE; 121cdf0e10cSrcweir double GetRmz( double fZins, double fZzr, double fBw, double fZw, sal_Int32 nF ); 122cdf0e10cSrcweir double GetZw( double fZins, double fZzr, double fRmz, double fBw, sal_Int32 nF ); 123cdf0e10cSrcweir //double TBillYield( constREFXPS& xOpt, sal_Int32 nSettle, sal_Int32 nMat, double fPrice )THROWDEF_RTE_IAE; 124cdf0e10cSrcweir 125cdf0e10cSrcweir double GetCouppcd( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, 126cdf0e10cSrcweir sal_Int32 nBase ) THROWDEF_RTE_IAE; 127cdf0e10cSrcweir double GetCoupncd( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, 128cdf0e10cSrcweir sal_Int32 nBase ) THROWDEF_RTE_IAE; 129cdf0e10cSrcweir double GetCoupdaybs( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, 130cdf0e10cSrcweir sal_Int32 nBase ) THROWDEF_RTE_IAE; 131cdf0e10cSrcweir double GetCoupdaysnc( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, 132cdf0e10cSrcweir sal_Int32 nBase ) THROWDEF_RTE_IAE; 133cdf0e10cSrcweir 134cdf0e10cSrcweir double GetCoupnum( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, 135cdf0e10cSrcweir sal_Int32 nFreq, sal_Int32 nBase ) THROWDEF_RTE_IAE; 136cdf0e10cSrcweir double GetCoupdays( sal_Int32 nNullDate, sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, 137cdf0e10cSrcweir sal_Int32 nBase ) THROWDEF_RTE_IAE; 138cdf0e10cSrcweir 139cdf0e10cSrcweir 140cdf0e10cSrcweir 141cdf0e10cSrcweir 142cdf0e10cSrcweir //----------------------------------------------------------------------------- 143cdf0e10cSrcweir 144cdf0e10cSrcweir 145cdf0e10cSrcweir 146cdf0e10cSrcweir class MyList 147cdf0e10cSrcweir { 148cdf0e10cSrcweir private: 149cdf0e10cSrcweir static const sal_uInt32 nStartSize; 150cdf0e10cSrcweir static const sal_uInt32 nIncrSize; 151cdf0e10cSrcweir 152cdf0e10cSrcweir void** pData; // pointer array 153cdf0e10cSrcweir sal_uInt32 nSize; // array size 154cdf0e10cSrcweir sal_uInt32 nNew; // next index to be inserted at 155cdf0e10cSrcweir sal_uInt32 nAct; // actual for iterations 156cdf0e10cSrcweir 157cdf0e10cSrcweir void _Grow( void ); 158cdf0e10cSrcweir inline void Grow( void ); 159cdf0e10cSrcweir protected: 160cdf0e10cSrcweir public: 161cdf0e10cSrcweir MyList( void ); 162cdf0e10cSrcweir virtual ~MyList(); 163cdf0e10cSrcweir 164cdf0e10cSrcweir inline const void* GetObject( sal_uInt32 nIndex ) const; 165cdf0e10cSrcweir inline const void* First( void ); 166cdf0e10cSrcweir inline const void* Next( void ); 167cdf0e10cSrcweir 168cdf0e10cSrcweir inline void Append( void* pNewElement ); 169cdf0e10cSrcweir void Insert( void* pNewLement, sal_uInt32 nPlace ); 170cdf0e10cSrcweir 171cdf0e10cSrcweir inline sal_uInt32 Count( void ) const; 172cdf0e10cSrcweir }; 173cdf0e10cSrcweir 174cdf0e10cSrcweir 175cdf0e10cSrcweir 176cdf0e10cSrcweir 177cdf0e10cSrcweir class StringList : protected MyList 178cdf0e10cSrcweir { 179cdf0e10cSrcweir public: 180cdf0e10cSrcweir virtual ~StringList(); 181cdf0e10cSrcweir 182cdf0e10cSrcweir inline const STRING* First( void ); 183cdf0e10cSrcweir inline const STRING* Next( void ); 184cdf0e10cSrcweir inline const STRING* Get( sal_uInt32 nIndex ) const; 185cdf0e10cSrcweir 186cdf0e10cSrcweir using MyList::Append; 187cdf0e10cSrcweir inline void Append( STRING* pNew ); 188cdf0e10cSrcweir inline void Append( const STRING& rNew ); 189cdf0e10cSrcweir 190cdf0e10cSrcweir using MyList::Count; 191cdf0e10cSrcweir }; 192cdf0e10cSrcweir 193cdf0e10cSrcweir 194cdf0e10cSrcweir 195cdf0e10cSrcweir 196cdf0e10cSrcweir enum FDCategory 197cdf0e10cSrcweir { 198cdf0e10cSrcweir FDCat_AddIn, 199cdf0e10cSrcweir FDCat_DateTime, 200cdf0e10cSrcweir FDCat_Finance, 201cdf0e10cSrcweir FDCat_Inf, 202cdf0e10cSrcweir FDCat_Math, 203cdf0e10cSrcweir FDCat_Tech 204cdf0e10cSrcweir }; 205cdf0e10cSrcweir 206cdf0e10cSrcweir 207cdf0e10cSrcweir struct FuncDataBase 208cdf0e10cSrcweir { 209cdf0e10cSrcweir const sal_Char* pIntName; 210cdf0e10cSrcweir sal_uInt16 nUINameID; // resource ID to UI name 211cdf0e10cSrcweir sal_uInt16 nDescrID; // resource ID to description, parameter names and ~ description 212cdf0e10cSrcweir sal_Bool bDouble; // name already exist in Calc 213cdf0e10cSrcweir sal_Bool bWithOpt; // first parameter is internal 214cdf0e10cSrcweir sal_uInt16 nCompListID; // resource ID to list of valid names 215cdf0e10cSrcweir sal_uInt16 nNumOfParams; // number of named / described parameters 216cdf0e10cSrcweir FDCategory eCat; // function category 217cdf0e10cSrcweir }; 218cdf0e10cSrcweir 219cdf0e10cSrcweir 220cdf0e10cSrcweir 221cdf0e10cSrcweir 222cdf0e10cSrcweir class FuncData 223cdf0e10cSrcweir { 224cdf0e10cSrcweir private: 225cdf0e10cSrcweir ::rtl::OUString aIntName; 226cdf0e10cSrcweir sal_uInt16 nUINameID; 227cdf0e10cSrcweir sal_uInt16 nDescrID; // leads also to parameter descriptions! 228cdf0e10cSrcweir sal_Bool bDouble; // flag for names, wich already exist in Calc 229cdf0e10cSrcweir sal_Bool bWithOpt; // has internal parameter on first position 230cdf0e10cSrcweir 231cdf0e10cSrcweir sal_uInt16 nParam; // num of parameters 232cdf0e10cSrcweir sal_uInt16 nCompID; 233cdf0e10cSrcweir StringList aCompList; // list of all valid names 234cdf0e10cSrcweir FDCategory eCat; // function category 235cdf0e10cSrcweir public: 236cdf0e10cSrcweir FuncData( const FuncDataBase& rBaseData, ResMgr& ); 237cdf0e10cSrcweir virtual ~FuncData(); 238cdf0e10cSrcweir 239cdf0e10cSrcweir inline sal_uInt16 GetUINameID( void ) const; 240cdf0e10cSrcweir inline sal_uInt16 GetDescrID( void ) const; 241cdf0e10cSrcweir inline sal_Bool IsDouble( void ) const; 242cdf0e10cSrcweir inline sal_Bool HasIntParam( void ) const; 243cdf0e10cSrcweir 244cdf0e10cSrcweir sal_uInt16 GetStrIndex( sal_uInt16 nParamNum ) const; 245cdf0e10cSrcweir inline sal_Bool Is( const ::rtl::OUString& rCompareTo ) const; 246cdf0e10cSrcweir 247cdf0e10cSrcweir inline const StringList& GetCompNameList( void ) const; 248cdf0e10cSrcweir 249cdf0e10cSrcweir inline FDCategory GetCategory( void ) const; 250cdf0e10cSrcweir }; 251cdf0e10cSrcweir 252cdf0e10cSrcweir 253cdf0e10cSrcweir 254cdf0e10cSrcweir 255cdf0e10cSrcweir class CStrList : private MyList 256cdf0e10cSrcweir { 257cdf0e10cSrcweir public: 258cdf0e10cSrcweir using MyList::Append; 259cdf0e10cSrcweir inline void Append( const sal_Char* pNew ); 260cdf0e10cSrcweir inline const sal_Char* Get( sal_uInt32 nIndex ) const; 261cdf0e10cSrcweir using MyList::Count; 262cdf0e10cSrcweir }; 263cdf0e10cSrcweir 264cdf0e10cSrcweir 265cdf0e10cSrcweir 266cdf0e10cSrcweir 267cdf0e10cSrcweir class FuncDataList : private MyList 268cdf0e10cSrcweir { 269cdf0e10cSrcweir ::rtl::OUString aLastName; 270cdf0e10cSrcweir sal_uInt32 nLast; 271cdf0e10cSrcweir public: 272cdf0e10cSrcweir FuncDataList( ResMgr& ); 273cdf0e10cSrcweir virtual ~FuncDataList(); 274cdf0e10cSrcweir using MyList::Append; 275cdf0e10cSrcweir inline void Append( FuncData* pNew ); 276cdf0e10cSrcweir inline const FuncData* Get( sal_uInt32 nIndex ) const; 277cdf0e10cSrcweir using MyList::Count; 278cdf0e10cSrcweir 279cdf0e10cSrcweir const FuncData* Get( const ::rtl::OUString& aProgrammaticName ) const; 280cdf0e10cSrcweir }; 281cdf0e10cSrcweir 282cdf0e10cSrcweir 283cdf0e10cSrcweir 284cdf0e10cSrcweir class AnalysisResId : public ResId 285cdf0e10cSrcweir { 286cdf0e10cSrcweir public: 287cdf0e10cSrcweir AnalysisResId( sal_uInt16 nId, ResMgr& rResMgr ); 288cdf0e10cSrcweir }; 289cdf0e10cSrcweir 290cdf0e10cSrcweir 291cdf0e10cSrcweir 292cdf0e10cSrcweir 293cdf0e10cSrcweir class AnalysisRscStrLoader : public Resource 294cdf0e10cSrcweir { 295cdf0e10cSrcweir private: 296cdf0e10cSrcweir String aStr; 297cdf0e10cSrcweir public: 298cdf0e10cSrcweir AnalysisRscStrLoader( sal_uInt16 nRsc, sal_uInt16 nStrId, ResMgr& rResMgr ) : 299cdf0e10cSrcweir Resource( AnalysisResId( nRsc, rResMgr ) ), 300cdf0e10cSrcweir aStr( AnalysisResId( nStrId, rResMgr ) ) 301cdf0e10cSrcweir { 302cdf0e10cSrcweir FreeResource(); 303cdf0e10cSrcweir } 304cdf0e10cSrcweir 305cdf0e10cSrcweir const String& GetString() const { return aStr; } 306cdf0e10cSrcweir 307cdf0e10cSrcweir }; 308cdf0e10cSrcweir 309cdf0e10cSrcweir 310cdf0e10cSrcweir 311cdf0e10cSrcweir //----------------------------------------------------------------------------- 312cdf0e10cSrcweir 313cdf0e10cSrcweir /// sorted list with unique sal_Int32 values 314cdf0e10cSrcweir class SortedIndividualInt32List : private MyList 315cdf0e10cSrcweir { 316cdf0e10cSrcweir protected: 317cdf0e10cSrcweir using MyList::Insert; 318cdf0e10cSrcweir void Insert( sal_Int32 nDay ); 319cdf0e10cSrcweir void Insert( sal_Int32 nDay, sal_Int32 nNullDate, sal_Bool bInsertOnWeekend ); 320cdf0e10cSrcweir void Insert( double fDay, sal_Int32 nNullDate, sal_Bool bInsertOnWeekend ) 321cdf0e10cSrcweir throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 322cdf0e10cSrcweir 323cdf0e10cSrcweir /** @param rAnyConv must be an initialized ScaAnyConmverter 324cdf0e10cSrcweir @param bInsertOnWeekend insertion mode: sal_False = holidays on weekend are omitted */ 325cdf0e10cSrcweir void InsertHolidayList( 326cdf0e10cSrcweir const ScaAnyConverter& rAnyConv, 327cdf0e10cSrcweir const CSS::uno::Any& rHolAny, 328cdf0e10cSrcweir sal_Int32 nNullDate, 329cdf0e10cSrcweir sal_Bool bInsertOnWeekend ) throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 330cdf0e10cSrcweir 331cdf0e10cSrcweir public: 332cdf0e10cSrcweir SortedIndividualInt32List(); 333cdf0e10cSrcweir virtual ~SortedIndividualInt32List(); 334cdf0e10cSrcweir 335cdf0e10cSrcweir using MyList::Count; 336cdf0e10cSrcweir 337cdf0e10cSrcweir /// @return element on position nIndex or 0 on invalid index 338cdf0e10cSrcweir inline sal_Int32 Get( sal_uInt32 nIndex ) const 339cdf0e10cSrcweir { return (sal_Int32)(sal_IntPtr) MyList::GetObject( nIndex ); } 340cdf0e10cSrcweir 341cdf0e10cSrcweir /// @return sal_True if nVal (internal date representation) is contained 342cdf0e10cSrcweir sal_Bool Find( sal_Int32 nVal ) const; 343cdf0e10cSrcweir 344cdf0e10cSrcweir /** @param rAnyConv is an initialized or uninitialized ScaAnyConverter 345cdf0e10cSrcweir @param bInsertOnWeekend insertion mode: sal_False = holidays on weekend are omitted */ 346cdf0e10cSrcweir void InsertHolidayList( 347cdf0e10cSrcweir ScaAnyConverter& rAnyConv, 348cdf0e10cSrcweir const CSS::uno::Reference< CSS::beans::XPropertySet >& xOptions, 349cdf0e10cSrcweir const CSS::uno::Any& rHolAny, 350cdf0e10cSrcweir sal_Int32 nNullDate, 351cdf0e10cSrcweir sal_Bool bInsertOnWeekend ) throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 352cdf0e10cSrcweir }; 353cdf0e10cSrcweir 354cdf0e10cSrcweir 355cdf0e10cSrcweir //----------------------------------------------------------------------------- 356cdf0e10cSrcweir 357cdf0e10cSrcweir class ScaDoubleList : protected MyList 358cdf0e10cSrcweir { 359cdf0e10cSrcweir protected: 360cdf0e10cSrcweir inline void ListAppend( double fValue ) { MyList::Append( new double( fValue ) ); } 361cdf0e10cSrcweir 362cdf0e10cSrcweir using MyList::Append; 363cdf0e10cSrcweir inline void Append( double fValue ) throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ) 364cdf0e10cSrcweir { if( CheckInsert( fValue ) ) ListAppend( fValue ); } 365cdf0e10cSrcweir 366cdf0e10cSrcweir /** @param rAnyConv must be an initialized ScaAnyConmverter 367cdf0e10cSrcweir @param bIgnoreEmpty handling of empty Any's/strings: sal_False = inserted as 0.0; sal_True = omitted */ 368cdf0e10cSrcweir void Append( 369cdf0e10cSrcweir const ScaAnyConverter& rAnyConv, 370cdf0e10cSrcweir const CSS::uno::Any& rAny, 371cdf0e10cSrcweir sal_Bool bIgnoreEmpty ) throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 372cdf0e10cSrcweir 373cdf0e10cSrcweir /** @param rAnyConv must be an initialized ScaAnyConmverter 374cdf0e10cSrcweir @param bIgnoreEmpty handling of empty Any's/strings: sal_False = inserted as 0.0; sal_True = omitted */ 375cdf0e10cSrcweir void Append( 376cdf0e10cSrcweir const ScaAnyConverter& rAnyConv, 377cdf0e10cSrcweir const CSS::uno::Sequence< CSS::uno::Any >& rAnySeq, 378cdf0e10cSrcweir sal_Bool bIgnoreEmpty ) throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 379cdf0e10cSrcweir 380cdf0e10cSrcweir /** @param rAnyConv must be an initialized ScaAnyConmverter 381cdf0e10cSrcweir @param bIgnoreEmpty handling of empty Any's/strings: sal_False = inserted as 0.0; sal_True = omitted */ 382cdf0e10cSrcweir void Append( 383cdf0e10cSrcweir const ScaAnyConverter& rAnyConv, 384cdf0e10cSrcweir const CSS::uno::Sequence< CSS::uno::Sequence< CSS::uno::Any > >& rAnySeq, 385cdf0e10cSrcweir sal_Bool bIgnoreEmpty ) throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 386cdf0e10cSrcweir 387cdf0e10cSrcweir public: 388cdf0e10cSrcweir virtual ~ScaDoubleList(); 389cdf0e10cSrcweir 390cdf0e10cSrcweir using MyList::Count; 391cdf0e10cSrcweir inline const double* Get( sal_uInt32 nIndex ) const 392cdf0e10cSrcweir { return static_cast< const double* >( MyList::GetObject( nIndex ) ); } 393cdf0e10cSrcweir 394cdf0e10cSrcweir inline const double* First() { return static_cast< const double* >( MyList::First() ); } 395cdf0e10cSrcweir inline const double* Next() { return static_cast< const double* >( MyList::Next() ); } 396cdf0e10cSrcweir 397cdf0e10cSrcweir void Append( const CSS::uno::Sequence< CSS::uno::Sequence< double > >& rValueArr ) 398cdf0e10cSrcweir throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 399cdf0e10cSrcweir void Append( const CSS::uno::Sequence< CSS::uno::Sequence< sal_Int32 > >& rValueArr ) 400cdf0e10cSrcweir throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 401cdf0e10cSrcweir 402cdf0e10cSrcweir /** @param rAnyConv is an initialized or uninitialized ScaAnyConverter 403cdf0e10cSrcweir @param bIgnoreEmpty handling of empty Any's/strings: sal_False = inserted as 0.0; sal_True = omitted */ 404cdf0e10cSrcweir void Append( 405cdf0e10cSrcweir ScaAnyConverter& rAnyConv, 406cdf0e10cSrcweir const CSS::uno::Reference< CSS::beans::XPropertySet >& xOpt, 407cdf0e10cSrcweir const CSS::uno::Sequence< CSS::uno::Any >& rAnySeq, 408cdf0e10cSrcweir sal_Bool bIgnoreEmpty = sal_True ) throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 409cdf0e10cSrcweir 410cdf0e10cSrcweir virtual sal_Bool CheckInsert( double fValue ) const 411cdf0e10cSrcweir throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 412cdf0e10cSrcweir }; 413cdf0e10cSrcweir 414cdf0e10cSrcweir 415cdf0e10cSrcweir //----------------------------------------------------------------------------- 416cdf0e10cSrcweir 417cdf0e10cSrcweir /// stores double values >0.0, throws exception for double values <0.0, does nothing for 0.0 418cdf0e10cSrcweir class ScaDoubleListGT0 : public ScaDoubleList 419cdf0e10cSrcweir { 420cdf0e10cSrcweir public: 421cdf0e10cSrcweir virtual sal_Bool CheckInsert( double fValue ) const 422cdf0e10cSrcweir throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 423cdf0e10cSrcweir }; 424cdf0e10cSrcweir 425cdf0e10cSrcweir 426cdf0e10cSrcweir //----------------------------------------------------------------------------- 427cdf0e10cSrcweir 428cdf0e10cSrcweir /// stores double values >=0.0, throws exception for double values <0.0 429cdf0e10cSrcweir class ScaDoubleListGE0 : public ScaDoubleList 430cdf0e10cSrcweir { 431cdf0e10cSrcweir public: 432cdf0e10cSrcweir virtual sal_Bool CheckInsert( double fValue ) const 433cdf0e10cSrcweir throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 434cdf0e10cSrcweir }; 435cdf0e10cSrcweir 436cdf0e10cSrcweir 437cdf0e10cSrcweir //----------------------------------------------------------------------------- 438cdf0e10cSrcweir 439cdf0e10cSrcweir class Complex 440cdf0e10cSrcweir { 441cdf0e10cSrcweir double r; 442cdf0e10cSrcweir double i; 443cdf0e10cSrcweir sal_Unicode c; 444cdf0e10cSrcweir 445cdf0e10cSrcweir public: 446*feb8f109SRegina Henschel inline Complex( double fReal, double fImag = 0.0, sal_Unicode cC = '\0' ); 447cdf0e10cSrcweir Complex( const STRING& rComplexAsString ) THROWDEF_RTE_IAE; 448cdf0e10cSrcweir 449cdf0e10cSrcweir inline static sal_Bool IsImagUnit( sal_Unicode c ); 450cdf0e10cSrcweir static sal_Bool ParseString( const STRING& rComplexAsString, Complex& rReturn ); 451cdf0e10cSrcweir STRING GetString() const THROWDEF_RTE_IAE; 452cdf0e10cSrcweir 453cdf0e10cSrcweir inline double Real( void ) const; 454cdf0e10cSrcweir inline double Imag( void ) const; 455cdf0e10cSrcweir 456cdf0e10cSrcweir double Arg( void ) const THROWDEF_RTE_IAE; 457cdf0e10cSrcweir inline double Abs( void ) const; 458cdf0e10cSrcweir 459cdf0e10cSrcweir // following functions change the complex number itself to avoid unnecessary copy actions! 460cdf0e10cSrcweir void Power( double fPower ) THROWDEF_RTE_IAE; 461cdf0e10cSrcweir void Sqrt( void ); 462cdf0e10cSrcweir void Sin( void ) THROWDEF_RTE_IAE; 463cdf0e10cSrcweir void Cos( void ) THROWDEF_RTE_IAE; 464cdf0e10cSrcweir void Div( const Complex& rDivisor ) THROWDEF_RTE_IAE; 465cdf0e10cSrcweir void Exp( void ); 466cdf0e10cSrcweir inline void Conjugate( void ); 467cdf0e10cSrcweir void Ln( void ) THROWDEF_RTE_IAE; 468cdf0e10cSrcweir void Log10( void ) THROWDEF_RTE_IAE; 469cdf0e10cSrcweir void Log2( void ) THROWDEF_RTE_IAE; 470cdf0e10cSrcweir inline void Mult( double fFact ); 471cdf0e10cSrcweir inline void Mult( const Complex& rMult ); 472cdf0e10cSrcweir inline void Sub( const Complex& rMult ); 473cdf0e10cSrcweir inline void Add( const Complex& rAdd ); 474*feb8f109SRegina Henschel void Tan( void ) THROWDEF_RTE_IAE; 475*feb8f109SRegina Henschel void Sec( void ) THROWDEF_RTE_IAE; 476*feb8f109SRegina Henschel void Csc( void ) THROWDEF_RTE_IAE; 477*feb8f109SRegina Henschel void Cot( void ) THROWDEF_RTE_IAE; 478*feb8f109SRegina Henschel void Sinh( void ) THROWDEF_RTE_IAE; 479*feb8f109SRegina Henschel void Cosh( void ) THROWDEF_RTE_IAE; 480*feb8f109SRegina Henschel void Sech( void ) THROWDEF_RTE_IAE; 481*feb8f109SRegina Henschel void Csch( void ) THROWDEF_RTE_IAE; 482*feb8f109SRegina Henschel 483cdf0e10cSrcweir }; 484cdf0e10cSrcweir 485cdf0e10cSrcweir 486cdf0e10cSrcweir 487cdf0e10cSrcweir 488cdf0e10cSrcweir enum ComplListAppendHandl 489cdf0e10cSrcweir { 490cdf0e10cSrcweir AH_EmptyAsErr, 491cdf0e10cSrcweir AH_EmpyAs0, 492cdf0e10cSrcweir AH_IgnoreEmpty 493cdf0e10cSrcweir }; 494cdf0e10cSrcweir 495cdf0e10cSrcweir 496cdf0e10cSrcweir class ComplexList : protected MyList 497cdf0e10cSrcweir { 498cdf0e10cSrcweir public: 499cdf0e10cSrcweir virtual ~ComplexList(); 500cdf0e10cSrcweir 501cdf0e10cSrcweir inline const Complex* Get( sal_uInt32 nIndex ) const; 502cdf0e10cSrcweir inline const Complex* First( void ); 503cdf0e10cSrcweir inline const Complex* Next( void ); 504cdf0e10cSrcweir 505cdf0e10cSrcweir using MyList::Count; 506cdf0e10cSrcweir 507cdf0e10cSrcweir using MyList::Append; 508cdf0e10cSrcweir inline void Append( Complex* pNew ); 509cdf0e10cSrcweir void Append( const SEQSEQ( STRING )& rComplexNumList, ComplListAppendHandl eAH = AH_EmpyAs0 ) THROWDEF_RTE_IAE; 510cdf0e10cSrcweir void Append( const SEQ( ANY )& aMultPars,ComplListAppendHandl eAH = AH_EmpyAs0 ) THROWDEF_RTE_IAE; 511cdf0e10cSrcweir }; 512cdf0e10cSrcweir 513cdf0e10cSrcweir 514cdf0e10cSrcweir 515cdf0e10cSrcweir 516cdf0e10cSrcweir enum ConvertDataClass 517cdf0e10cSrcweir { 518cdf0e10cSrcweir CDC_Mass, CDC_Length, CDC_Time, CDC_Pressure, CDC_Force, CDC_Energy, CDC_Power, CDC_Magnetism, 519cdf0e10cSrcweir CDC_Temperature, CDC_Volume, CDC_Area, CDC_Speed, CDC_Information 520cdf0e10cSrcweir }; 521cdf0e10cSrcweir 522cdf0e10cSrcweir 523cdf0e10cSrcweir #define INV_MATCHLEV 1764 // guess, what this is... :-) 524cdf0e10cSrcweir 525cdf0e10cSrcweir 526cdf0e10cSrcweir class ConvertDataList; 527cdf0e10cSrcweir 528cdf0e10cSrcweir 529cdf0e10cSrcweir 530cdf0e10cSrcweir 531cdf0e10cSrcweir class ConvertData 532cdf0e10cSrcweir { 533cdf0e10cSrcweir protected: 534cdf0e10cSrcweir friend class ConvertDataList; 535cdf0e10cSrcweir double fConst; 536cdf0e10cSrcweir STRING aName; 537cdf0e10cSrcweir ConvertDataClass eClass; 538cdf0e10cSrcweir sal_Bool bPrefixSupport; 539cdf0e10cSrcweir public: 540cdf0e10cSrcweir ConvertData( 541cdf0e10cSrcweir const sal_Char pUnitName[], 542cdf0e10cSrcweir double fConvertConstant, 543cdf0e10cSrcweir ConvertDataClass eClass, 544cdf0e10cSrcweir sal_Bool bPrefSupport = sal_False ); 545cdf0e10cSrcweir 546cdf0e10cSrcweir virtual ~ConvertData(); 547cdf0e10cSrcweir 548cdf0e10cSrcweir sal_Int16 GetMatchingLevel( const STRING& rRef ) const; 549cdf0e10cSrcweir // 0.0 = no equality 550cdf0e10cSrcweir // 1.0 = matches exact 551cdf0e10cSrcweir // rest = matches without an assumed prefix of one character 552cdf0e10cSrcweir // rest gives power for 10 represented by the prefix (e.g. 3 for k or -9 for n 553cdf0e10cSrcweir 554cdf0e10cSrcweir virtual double Convert( double fVal, const ConvertData& rTo, 555cdf0e10cSrcweir sal_Int16 nMatchLevelFrom, sal_Int16 nMatchLevelTo ) const THROWDEF_RTE_IAE; 556cdf0e10cSrcweir // converts fVal from this unit to rFrom unit 557cdf0e10cSrcweir // throws exception if not from same class 558cdf0e10cSrcweir // this implementation is for proportional cases only 559cdf0e10cSrcweir virtual double ConvertToBase( double fVal, sal_Int16 nMatchLevel ) const; 560cdf0e10cSrcweir virtual double ConvertFromBase( double fVal, sal_Int16 nMatchLevel ) const; 561cdf0e10cSrcweir 562cdf0e10cSrcweir inline ConvertDataClass Class( void ) const; 563cdf0e10cSrcweir inline sal_Bool IsPrefixSupport( void ) const; 564cdf0e10cSrcweir }; 565cdf0e10cSrcweir 566cdf0e10cSrcweir 567cdf0e10cSrcweir 568cdf0e10cSrcweir 569cdf0e10cSrcweir class ConvertDataLinear : public ConvertData 570cdf0e10cSrcweir { 571cdf0e10cSrcweir protected: 572cdf0e10cSrcweir double fOffs; 573cdf0e10cSrcweir public: 574cdf0e10cSrcweir inline ConvertDataLinear( 575cdf0e10cSrcweir const sal_Char pUnitName[], 576cdf0e10cSrcweir double fConvertConstant, 577cdf0e10cSrcweir double fConvertOffset, 578cdf0e10cSrcweir ConvertDataClass eClass, 579cdf0e10cSrcweir sal_Bool bPrefSupport = sal_False ); 580cdf0e10cSrcweir 581cdf0e10cSrcweir virtual ~ConvertDataLinear(); 582cdf0e10cSrcweir 583cdf0e10cSrcweir virtual double Convert( double fVal, const ConvertData& rTo, 584cdf0e10cSrcweir sal_Int16 nMatchLevelFrom, sal_Int16 nMatchLevelTo ) const THROWDEF_RTE_IAE; 585cdf0e10cSrcweir // for cases where f(x) = a + bx applies (e.g. Temperatures) 586cdf0e10cSrcweir 587cdf0e10cSrcweir virtual double ConvertToBase( double fVal, sal_Int16 nMatchLevel ) const; 588cdf0e10cSrcweir virtual double ConvertFromBase( double fVal, sal_Int16 nMatchLevel ) const; 589cdf0e10cSrcweir }; 590cdf0e10cSrcweir 591cdf0e10cSrcweir 592cdf0e10cSrcweir 593cdf0e10cSrcweir 594cdf0e10cSrcweir class ConvertDataList : protected MyList 595cdf0e10cSrcweir { 596cdf0e10cSrcweir private: 597cdf0e10cSrcweir protected: 598cdf0e10cSrcweir inline ConvertData* First( void ); 599cdf0e10cSrcweir inline ConvertData* Next( void ); 600cdf0e10cSrcweir public: 601cdf0e10cSrcweir ConvertDataList( void ); 602cdf0e10cSrcweir virtual ~ConvertDataList(); 603cdf0e10cSrcweir 604cdf0e10cSrcweir double Convert( double fVal, const STRING& rFrom, const STRING& rTo ) THROWDEF_RTE_IAE; 605cdf0e10cSrcweir }; 606cdf0e10cSrcweir 607cdf0e10cSrcweir 608cdf0e10cSrcweir 609cdf0e10cSrcweir 610cdf0e10cSrcweir inline sal_Bool IsLeapYear( sal_uInt16 n ) 611cdf0e10cSrcweir { 612cdf0e10cSrcweir return ( (( ( n % 4 ) == 0 ) && ( ( n % 100 ) != 0)) || ( ( n % 400 ) == 0 ) ); 613cdf0e10cSrcweir } 614cdf0e10cSrcweir 615cdf0e10cSrcweir 616cdf0e10cSrcweir inline sal_Int32 GetDiffDate360( constREFXPS& xOpt, sal_Int32 nDate1, sal_Int32 nDate2, sal_Bool bUSAMethod ) 617cdf0e10cSrcweir { 618cdf0e10cSrcweir return GetDiffDate360( GetNullDate( xOpt ), nDate1, nDate2, bUSAMethod ); 619cdf0e10cSrcweir } 620cdf0e10cSrcweir 621cdf0e10cSrcweir 622cdf0e10cSrcweir inline sal_Int16 GetDayOfWeek( sal_Int32 n ) 623cdf0e10cSrcweir { // monday = 0, ..., sunday = 6 624cdf0e10cSrcweir return static_cast< sal_Int16 >( ( n - 1 ) % 7 ); 625cdf0e10cSrcweir } 626cdf0e10cSrcweir 627cdf0e10cSrcweir 628cdf0e10cSrcweir inline double GetYearFrac( constREFXPS& xOpt, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode ) THROWDEF_RTE_IAE 629cdf0e10cSrcweir { 630cdf0e10cSrcweir return GetYearFrac( GetNullDate( xOpt ), nStartDate, nEndDate, nMode ); 631cdf0e10cSrcweir } 632cdf0e10cSrcweir 633cdf0e10cSrcweir 634cdf0e10cSrcweir inline void AlignDate( sal_uInt16& rD, sal_uInt16 nM, sal_uInt16 nY ) 635cdf0e10cSrcweir { 636cdf0e10cSrcweir sal_uInt16 nMax = DaysInMonth( nM, nY ); 637cdf0e10cSrcweir 638cdf0e10cSrcweir if( rD > nMax ) 639cdf0e10cSrcweir rD = nMax; 640cdf0e10cSrcweir } 641cdf0e10cSrcweir 642cdf0e10cSrcweir 643cdf0e10cSrcweir inline void MyList::Grow( void ) 644cdf0e10cSrcweir { 645cdf0e10cSrcweir if( nNew >= nSize ) 646cdf0e10cSrcweir _Grow(); 647cdf0e10cSrcweir } 648cdf0e10cSrcweir 649cdf0e10cSrcweir 650cdf0e10cSrcweir inline const void* MyList::GetObject( sal_uInt32 n ) const 651cdf0e10cSrcweir { 652cdf0e10cSrcweir if( n < nNew ) 653cdf0e10cSrcweir return pData[ n ]; 654cdf0e10cSrcweir else 655cdf0e10cSrcweir return NULL; 656cdf0e10cSrcweir } 657cdf0e10cSrcweir 658cdf0e10cSrcweir 659cdf0e10cSrcweir inline const void* MyList::First( void ) 660cdf0e10cSrcweir { 661cdf0e10cSrcweir nAct = 0; 662cdf0e10cSrcweir if( nNew ) 663cdf0e10cSrcweir return pData[ 0 ]; 664cdf0e10cSrcweir else 665cdf0e10cSrcweir return NULL; 666cdf0e10cSrcweir } 667cdf0e10cSrcweir 668cdf0e10cSrcweir 669cdf0e10cSrcweir inline const void* MyList::Next( void ) 670cdf0e10cSrcweir { 671cdf0e10cSrcweir nAct++; 672cdf0e10cSrcweir if( nAct < nNew ) 673cdf0e10cSrcweir return pData[ nAct ]; 674cdf0e10cSrcweir else 675cdf0e10cSrcweir { 676cdf0e10cSrcweir nAct--; 677cdf0e10cSrcweir return NULL; 678cdf0e10cSrcweir } 679cdf0e10cSrcweir } 680cdf0e10cSrcweir 681cdf0e10cSrcweir 682cdf0e10cSrcweir inline void MyList::Append( void* p ) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir Grow(); 685cdf0e10cSrcweir pData[ nNew ] = p; 686cdf0e10cSrcweir nNew++; 687cdf0e10cSrcweir } 688cdf0e10cSrcweir 689cdf0e10cSrcweir 690cdf0e10cSrcweir inline sal_uInt32 MyList::Count( void ) const 691cdf0e10cSrcweir { 692cdf0e10cSrcweir return nNew; 693cdf0e10cSrcweir } 694cdf0e10cSrcweir 695cdf0e10cSrcweir 696cdf0e10cSrcweir 697cdf0e10cSrcweir 698cdf0e10cSrcweir inline const STRING* StringList::First( void ) 699cdf0e10cSrcweir { 700cdf0e10cSrcweir return ( const STRING* ) MyList::First(); 701cdf0e10cSrcweir } 702cdf0e10cSrcweir 703cdf0e10cSrcweir 704cdf0e10cSrcweir inline const STRING* StringList::Next( void ) 705cdf0e10cSrcweir { 706cdf0e10cSrcweir return ( const STRING* ) MyList::Next(); 707cdf0e10cSrcweir } 708cdf0e10cSrcweir 709cdf0e10cSrcweir 710cdf0e10cSrcweir inline const STRING* StringList::Get( sal_uInt32 n ) const 711cdf0e10cSrcweir { 712cdf0e10cSrcweir return ( const STRING* ) MyList::GetObject( n ); 713cdf0e10cSrcweir } 714cdf0e10cSrcweir 715cdf0e10cSrcweir 716cdf0e10cSrcweir inline void StringList::Append( STRING* p ) 717cdf0e10cSrcweir { 718cdf0e10cSrcweir MyList::Append( p ); 719cdf0e10cSrcweir } 720cdf0e10cSrcweir 721cdf0e10cSrcweir 722cdf0e10cSrcweir inline void StringList::Append( const STRING& r ) 723cdf0e10cSrcweir { 724cdf0e10cSrcweir MyList::Append( new STRING( r ) ); 725cdf0e10cSrcweir } 726cdf0e10cSrcweir 727cdf0e10cSrcweir 728cdf0e10cSrcweir 729cdf0e10cSrcweir 730cdf0e10cSrcweir inline sal_uInt16 FuncData::GetUINameID( void ) const 731cdf0e10cSrcweir { 732cdf0e10cSrcweir return nUINameID; 733cdf0e10cSrcweir } 734cdf0e10cSrcweir 735cdf0e10cSrcweir 736cdf0e10cSrcweir inline sal_uInt16 FuncData::GetDescrID( void ) const 737cdf0e10cSrcweir { 738cdf0e10cSrcweir return nDescrID; 739cdf0e10cSrcweir } 740cdf0e10cSrcweir 741cdf0e10cSrcweir 742cdf0e10cSrcweir inline sal_Bool FuncData::IsDouble( void ) const 743cdf0e10cSrcweir { 744cdf0e10cSrcweir return bDouble; 745cdf0e10cSrcweir } 746cdf0e10cSrcweir 747cdf0e10cSrcweir 748cdf0e10cSrcweir inline sal_Bool FuncData::HasIntParam( void ) const 749cdf0e10cSrcweir { 750cdf0e10cSrcweir return bWithOpt; 751cdf0e10cSrcweir } 752cdf0e10cSrcweir 753cdf0e10cSrcweir 754cdf0e10cSrcweir inline sal_Bool FuncData::Is( const ::rtl::OUString& r ) const 755cdf0e10cSrcweir { 756cdf0e10cSrcweir return aIntName == r; 757cdf0e10cSrcweir } 758cdf0e10cSrcweir 759cdf0e10cSrcweir 760cdf0e10cSrcweir inline const StringList& FuncData::GetCompNameList( void ) const 761cdf0e10cSrcweir { 762cdf0e10cSrcweir return aCompList; 763cdf0e10cSrcweir } 764cdf0e10cSrcweir 765cdf0e10cSrcweir 766cdf0e10cSrcweir inline FDCategory FuncData::GetCategory( void ) const 767cdf0e10cSrcweir { 768cdf0e10cSrcweir return eCat; 769cdf0e10cSrcweir } 770cdf0e10cSrcweir 771cdf0e10cSrcweir 772cdf0e10cSrcweir 773cdf0e10cSrcweir 774cdf0e10cSrcweir inline void CStrList::Append( const sal_Char* p ) 775cdf0e10cSrcweir { 776cdf0e10cSrcweir MyList::Append( ( void* ) p ); 777cdf0e10cSrcweir } 778cdf0e10cSrcweir 779cdf0e10cSrcweir 780cdf0e10cSrcweir inline const sal_Char* CStrList::Get( sal_uInt32 n ) const 781cdf0e10cSrcweir { 782cdf0e10cSrcweir return ( const sal_Char* ) MyList::GetObject( n ); 783cdf0e10cSrcweir } 784cdf0e10cSrcweir 785cdf0e10cSrcweir 786cdf0e10cSrcweir 787cdf0e10cSrcweir 788cdf0e10cSrcweir inline void FuncDataList::Append( FuncData* p ) 789cdf0e10cSrcweir { 790cdf0e10cSrcweir MyList::Append( p ); 791cdf0e10cSrcweir } 792cdf0e10cSrcweir 793cdf0e10cSrcweir 794cdf0e10cSrcweir inline const FuncData* FuncDataList::Get( sal_uInt32 n ) const 795cdf0e10cSrcweir { 796cdf0e10cSrcweir return ( const FuncData* ) MyList::GetObject( n ); 797cdf0e10cSrcweir } 798cdf0e10cSrcweir 799cdf0e10cSrcweir 800*feb8f109SRegina Henschel inline Complex::Complex( double fReal, double fImag, sal_Unicode cC ) : 801cdf0e10cSrcweir r( fReal ), i( fImag ), c( cC ) 802cdf0e10cSrcweir { 803cdf0e10cSrcweir } 804cdf0e10cSrcweir 805cdf0e10cSrcweir 806cdf0e10cSrcweir inline double Complex::Real( void ) const 807cdf0e10cSrcweir { 808cdf0e10cSrcweir return r; 809cdf0e10cSrcweir } 810cdf0e10cSrcweir 811cdf0e10cSrcweir 812cdf0e10cSrcweir inline double Complex::Imag( void ) const 813cdf0e10cSrcweir { 814cdf0e10cSrcweir return i; 815cdf0e10cSrcweir } 816cdf0e10cSrcweir 817cdf0e10cSrcweir 818cdf0e10cSrcweir inline double Complex::Abs( void ) const 819cdf0e10cSrcweir { 820cdf0e10cSrcweir return sqrt( r * r + i * i ); 821cdf0e10cSrcweir } 822cdf0e10cSrcweir 823cdf0e10cSrcweir 824cdf0e10cSrcweir void Complex::Conjugate( void ) 825cdf0e10cSrcweir { 826cdf0e10cSrcweir i = -i; 827cdf0e10cSrcweir } 828cdf0e10cSrcweir 829cdf0e10cSrcweir 830cdf0e10cSrcweir inline void Complex::Mult( double f ) 831cdf0e10cSrcweir { 832cdf0e10cSrcweir i *= f; 833cdf0e10cSrcweir r *= f; 834cdf0e10cSrcweir } 835cdf0e10cSrcweir 836cdf0e10cSrcweir 837cdf0e10cSrcweir inline void Complex::Mult( const Complex& rM ) 838cdf0e10cSrcweir { 839cdf0e10cSrcweir double r_ = r; 840cdf0e10cSrcweir double i_ = i; 841cdf0e10cSrcweir 842cdf0e10cSrcweir r = r_ * rM.r - i_ * rM.i; 843cdf0e10cSrcweir i = r_ * rM.i + i_ * rM.r; 844cdf0e10cSrcweir 845cdf0e10cSrcweir if( !c ) c = rM.c; 846cdf0e10cSrcweir } 847cdf0e10cSrcweir 848cdf0e10cSrcweir 849cdf0e10cSrcweir inline void Complex::Sub( const Complex& rC ) 850cdf0e10cSrcweir { 851cdf0e10cSrcweir r -= rC.r; 852cdf0e10cSrcweir i -= rC.i; 853cdf0e10cSrcweir if( !c ) c = rC.c; 854cdf0e10cSrcweir } 855cdf0e10cSrcweir 856cdf0e10cSrcweir 857cdf0e10cSrcweir inline void Complex::Add( const Complex& rAdd ) 858cdf0e10cSrcweir { 859cdf0e10cSrcweir r += rAdd.r; 860cdf0e10cSrcweir i += rAdd.i; 861cdf0e10cSrcweir if( !c ) c = rAdd.c; 862cdf0e10cSrcweir } 863cdf0e10cSrcweir 864cdf0e10cSrcweir 865cdf0e10cSrcweir 866cdf0e10cSrcweir 867cdf0e10cSrcweir inline const Complex* ComplexList::Get( sal_uInt32 n ) const 868cdf0e10cSrcweir { 869cdf0e10cSrcweir return ( const Complex* ) MyList::GetObject( n ); 870cdf0e10cSrcweir } 871cdf0e10cSrcweir 872cdf0e10cSrcweir 873cdf0e10cSrcweir inline const Complex* ComplexList::First( void ) 874cdf0e10cSrcweir { 875cdf0e10cSrcweir return ( const Complex* ) MyList::First(); 876cdf0e10cSrcweir } 877cdf0e10cSrcweir 878cdf0e10cSrcweir 879cdf0e10cSrcweir inline const Complex* ComplexList::Next( void ) 880cdf0e10cSrcweir { 881cdf0e10cSrcweir return ( const Complex* ) MyList::Next(); 882cdf0e10cSrcweir } 883cdf0e10cSrcweir 884cdf0e10cSrcweir 885cdf0e10cSrcweir inline void ComplexList::Append( Complex* p ) 886cdf0e10cSrcweir { 887cdf0e10cSrcweir MyList::Append( p ); 888cdf0e10cSrcweir } 889cdf0e10cSrcweir 890cdf0e10cSrcweir 891cdf0e10cSrcweir 892cdf0e10cSrcweir 893cdf0e10cSrcweir inline ConvertDataClass ConvertData::Class( void ) const 894cdf0e10cSrcweir { 895cdf0e10cSrcweir return eClass; 896cdf0e10cSrcweir } 897cdf0e10cSrcweir 898cdf0e10cSrcweir 899cdf0e10cSrcweir 900cdf0e10cSrcweir inline sal_Bool ConvertData::IsPrefixSupport( void ) const 901cdf0e10cSrcweir { 902cdf0e10cSrcweir return bPrefixSupport; 903cdf0e10cSrcweir } 904cdf0e10cSrcweir 905cdf0e10cSrcweir inline ConvertDataLinear::ConvertDataLinear( const sal_Char* p, double fC, double fO, ConvertDataClass e, 906cdf0e10cSrcweir sal_Bool bPrefSupport ) : 907cdf0e10cSrcweir ConvertData( p, fC, e, bPrefSupport ), 908cdf0e10cSrcweir fOffs( fO ) 909cdf0e10cSrcweir { 910cdf0e10cSrcweir } 911cdf0e10cSrcweir 912cdf0e10cSrcweir 913cdf0e10cSrcweir 914cdf0e10cSrcweir 915cdf0e10cSrcweir inline ConvertData* ConvertDataList::First( void ) 916cdf0e10cSrcweir { 917cdf0e10cSrcweir return ( ConvertData* ) MyList::First(); 918cdf0e10cSrcweir } 919cdf0e10cSrcweir 920cdf0e10cSrcweir 921cdf0e10cSrcweir inline ConvertData* ConvertDataList::Next( void ) 922cdf0e10cSrcweir { 923cdf0e10cSrcweir return ( ConvertData* ) MyList::Next(); 924cdf0e10cSrcweir } 925cdf0e10cSrcweir 926cdf0e10cSrcweir //----------------------------------------------------------------------------- 927cdf0e10cSrcweir 928cdf0e10cSrcweir /// Helper class for date calculation for various financial functions 929cdf0e10cSrcweir class ScaDate 930cdf0e10cSrcweir { 931cdf0e10cSrcweir private: 932cdf0e10cSrcweir sal_uInt16 nOrigDay; /// is the day of the original date. 933cdf0e10cSrcweir sal_uInt16 nDay; /// is the calculated day depending on the current month/year. 934cdf0e10cSrcweir sal_uInt16 nMonth; /// is the current month (one-based). 935cdf0e10cSrcweir sal_uInt16 nYear; /// is the current year. 936cdf0e10cSrcweir sal_Bool bLastDayMode : 1; /// if sal_True, recalculate nDay after every calculation. 937cdf0e10cSrcweir sal_Bool bLastDay : 1; /// is sal_True, if original date was the last day in month. 938cdf0e10cSrcweir sal_Bool b30Days : 1; /// is sal_True, if every month has 30 days in calculations. 939cdf0e10cSrcweir sal_Bool bUSMode : 1; /// is sal_True, if the US method of 30-day-calculations is used. 940cdf0e10cSrcweir 941cdf0e10cSrcweir /// Calculates nDay from nOrigDay and current date. 942cdf0e10cSrcweir void setDay(); 943cdf0e10cSrcweir 944cdf0e10cSrcweir /// @return count of days in current month 945cdf0e10cSrcweir inline sal_uInt16 getDaysInMonth() const; 946cdf0e10cSrcweir /// @return count of days in given month 947cdf0e10cSrcweir inline sal_uInt16 getDaysInMonth( sal_uInt16 _nMon ) const; 948cdf0e10cSrcweir 949cdf0e10cSrcweir /// @ return count of days in the given month range 950cdf0e10cSrcweir sal_Int32 getDaysInMonthRange( sal_uInt16 nFrom, sal_uInt16 nTo ) const; 951cdf0e10cSrcweir /// @ return count of days in the given year range 952cdf0e10cSrcweir sal_Int32 getDaysInYearRange( sal_uInt16 nFrom, sal_uInt16 nTo ) const; 953cdf0e10cSrcweir 954cdf0e10cSrcweir /// Adds/subtracts the given count of years, does not adjust day. 955cdf0e10cSrcweir void doAddYears( sal_Int32 nYearCount ) throw( CSS::lang::IllegalArgumentException ); 956cdf0e10cSrcweir 957cdf0e10cSrcweir public: 958cdf0e10cSrcweir ScaDate(); 959cdf0e10cSrcweir /** @param nBase 960cdf0e10cSrcweir date handling mode (days in month / days in year): 961cdf0e10cSrcweir 0 = 30 days / 360 days (US NASD) 962cdf0e10cSrcweir 1 = exact / exact 963cdf0e10cSrcweir 2 = exact / 360 964cdf0e10cSrcweir 3 = exact / 365 965cdf0e10cSrcweir 4 = 30 days / 360 days (Europe) 966cdf0e10cSrcweir 5 = exact / exact (no last day adjustment) */ 967cdf0e10cSrcweir ScaDate( sal_Int32 nNullDate, sal_Int32 nDate, sal_Int32 nBase ); 968cdf0e10cSrcweir ScaDate( const ScaDate& rCopy ); 969cdf0e10cSrcweir ScaDate& operator=( const ScaDate& rCopy ); 970cdf0e10cSrcweir 971cdf0e10cSrcweir /// @return the current month. 972cdf0e10cSrcweir inline sal_uInt16 getMonth() const { return nMonth; }; 973cdf0e10cSrcweir /// @return the current year. 974cdf0e10cSrcweir inline sal_uInt16 getYear() const { return nYear; }; 975cdf0e10cSrcweir 976cdf0e10cSrcweir /// adds/subtracts the given count of months, adjusts day 977cdf0e10cSrcweir void addMonths( sal_Int32 nMonthCount ) throw( CSS::lang::IllegalArgumentException ); 978cdf0e10cSrcweir 979cdf0e10cSrcweir /// sets the given year, adjusts day 980cdf0e10cSrcweir inline void setYear( sal_uInt16 nNewYear ); 981cdf0e10cSrcweir /// adds/subtracts the given count of years, adjusts day 982cdf0e10cSrcweir inline void addYears( sal_Int32 nYearCount ) throw( CSS::lang::IllegalArgumentException ); 983cdf0e10cSrcweir 984cdf0e10cSrcweir /// @return the internal number of the current date 985cdf0e10cSrcweir sal_Int32 getDate( sal_Int32 nNullDate ) const; 986cdf0e10cSrcweir /// @return the number of days between the two dates 987cdf0e10cSrcweir static sal_Int32 getDiff( const ScaDate& rFrom, const ScaDate& rTo ) throw( CSS::lang::IllegalArgumentException ); 988cdf0e10cSrcweir 989cdf0e10cSrcweir sal_Bool operator<( const ScaDate& rCmp ) const; 990cdf0e10cSrcweir inline sal_Bool operator<=( const ScaDate& rCmp ) const { return !(rCmp < *this); } 991cdf0e10cSrcweir inline sal_Bool operator>( const ScaDate& rCmp ) const { return rCmp < *this; } 992cdf0e10cSrcweir inline sal_Bool operator>=( const ScaDate& rCmp ) const { return !(*this < rCmp); } 993cdf0e10cSrcweir }; 994cdf0e10cSrcweir 995cdf0e10cSrcweir inline sal_uInt16 ScaDate::getDaysInMonth() const 996cdf0e10cSrcweir { 997cdf0e10cSrcweir return getDaysInMonth( nMonth ); 998cdf0e10cSrcweir } 999cdf0e10cSrcweir 1000cdf0e10cSrcweir inline sal_uInt16 ScaDate::getDaysInMonth( sal_uInt16 _nMon ) const 1001cdf0e10cSrcweir { 1002cdf0e10cSrcweir return b30Days ? 30 : DaysInMonth( _nMon, nYear ); 1003cdf0e10cSrcweir } 1004cdf0e10cSrcweir 1005cdf0e10cSrcweir inline void ScaDate::setYear( sal_uInt16 nNewYear ) 1006cdf0e10cSrcweir { 1007cdf0e10cSrcweir nYear = nNewYear; 1008cdf0e10cSrcweir setDay(); 1009cdf0e10cSrcweir } 1010cdf0e10cSrcweir 1011cdf0e10cSrcweir inline void ScaDate::addYears( sal_Int32 nYearCount ) throw( CSS::lang::IllegalArgumentException ) 1012cdf0e10cSrcweir { 1013cdf0e10cSrcweir doAddYears( nYearCount ); 1014cdf0e10cSrcweir setDay(); 1015cdf0e10cSrcweir } 1016cdf0e10cSrcweir 1017cdf0e10cSrcweir 1018cdf0e10cSrcweir //----------------------------------------------------------------------------- 1019cdf0e10cSrcweir 1020cdf0e10cSrcweir /// Helper class for Any->double conversion, using current language settings 1021cdf0e10cSrcweir class ScaAnyConverter 1022cdf0e10cSrcweir { 1023cdf0e10cSrcweir private: 1024cdf0e10cSrcweir CSS::uno::Reference< CSS::util::XNumberFormatter > xFormatter; 1025cdf0e10cSrcweir sal_Int32 nDefaultFormat; 1026cdf0e10cSrcweir sal_Bool bHasValidFormat; 1027cdf0e10cSrcweir 1028cdf0e10cSrcweir /** Converts a string to double using the number formatter. If the formatter is not 1029cdf0e10cSrcweir valid, ::rtl::math::stringToDouble() with english separators will be used. 1030cdf0e10cSrcweir @throws com::sun::star::lang::IllegalArgumentException 1031cdf0e10cSrcweir on strings not representing any double value. 1032cdf0e10cSrcweir @return the converted double value. */ 1033cdf0e10cSrcweir double convertToDouble( 1034cdf0e10cSrcweir const ::rtl::OUString& rString ) const 1035cdf0e10cSrcweir throw( CSS::lang::IllegalArgumentException ); 1036cdf0e10cSrcweir 1037cdf0e10cSrcweir public: 1038cdf0e10cSrcweir ScaAnyConverter( 1039cdf0e10cSrcweir const CSS::uno::Reference< CSS::lang::XMultiServiceFactory >& xServiceFact ); 1040cdf0e10cSrcweir ~ScaAnyConverter(); 1041cdf0e10cSrcweir 1042cdf0e10cSrcweir /// Initializing with current language settings 1043cdf0e10cSrcweir void init( 1044cdf0e10cSrcweir const CSS::uno::Reference< CSS::beans::XPropertySet >& xPropSet ) 1045cdf0e10cSrcweir throw( CSS::uno::RuntimeException ); 1046cdf0e10cSrcweir 1047cdf0e10cSrcweir /** Converts an Any to double (without initialization). 1048cdf0e10cSrcweir The Any can be empty or contain a double or string. 1049cdf0e10cSrcweir @throws com::sun::star::lang::IllegalArgumentException 1050cdf0e10cSrcweir on other Any types or on invalid strings. 1051cdf0e10cSrcweir @return sal_True if the Any contains a double or a non-empty valid string, 1052cdf0e10cSrcweir sal_False if the Any is empty or the string is empty */ 1053cdf0e10cSrcweir sal_Bool getDouble( 1054cdf0e10cSrcweir double& rfResult, 1055cdf0e10cSrcweir const CSS::uno::Any& rAny ) const 1056cdf0e10cSrcweir throw( CSS::lang::IllegalArgumentException ); 1057cdf0e10cSrcweir 1058cdf0e10cSrcweir /** Converts an Any to double (with initialization). 1059cdf0e10cSrcweir The Any can be empty or contain a double or string. 1060cdf0e10cSrcweir @throws com::sun::star::lang::IllegalArgumentException 1061cdf0e10cSrcweir on other Any types or on invalid strings. 1062cdf0e10cSrcweir @return sal_True if the Any contains a double or a non-empty valid string, 1063cdf0e10cSrcweir sal_False if the Any is empty or the string is empty */ 1064cdf0e10cSrcweir sal_Bool getDouble( 1065cdf0e10cSrcweir double& rfResult, 1066cdf0e10cSrcweir const CSS::uno::Reference< CSS::beans::XPropertySet >& xPropSet, 1067cdf0e10cSrcweir const CSS::uno::Any& rAny ) 1068cdf0e10cSrcweir throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 1069cdf0e10cSrcweir 1070cdf0e10cSrcweir /** Converts an Any to double (with initialization). 1071cdf0e10cSrcweir The Any can be empty or contain a double or string. 1072cdf0e10cSrcweir @throws com::sun::star::lang::IllegalArgumentException 1073cdf0e10cSrcweir on other Any types or on invalid strings. 1074cdf0e10cSrcweir @return the value of the double or string or fDefault if the Any or string is empty */ 1075cdf0e10cSrcweir double getDouble( 1076cdf0e10cSrcweir const CSS::uno::Reference< CSS::beans::XPropertySet >& xPropSet, 1077cdf0e10cSrcweir const CSS::uno::Any& rAny, 1078cdf0e10cSrcweir double fDefault ) 1079cdf0e10cSrcweir throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 1080cdf0e10cSrcweir 1081cdf0e10cSrcweir /** Converts an Any to sal_Int32 (with initialization). 1082cdf0e10cSrcweir The Any can be empty or contain a double or string. 1083cdf0e10cSrcweir @throws com::sun::star::lang::IllegalArgumentException 1084cdf0e10cSrcweir on other Any types or on invalid values or strings. 1085cdf0e10cSrcweir @return sal_True if the Any contains a double or a non-empty valid string, 1086cdf0e10cSrcweir sal_False if the Any is empty or the string is empty */ 1087cdf0e10cSrcweir sal_Bool getInt32( 1088cdf0e10cSrcweir sal_Int32& rnResult, 1089cdf0e10cSrcweir const CSS::uno::Reference< CSS::beans::XPropertySet >& xPropSet, 1090cdf0e10cSrcweir const CSS::uno::Any& rAny ) 1091cdf0e10cSrcweir throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 1092cdf0e10cSrcweir 1093cdf0e10cSrcweir /** Converts an Any to sal_Int32 (with initialization). 1094cdf0e10cSrcweir The Any can be empty or contain a double or string. 1095cdf0e10cSrcweir @throws com::sun::star::lang::IllegalArgumentException 1096cdf0e10cSrcweir on other Any types or on invalid values or strings. 1097cdf0e10cSrcweir @return the truncated value of the double or string or nDefault if the Any or string is empty */ 1098cdf0e10cSrcweir sal_Int32 getInt32( 1099cdf0e10cSrcweir const CSS::uno::Reference< CSS::beans::XPropertySet >& xPropSet, 1100cdf0e10cSrcweir const CSS::uno::Any& rAny, 1101cdf0e10cSrcweir sal_Int32 nDefault ) 1102cdf0e10cSrcweir throw( CSS::uno::RuntimeException, CSS::lang::IllegalArgumentException ); 1103cdf0e10cSrcweir }; 1104cdf0e10cSrcweir 1105cdf0e10cSrcweir 1106cdf0e10cSrcweir //----------------------------------------------------------------------------- 1107cdf0e10cSrcweir 1108cdf0e10cSrcweir 1109cdf0e10cSrcweir #endif 1110cdf0e10cSrcweir 1111