From f983267746774f37040303f68760453eadf07ca6 Mon Sep 17 00:00:00 2001 From: gt Date: Fri, 6 Apr 2001 12:59:16 +0000 Subject: [PATCH] in the middle of the work, don't expect that this work --- scaddins/source/analysis/analysis.cxx | 1417 +++++++++++++++ scaddins/source/analysis/analysis.hxx | 206 +++ scaddins/source/analysis/analysisadd.idl | 379 ++++ scaddins/source/analysis/analysisdefs.hxx | 78 + scaddins/source/analysis/analysishelper.cxx | 1800 +++++++++++++++++++ scaddins/source/analysis/analysishelper.hxx | 697 +++++++ scaddins/source/analysis/makefile.mk | 144 ++ 7 files changed, 4721 insertions(+) create mode 100644 scaddins/source/analysis/analysis.cxx create mode 100644 scaddins/source/analysis/analysis.hxx create mode 100644 scaddins/source/analysis/analysisadd.idl create mode 100644 scaddins/source/analysis/analysisdefs.hxx create mode 100644 scaddins/source/analysis/analysishelper.cxx create mode 100644 scaddins/source/analysis/analysishelper.hxx create mode 100644 scaddins/source/analysis/makefile.mk diff --git a/scaddins/source/analysis/analysis.cxx b/scaddins/source/analysis/analysis.cxx new file mode 100644 index 000000000000..c828e63a235a --- /dev/null +++ b/scaddins/source/analysis/analysis.cxx @@ -0,0 +1,1417 @@ +/************************************************************************* + * + * $RCSfile: analysis.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: gt $ $Date: 2001-04-06 13:59:16 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "analysis.hxx" +#include "analysishelper.hxx" + +#include +#include +#include +#include + + +#define ADDIN_SERVICE "com.sun.star.sheet.AddIn" +#define MY_SERVICE "com.sun.star.sheet.addin.Analysis" +#define MY_IMPLNAME "com.sun.star.sheet.addin.AnalysisImpl" + + +//------------------------------------------------------------------ +// +// entry points for service registration / instantiation +// +//------------------------------------------------------------------ + +extern "C" { + + +void SAL_CALL component_getImplementationEnvironment( const sal_Char** ppEnvTypeName, uno_Environment** ppEnv ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + + +sal_Bool SAL_CALL component_writeInfo( void* pServiceManager, registry::XRegistryKey* pRegistryKey ) +{ + if( pRegistryKey ) + { + try + { + STRING aImpl = STRFROMASCII( "/" ); + aImpl += AnalysisAddIn::getImplementationName_Static(); + aImpl += STRFROMASCII( "/UNO/SERVICES" ); + + REF( registry::XRegistryKey ) xNewKey( + reinterpret_cast< registry::XRegistryKey* >( pRegistryKey )->createKey( aImpl ) ); + + SEQ( STRING ) aSequ = AnalysisAddIn::getSupportedServiceNames_Static(); + const STRING* pArray = aSequ.getConstArray(); + + for( sal_Int32 i = 0 ; i < aSequ.getLength() ; i++ ) + xNewKey->createKey( pArray[ i ] ); + + return sal_True; + } + catch( registry::InvalidRegistryException& ) + { + OSL_ENSHURE( sal_False, "### InvalidRegistryException!" ); + } + } + return sal_False; +} + + +void* SAL_CALL component_getFactory( const sal_Char* pImplName, void* pServiceManager, void* pRegistryKey ) +{ + void* pRet = 0; + + if( pServiceManager && STRING::createFromAscii( pImplName ) == AnalysisAddIn::getImplementationName_Static() ) + { + REF( lang::XSingleServiceFactory ) xFactory( cppu::createOneInstanceFactory( + reinterpret_cast< lang::XMultiServiceFactory* >( pServiceManager ), + AnalysisAddIn::getImplementationName_Static(), + AnalysisAddIn_CreateInstance, + AnalysisAddIn::getSupportedServiceNames_Static() ) ); + + if( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +} + + +} // extern C + + + + +//------------------------------------------------------------------------ +// +// "normal" service implementation +// +//------------------------------------------------------------------------ + +const sal_Char* pFuncDatas[] = +{ + "iget_Test", "1_test", "2_test", + "d4 testing only", + "pMode", "pparameter 1", "pparameter 2", "pparameter 3", + "PMode", "Pparameter 1", "Pparameter 2", "Pparameter 3", + EOE, + "igetWorkday", "1Arbeitstag", "2Workday", + "dReturns the serial number of the date before or after a specified number of workdays", + "pstart date", "pdays", "pholidays", + "PThe start date for calculating the work day", "PThe number of working days for calculating the work day", "PList of days work off", + EOE, + "igetYearfrac", "1Brteiljahre", "2Yearfrac", + "dReturns the year fraction representing the number of whole days between start_date and end_date", + "pstart date", "pend date", "pbasis", + "PThe start date for calculating the fraction of year", "PThe end date for calculating the fraction of year", "PBase for counting days: 0=USA (NASD) 30/360, 1=exact/exact, 2=exact/360, 3=exact/365, 4=Europe 30/360", + EOE, + "igetEdate", "1Edatum", "2Edate", + "dReturns the serial number of the date that is the indicated number of months before or after the start date", + "pstart date", "pmonths", + "PThe start date for calculating the edate", "PThe number of months to be added or subtracted", + EOE, + "igetWeeknum", "1_Kalenderwoche", "2_Weeknum", + "dReturns the week number in year", + "pdate", "preturn type", + "PDate as calculation base for weeknum", "PType of the return value: 1=week starts on sunday, 2=week starts on monday", + EOE, + "igetEomonth", "1Monatsende", "2EoMonth", + "dReturns the serial number of the last day of the month before or after a specified number of months", + "pstart date", "pmonths", + "PThe start date for calculating the end of month", "PThe number of months before or after", + EOE, + "igetNetworkdays", "1Nettoarbeitstage", "2Networkdays", + "dReturns the number of whole workdays between to dates", + "pstart date", "pend date", "pholidays", + "Pstart date", "Pend date", "Pholidays", + EOE, + "igetIseven", "1_Istgerade", "2_Iseven", + "dReturns true if the number is even", + "pnumber", + "Pnumber", + EOE, + "igetIsodd", "1_Istungerade", "2_Isodd", + "dReturns true if the number is odd", + "pnumber", + "Pnumber", + EOE, + "igetMultinomial", "1Polynomial", "2Multinomial", + "dReturns the multinomial of a set of numbers", + "pnumbers", + "Pnumbers", + EOE, + "igetSeriessum", "1Potenzreihe", "2Seriessum", + "dReturns the sum of a power series based on the formula", + "pX", "pN", "pM", "pCoefficients", + "PX is the value of the independent variable of the serie", "PN is the starting power of X", "PM is the increment from N from one element to the next", "PIs a group of coefficients", + EOE, + "igetQuotient", "1Quotient", "2Quotient", + "dReturns the integer portion of a division", + "pnumerator", "pdenominator", + "Pnumerator", "Pdenominator", + EOE, + "igetMround", "1Vrunden", "2Mround", + "dReturns a number rounded to the desire multiple", + "pnumber", "pmultiple", + "Pnumber", "Pmultiple", + EOE, + "igetSqrtpi", "1Wurzelpi", "2SqrtPI", + "dReturns the square root of ( number * pi )", + "pnumber", + "Pnumber", + EOE, + "igetRandbetween", "1Zufallsbereich", "2Randbetween", + "dReturns a random integer number between the numbers you specify", + "pbottom", "ptop", + "Pbottom", "Ptop", + EOE, + "igetGcd", "1_Ggt", "2_Gcd", + "dReturns the greatest common divisor", + "pnumber", + "Pnumber", + EOE, + "igetLcm", "1_Kgv", "2_Lcm", + "dReturns the least common multiple", + "pnumber", + "Pnumber", + EOE, + "igetBesseli", "1Besseli", "2BesselI", + "dReturns the modified Bessel function In(x)", + "px", "pn", + "Px", "Porder", + EOE, + "igetBesselj", "1Besselj", "2BesselJ", + "dReturns the Bessel function Jn(x)", + "px", "pn", + "Px", "Porder", + EOE, + "igetBesselk", "1Besselk", "2BesselK", + "dReturns the Bessel function Kn(x)", + "px", "pn", + "Px", "Porder", + EOE, + "igetBessely", "1Bessely", "2BesselY", + "dReturns the Bessel function Yn(x)", + "px", "pn", + "Px", "Porder", + EOE, + "igetBin2oct", "1Bininokt", "2Bin2Oct", // bin2 + "dConverts a binary number to octal", + "pnumber", "pplaces", + "Pnumber", "Pplaces", + EOE, + "igetBin2dec", "1Binindez", "2Bin2Dec", + "dConverts a binary number to decimal", + "pnumber", + "Pnumber", + EOE, + "igetBin2hex", "1Bininhex", "2Bin2Hex", + "dConverts a binary number to hexadecimal", + "pnumber", "pplaces", + "Pnumber", "Pplaces", + EOE, + "igetOct2bin", "1Oktinbin", "2Oct2Bin", // oct2 + "dConverts a octal number to binary", + "pnumber", "pplaces", + "Pnumber", "Pplaces", + EOE, + "igetOct2dec", "1Oktindez", "2Oct2Dec", + "dConverts a octal number to decimal", + "pnumber", + "Pnumber", + EOE, + "igetOct2hex", "1Oktinhex", "2Oct2Hex", + "dConverts a octal number to hexadecimal", + "pnumber", "pplaces", + "Pnumber", "Pplaces", + EOE, + "igetDec2bin", "1Dezinbin", "2Dec2Bin", // dec2 + "dConverts a decimal number to binary", + "pnumber", "pplaces", + "Pnumber", "Pplaces", + EOE, + "igetDec2oct", "1Dezinokt", "2Dec2Oct", + "dConverts a decimal number to octal", + "pnumber", "pplaces", + "Pnumber", "Pplaces", + EOE, + "igetDec2hex", "1Dezinhex", "2Dec2Hex", + "dConverts a decimal number to hexadecimal", + "pnumber", "pplaces", + "Pnumber", "Pplaces", + EOE, + "igetHex2bin", "1Hexinbin", "2Hex2Bin", // hex2 + "dConverts a hexadecimal number to binary", + "pnumber", "pplaces", + "Pnumber", "Pplaces", + EOE, + "igetHex2dec", "1Hexindez", "2Hex2Dec", + "dConverts a hexadecimal number to decimal", + "pnumber", + "Pnumber", + EOE, + "igetHex2oct", "1Hexinokt", "2Hex2Oct", + "dConverts a hexadecimal number to octal", + "pnumber", "pplaces", + "Pnumber", "Pplaces", + EOE, + "igetDelta", "1Delta", "2Delta", + "dTests wether two numbers are equal", + "pnumber 1", "pnumber 2", + "Pnumber 1", "Pnumber 2", + EOE, + "igetErf", "1Gaussfehler", "2Erf", + "dReturns the error function", + "plower limit", "pupper limit", + "Plower limit", "Pupper limit", + EOE, + "igetErfc", "1Gaussfkompl", "2Erfc", + "dReturns the complementary error function", + "plower limit", + "Plower limit", + EOE, + "igetGestep", "1Gganzzahl", "2GeStep", + "dTests wether a number is greater than a threshold value", + "pnumber", "pstep", + "Pnumber", "Pstep", + EOE, + "igetFactdouble", "1Zweifakultaet", "2Factdouble", + "dReturns the double factorial of a number", + "pnumber", + "Pnumber", + EOE, + "igetImabs", "1Imabs", "2Imabs", + "dReturns the absolute value (modulus) of a complex number", + "pinumber", + "Pinumber", + EOE, + "igetImaginary", "1Imaginaerteil", "2Imaginary", + "dReturns the imaginary coefficient of a complex number", + "pinumber", + "Pinumber", + EOE, + "igetImpower", "1Imapotenz", "2Impower", + "dReturns a complex number raised by a real number", + "pinumber", "pnumber", + "Pinumber", "Pnumber", + EOE, + "igetImargument", "1Imargument", "2Imargument", + "dReturns the argument q, an angle expressed in radians", + "pinumber", + "Pinumber", + EOE, + "igetImcos", "1Imcos", "2Imcos", + "dReturns the cosine of a complex number", + "pinumber", + "Pinumber", + EOE, + "igetImdiv", "1Imdiv", "2Imdiv", + "dReturns the quotient of two complex numbers", + "pinumber 1", "pinumber 2", + "Pinumber 1", "Pinumber 2", + EOE, + "igetImexp", "1Imexp", "2Imexp", + "dReturns the exponential of a complex number", + "pinumber", + "Pinumber", + EOE, + "igetImconjugate", "1Imkonjugierte", "2Imconjugate", + "dReturns the comlex conjugate of a complex number", + "pinumber", + "Pinumber", + EOE, + "igetImln", "1Imln", "2Imln", + "dReturns the natural logarithm of a complex number", + "pinumber", + "Pinumber", + EOE, + "igetImlog10", "1Imlog10", "2Imlog10", + "dReturns the base-10 logarithm of a complex number", + "pinumber", + "Pinumber", + EOE, + "igetImlog2", "1Imlog2", "2Imlog2", + "dReturns the base-2 logarithm of a complex number", + "pinumber", + "Pinumber", + EOE, + "igetImproduct", "1Improdukt", "2Improduct", + "dReturns the product of complex numbers", + "pinumber1", "pinumber2", + "Pinumber1", "Pinumber2", + EOE, + "igetImreal", "1Imrealteil", "2Imreal", + "dReturns the real coefficient of a complex number", + "pinumber", + "Pinumber", + EOE, + "igetImsin", "1Imsin", "2Imsin", + "dReturns the sine of a complex number", + "pinumber", + "Pinumber", + EOE, + "igetImsub", "1Imsub", "2Imsub", + "dReturns the difference of two complex numbers", + "pinumber1", "pinumber2", + "Pinumber1", "Pinumber2", + EOE, + "igetImsum", "1Imsumme", "2Imsum", + "dReturns the sum of complex numbers", + "pinumber1", "pinumber2", + "Pinumber1", "Pinumber2", + EOE, + "igetComplex", "1Komplexe", "2Complex", + "dConverts real and imaginary coefficients into a complex number", + "preal_num", "pi_num", "psuffix", + "Preal_num", "Pi_num", "Psuffix", + EOE, + "igetConvert", "1_Umwandeln", "2_Convert", + "dConverts a number from one measurement system to another", + "pnumber", "pfrom_unit", "pto_unit", + "Pnumber", "Pfrom_unit", "Pto_unit", + EOE, + EOL +}; + + +AnalysisAddIn::AnalysisAddIn() +{ + pFD = new FuncDataList( pFuncDatas ); + pFactDoubles = NULL; + pCDL = NULL; +} + + +AnalysisAddIn::~AnalysisAddIn() +{ + delete pFD; + + if( pFactDoubles ) + delete pFactDoubles; + + if( pCDL ) + delete pCDL; +} + + +#define MAXFACTDOUBLE 300 + +double AnalysisAddIn::FactDouble( sal_Int32 nNum ) THROWDEF_RTE_IAE +{ + if( nNum < 0 || nNum > MAXFACTDOUBLE ) + THROW_IAE; + + if( !pFactDoubles ) + { + pFactDoubles = new double[ MAXFACTDOUBLE + 1 ]; + + pFactDoubles[ 0 ] = 1.0; // by default + + double fOdd = 1.0; + double fEven = 2.0; + + pFactDoubles[ 1 ] = fOdd; + pFactDoubles[ 2 ] = fEven; + + sal_Bool bOdd = sal_True; + + for( sal_uInt16 nCnt = 3 ; nCnt <= MAXFACTDOUBLE ; nCnt++ ) + { + if( bOdd ) + { + fOdd *= nCnt; + pFactDoubles[ nCnt ] = fOdd; + } + else + { + fEven *= nCnt; + pFactDoubles[ nCnt ] = fEven; + } + + bOdd = !bOdd; + + } + } + + return pFactDoubles[ nNum ]; +} + + +STRING AnalysisAddIn::getImplementationName_Static() +{ + return STRFROMASCII( MY_IMPLNAME ); +} + + +SEQ( STRING ) AnalysisAddIn::getSupportedServiceNames_Static() +{ + SEQ( STRING ) aRet(2); + STRING* pArray = aRet.getArray(); + pArray[0] = STRFROMASCII( ADDIN_SERVICE ); + pArray[1] = STRFROMASCII( MY_SERVICE ); + return aRet; +} + + +REF( uno::XInterface ) SAL_CALL AnalysisAddIn_CreateInstance( const REF( lang::XMultiServiceFactory )& ) +{ + static REF( uno::XInterface ) xInst = ( cppu::OWeakObject* ) new AnalysisAddIn(); + return xInst; +} + + +// XServiceName + +STRING SAL_CALL AnalysisAddIn::getServiceName() THROWDEF_RTE +{ + // name of specific AddIn service + return STRFROMASCII( MY_SERVICE ); +} + + +// XServiceInfo + +STRING SAL_CALL AnalysisAddIn::getImplementationName() THROWDEF_RTE +{ + return getImplementationName_Static(); +} + + +sal_Bool SAL_CALL AnalysisAddIn::supportsService( const STRING& aName ) THROWDEF_RTE +{ + return aName.compareToAscii( ADDIN_SERVICE ) == 0 || aName.compareToAscii( MY_SERVICE ) == 0; +} + + +SEQ( STRING ) SAL_CALL AnalysisAddIn::getSupportedServiceNames() THROWDEF_RTE +{ + return getSupportedServiceNames_Static(); +} + + +// XLocalizable + +void SAL_CALL AnalysisAddIn::setLocale( const lang::Locale& eLocale ) THROWDEF_RTE +{ + aFuncLoc = eLocale; +} + +lang::Locale SAL_CALL AnalysisAddIn::getLocale() THROWDEF_RTE +{ + return aFuncLoc; +} + + +// XAddIn + +STRING SAL_CALL AnalysisAddIn::getProgrammaticFuntionName( const STRING& aDisplayName ) THROWDEF_RTE +{ + // not used by calc + // (but should be implemented for other uses of the AddIn service) + + return STRING(); +} + + +STRING SAL_CALL AnalysisAddIn::getDisplayFunctionName( const STRING& aProgrammaticName ) THROWDEF_RTE +{ + //! allow different languages + sal_Bool bGerman = ( aFuncLoc.Language.equalsIgnoreCase( STRFROMASCII( "DE" ) ) ); + + STRING aRet; + + const FuncData* p = pFD->Get( aProgrammaticName ); + if( p ) + aRet = STRFROMASCII( bGerman ? p->pGerman : p->pEnglish ); + + return aRet; +} + + +STRING SAL_CALL AnalysisAddIn::getFunctionDescription( const STRING& aProgrammaticName ) THROWDEF_RTE +{ + //! return translated strings + + STRING aRet; + + const FuncData* p = pFD->Get( aProgrammaticName ); + if( p ) + aRet = STRFROMASCII( p->pDescr ); + + return aRet; +} + + +STRING SAL_CALL AnalysisAddIn::getDisplayArgumentName( const STRING& aName, sal_Int32 nArg ) THROWDEF_RTE +{ + //! return translated strings + STRING aRet; + + const FuncData* p = pFD->Get( aName ); + if( p ) + aRet = STRFROMASCII( p->GetParam( nArg ) ); + + return aRet; +} + + +STRING SAL_CALL AnalysisAddIn::getArgumentDescription( const STRING& aName, sal_Int32 nArg ) THROWDEF_RTE +{ + //! return translated strings + STRING aRet; + const FuncData* p = pFD->Get( aName ); + if( p ) + aRet = STRFROMASCII( p->GetParamDescr( nArg ) ); + + return aRet; +} + + +STRING SAL_CALL AnalysisAddIn::getProgrammaticCategoryName( const STRING& aName ) THROWDEF_RTE +{ + // return non-translated strings + return STRFROMASCII( "Add-In" ); +} + + +STRING SAL_CALL AnalysisAddIn::getDisplayCategoryName( const STRING& aProgrammaticFunctionName ) THROWDEF_RTE +{ + // return translated strings, not used for predefined categories + return STRFROMASCII( "Add-In" ); +} + + +// XAnalysis + +double SAL_CALL AnalysisAddIn::get_Test( constREFXPS&, + sal_Int32 nMode, double f1, double f2, double f3 ) THROWDEF_RTE +{ + return _Test( nMode, f1, f2, f3 ); +} + + +/** + * Workday + */ + +sal_Int32 SAL_CALL AnalysisAddIn::getWorkday( constREFXPS& xOptions, + sal_Int32 nDate, sal_Int32 nDays, const SEQSEQ( sal_Int32 )& aHDay ) THROWDEF_RTE +{ + if( !nDays ) + return nDate; + + sal_Int32 nNullDate = GetNullDate( xOptions ); + + SortedIndividualInt32List aSrtLst; + + aSrtLst.InsertHolidayList( aHDay, nNullDate, sal_False ); + + sal_Int32 nActDate = nDate + nNullDate; + + if( nDays > 0 ) + { + while( nDays ) + { + nActDate++; + + if( GetDayOfWeek( nActDate ) < 5 ) + { + if( !aSrtLst.Find( nActDate ) ) + nDays--; + } + else + nActDate++; // jump over weekend + } + } + else + { + while( nDays ) + { + nActDate--; + + if( GetDayOfWeek( nActDate ) < 5 ) + { + if( !aSrtLst.Find( nActDate ) ) + nDays--; + } + else + nActDate--; // jump over weekend + } + } + + return nActDate - nNullDate; +} + + +/** + * Yearfrac + */ + +double SAL_CALL AnalysisAddIn::getYearfrac( constREFXPS& xOpt, + sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode ) THROWDEF_RTE +{ + if( nStartDate == nEndDate ) + return 0.0; // nothing to do... + else if( nStartDate > nEndDate ) + { + sal_Int32 n = nEndDate; + nEndDate = nStartDate; + nStartDate = n; + } + + sal_Int32 nNullDate = GetNullDate( xOpt ); + + sal_Int32 nDate1 = nStartDate + nNullDate; + sal_Int32 nDate2 = nEndDate + nNullDate; + + sal_uInt16 nDay1, nDay2; + sal_uInt16 nMonth1, nMonth2; + sal_uInt16 nYear1, nYear2; + + DaysToDate( nDate1, nDay1, nMonth1, nYear1 ); + DaysToDate( nDate2, nDay2, nMonth2, nYear2 ); + + sal_uInt16 nYears = nYear2 - nYear1; + sal_Int32 nDayDiff, nDaysInYear; + + switch( nMode ) + { + case 0: // 0=USA (NASD) 30/360 + case 4: // 4=Europe 30/360 + nDaysInYear = 360; + nDayDiff = GetDiffDate360( nDay1, nMonth1, nYear1, IsLeapYear( nYear1 ), + nDay2, nMonth2, nYear2, nMode == 0 ) - nYears * nDaysInYear; + break; + case 1: // 1=exact/exact + nDaysInYear = IsLeapYear( nYear1 )? 366 : 365; + if( nYears ) + nDayDiff = nDate2 - DateToDays( nDay1, nMonth1, nYear2 ); + else + nDayDiff = nDate2 - nDate1; + + break; + case 2: // 2=exact/360 + nDaysInYear = 360; + nDayDiff = nDate2 - nDate1; + nDayDiff %= nDaysInYear; + break; + case 3: //3=exact/365 + nDaysInYear = 365; + nDayDiff = nDate2 - nDate1; + nDayDiff %= nDaysInYear; + break; + default: + nDaysInYear = -1; + nDayDiff = 1; + nYears = 0; + } + + return double( nYears ) + double( nDayDiff ) / double( nDaysInYear ); +} + + +sal_Int32 SAL_CALL AnalysisAddIn::getEdate( constREFXPS& xOpt, sal_Int32 nStartDate, sal_Int32 nMonths ) THROWDEF_RTE +{ + sal_Int32 nNullDate = GetNullDate( xOpt ); + sal_Int32 nDate = nStartDate + nNullDate; + sal_uInt16 nDay, nMonth, nYear; + DaysToDate( nDate, nDay, nMonth, nYear ); + + nYear += nMonths / 12; + nMonth += nMonths % 12; + + sal_uInt16 nDaysInMonth = DaysInMonth( nMonth, nYear ); + if( nDay > nDaysInMonth ) + nDay = nDaysInMonth; + + return DateToDays( nDay, nMonth, nYear ) - nNullDate; +} + + +sal_Int32 SAL_CALL AnalysisAddIn::getWeeknum( constREFXPS& xOpt, sal_Int32 nDate, sal_Int32 nMode ) THROWDEF_RTE +{ + nDate += GetNullDate( xOpt ); + + sal_uInt16 nDay, nMonth, nYear; + DaysToDate( nDate, nDay, nMonth, nYear ); + + sal_Int32 nFirstInYear = DateToDays( 1, 1, nYear ); + sal_uInt16 nFirstDayInYear = GetDayOfWeek( nFirstInYear ); + + return ( nDate - nFirstInYear + ( ( nMode == 1 )? ( nFirstDayInYear + 1 ) % 7 : nFirstDayInYear ) ) / 7 + 1; +} + + +sal_Int32 SAL_CALL AnalysisAddIn::getEomonth( constREFXPS& xOpt, sal_Int32 nDate, sal_Int32 nMonths ) THROWDEF_RTE +{ + sal_Int32 nNullDate = GetNullDate( xOpt ); + nDate += nNullDate; + sal_uInt16 nDay, nMonth, nYear; + DaysToDate( nDate, nDay, nMonth, nYear ); + + nYear += nMonths / 12; + + sal_uInt16 nNewMonth; + + if( nMonths > 0 && nMonth == 12 ) + { + nYear++; + nNewMonth = 1; + } + else if( nMonths < 0 && nMonth == 1 ) + { + nYear--; + nNewMonth = 12; + } + else + nNewMonth = nMonth + nMonths % 12; + + return DateToDays( DaysInMonth( nNewMonth, nYear ), nNewMonth, nYear ) - nNullDate; +} + + +sal_Int32 SAL_CALL AnalysisAddIn::getNetworkdays( constREFXPS& xOpt, + sal_Int32 nStartDate, sal_Int32 nEndDate, const SEQSEQ( sal_Int32 )& aHDay ) THROWDEF_RTE +{ + sal_Int32 nNullDate = GetNullDate( xOpt ); + + SortedIndividualInt32List aSrtLst; + + aSrtLst.InsertHolidayList( aHDay, nNullDate, sal_False ); + + sal_Int32 nActDate = nStartDate + nNullDate; + sal_Int32 nStopDate = nEndDate + nNullDate; + sal_Int32 nCnt = 0; + + if( nActDate <= nStopDate ) + { + while( nActDate <= nStopDate ) + { + if( GetDayOfWeek( nActDate ) < 5 && !aSrtLst.Find( nActDate ) ) + nCnt++; + + nActDate++; + } + } + else + { + while( nActDate >= nStopDate ) + { + if( GetDayOfWeek( nActDate ) < 5 && !aSrtLst.Find( nActDate ) ) + nCnt--; + + nActDate--; + } + } + + return nCnt; +} + + +sal_Int32 SAL_CALL AnalysisAddIn::getIseven( constREFXPS&, sal_Int32 nVal ) THROWDEF_RTE +{ + return ( nVal & 0x00000001 )? 0 : 1; +} + + +sal_Int32 SAL_CALL AnalysisAddIn::getIsodd( constREFXPS&, sal_Int32 nVal ) THROWDEF_RTE +{ + return ( nVal & 0x00000001 )? 1 : 0; +} + + +double SAL_CALL AnalysisAddIn::getMultinomial( constREFXPS&, const SEQSEQ( sal_Int32 )& aV ) THROWDEF_RTE +{ + sal_Int32 n1, n2; + sal_Int32 nE1 = aV.getLength(); + sal_Int32 nE2; + sal_Int32 nZ = 0; + double fN = 1.0; + + for( n1 = 0 ; n1 < nE1 ; n1++ ) + { + const SEQ( sal_Int32 )& rList = aV[ n1 ]; + nE2 = rList.getLength(); + const sal_Int32* pList = rList.getConstArray(); + + for( n2 = 0 ; n2 < nE2 ; n2++ ) + { + sal_Int32 n = pList[ n2 ]; + + if( n < 0 || n > 170 ) + return -1.0; + else if( n > 0 ) + { + nZ += n; + fN *= Fak( n ); + } + } + } + + if( nZ <= 170 ) + return Fak( nZ ) / fN; + else + return -1.0; +} + + +double SAL_CALL AnalysisAddIn::getSeriessum( constREFXPS&, + double fX, double fN, double fM, const SEQSEQ( double )& aCoeffList ) THROWDEF_RTE +{ + double fRet = 0.0; + + if( fX != 0.0 ) + { + sal_Int32 n1, n2; + sal_Int32 nE1 = aCoeffList.getLength(); + sal_Int32 nE2; + sal_Int32 nZ = 0; + + for( n1 = 0 ; n1 < nE1 ; n1++ ) + { + const SEQ( double )& rList = aCoeffList[ n1 ]; + nE2 = rList.getLength(); + const double* pList = rList.getConstArray(); + + for( n2 = 0 ; n2 < nE2 ; n2++ ) + { + fRet += pList[ n2 ] * pow( fX, fN ); + + fN += fM; + } + } + } + + return fRet; +} + + +double SAL_CALL AnalysisAddIn::getQuotient( constREFXPS&, double fNum, double fDenum ) THROWDEF_RTE +{ + return SolarMath::ApproxFloor( fNum / fDenum ); +} + + +double SAL_CALL AnalysisAddIn::getMround( constREFXPS&, double fNum, double fMult ) THROWDEF_RTE +{ + if( fMult == 0.0 ) + return fMult; + + return fMult * SolarMath::Round( fNum / fMult ); +} + + +double SAL_CALL AnalysisAddIn::getSqrtpi( constREFXPS&, double fNum ) THROWDEF_RTE +{ + return sqrt( fNum * PI ); +} + + +double SAL_CALL AnalysisAddIn::getRandbetween( constREFXPS&, double fMin, double fMax ) THROWDEF_RTE +{ + const SolarMathRoundingMode eRM = SolarMathRoundUp; + fMin = SolarMath::Round( fMin, 0, eRM ); + fMax = SolarMath::Round( fMax, 0, eRM ); + + if( fMin > fMax ) + return -1.0; + + // fMax -> range + fMax -= fMin; + fMax /= double( RAND_MAX ); + + return SolarMath::Round( fMin + fMax * double( rand() ) ); +} + + +double SAL_CALL AnalysisAddIn::getGcd( constREFXPS&, const SEQSEQ( double )& aVLst ) THROWDEF_RTE +{ + ChkDoubleList1 aValList; + + if( !aValList.Append( aVLst ) ) + return -1.0; + + if( aValList.Count() == 0 ) + return 0.0; + + const double* p = aValList.First(); + double f = *p; + + p = aValList.Next(); + + while( p ) + { + f = GetGcd( *p, f ); + p = aValList.Next(); + } + + return f; +} + + +double SAL_CALL AnalysisAddIn::getLcm( constREFXPS&, const SEQSEQ( double )& aVLst ) THROWDEF_RTE +{ + ChkDoubleList1 aValList; + + if( !aValList.Append( aVLst ) ) + return -1.0; + + if( aValList.Count() == 0 ) + return 0.0; + + const double* p = aValList.First(); + double f = *p; + + p = aValList.Next(); + + while( p ) + { + double fTmp = *p; + f = fTmp * f / GetGcd( fTmp, f ); + p = aValList.Next(); + } + + return f; +} + + +double SAL_CALL AnalysisAddIn::getBesseli( constREFXPS&, double fNum, sal_Int32 nOrder ) THROWDEF_RTE +{ + return Bessel( fNum, nOrder, sal_True ); +} + + +double SAL_CALL AnalysisAddIn::getBesselj( constREFXPS&, double fNum, sal_Int32 nOrder ) THROWDEF_RTE +{ + return Bessel( fNum, nOrder, sal_False ); +} + + +double SAL_CALL AnalysisAddIn::getBesselk( constREFXPS&, double fNum, sal_Int32 nOrder ) THROWDEF_RTE +{ + if( nOrder < 0 ) + return -1.0; + + double fOrd = nOrder; + + double f = PI_2; + double f0 = fOrd * PI; + f0 = sin( f0 ); + f /= f0; + double f1 = BesselR( fNum, -fOrd ); + double f2 = Bessel( fNum, nOrder, sal_True ); + f1 -= f2; + + f *= f1; + + return f; +// return PI_2 / sin( fOrd * PI ) * ( BesselR( fNum, -fOrd ) - Bessel( fNum, nOrder, sal_True ) ); + +} + + +double SAL_CALL AnalysisAddIn::getBessely( constREFXPS&, double fNum, sal_Int32 nOrder ) THROWDEF_RTE +{ +// if( nOrder < 0 ) + return -1.0; +} + + +#define _P 10 // max. number of places +#define _MIN2 -512 // min. val for binary numbers +#define _MAX2 511 // min. val for binary numbers +#define _MIN8 -536870912 // min. val for octal numbers +#define _MAX8 536870911 // max. val for octal numbers +#define _MIN16 -1099511627776 // min. val for hexadecimal numbers +#define _MAX16 1099511627775 // max. val for hexadecimal numbers +#define DOUBLECONV(from,to) ConvertFromDec(sal_Int64(ConvertToDec(aNum,from,_P)),_MIN##to,_MAX##to,to,nPlaces,_P) + + +STRING SAL_CALL AnalysisAddIn::getBin2oct( constREFXPS&, const STRING& aNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE +{ + return DOUBLECONV( 2, 8 ); +} + + +double SAL_CALL AnalysisAddIn::getBin2dec( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE +{ + return ConvertToDec( aNum, 2, _P ); +} + + +STRING SAL_CALL AnalysisAddIn::getBin2hex( constREFXPS&, const STRING& aNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE +{ + return DOUBLECONV( 2, 16 ); +} + + +STRING SAL_CALL AnalysisAddIn::getOct2bin( constREFXPS&, const STRING& aNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE +{ + return DOUBLECONV( 8, 2 ); +} + + +double SAL_CALL AnalysisAddIn::getOct2dec( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE +{ + return ConvertToDec( aNum, 8, _P ); +} + + +STRING SAL_CALL AnalysisAddIn::getOct2hex( constREFXPS&, const STRING& aNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE +{ + return DOUBLECONV( 8, 16 ); +} + + +STRING SAL_CALL AnalysisAddIn::getDec2bin( constREFXPS&, sal_Int32 nNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE +{ + return ConvertFromDec( nNum, _MIN2, _MAX2, 2, nPlaces, _P ); +} + + +STRING SAL_CALL AnalysisAddIn::getDec2oct( constREFXPS&, sal_Int32 nNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE +{ + return ConvertFromDec( nNum, _MIN8, _MAX8, 8, nPlaces, _P ); +} + + +STRING SAL_CALL AnalysisAddIn::getDec2hex( constREFXPS&, double fNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE +{ + return ConvertFromDec( sal_Int64( fNum ), _MIN16, _MAX16, 16, nPlaces, _P ); +} + + +STRING SAL_CALL AnalysisAddIn::getHex2bin( constREFXPS&, const STRING& aNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE +{ + return DOUBLECONV( 16, 2 ); +} + + +double SAL_CALL AnalysisAddIn::getHex2dec( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE +{ + return ConvertToDec( aNum, 16, _P ); +} + + +STRING SAL_CALL AnalysisAddIn::getHex2oct( constREFXPS&, const STRING& aNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE +{ + return DOUBLECONV( 16, 8 ); +} + + +sal_Int32 SAL_CALL AnalysisAddIn::getDelta( constREFXPS&, double fNum1, double fNum2 ) THROWDEF_RTE +{ +#ifdef DEBUG + return ( fNum1 == fNum2 )? 1 : 0; +#else + return fNum1 == fNum2; +#endif +} + + +double SAL_CALL AnalysisAddIn::getErf( constREFXPS&, double fLL, double fUL ) THROWDEF_RTE +{ + return Erf( fUL ) - Erf( fLL ); +} + + +double SAL_CALL AnalysisAddIn::getErfc( constREFXPS&, double f ) THROWDEF_RTE +{ + return 1.0 - Erf( f ); +} + + +sal_Int32 SAL_CALL AnalysisAddIn::getGestep( constREFXPS&, double fNum, double fStep ) THROWDEF_RTE +{ +#ifdef DEBUG + return ( fNum >= fStep )? 1 : 0; +#else + return fNum >= fStep; +#endif +} + + +double SAL_CALL AnalysisAddIn::getFactdouble( constREFXPS&, sal_Int32 nNum ) THROWDEF_RTE_IAE +{ +/* if( nNum < 0 ) + THROW_IAE; + else if( nNum == 0 ) + return 1.0; + + sal_Bool bEven = ( nNum & 0x00000001 ) == 0; + double f = bEven? 2.0 : 1.0; + double fMult = bEven? 4.0 : 3.0; + double fLast = nNum; + + while( fMult <= fLast ) + { + f *= fMult; + fMult += 2.0; + } + + return f;*/ + return FactDouble( nNum ); +} + + +double SAL_CALL AnalysisAddIn::getImabs( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE +{ + return Complex( aNum ).Abs(); +} + + +double SAL_CALL AnalysisAddIn::getImaginary( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE +{ + return Complex( aNum ).Imag(); +} + + +STRING SAL_CALL AnalysisAddIn::getImpower( constREFXPS&, const STRING& aNum, double f ) THROWDEF_RTE_IAE +{ + Complex z( aNum ); + + z.Power( f ); + + return z.GetString(); +} + + +double SAL_CALL AnalysisAddIn::getImargument( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE +{ + return Complex( aNum ).Arg(); +} + + +STRING SAL_CALL AnalysisAddIn::getImcos( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE +{ + Complex z( aNum ); + + z.Cos(); + + return z.GetString(); +} + + +STRING SAL_CALL AnalysisAddIn::getImdiv( constREFXPS&, const STRING& aDivid, const STRING& aDivis ) THROWDEF_RTE_IAE +{ + Complex z( aDivid ); + + z.Div( Complex( aDivis ) ); + + return z.GetString(); +} + + +STRING SAL_CALL AnalysisAddIn::getImexp( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE +{ + Complex z( aNum ); + + z.Exp(); + + return z.GetString(); +} + + +STRING SAL_CALL AnalysisAddIn::getImconjugate( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE +{ + Complex z( aNum ); + + z.Conjugate(); + + return z.GetString(); +} + + +STRING SAL_CALL AnalysisAddIn::getImln( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE +{ + Complex z( aNum ); + + z.Ln(); + + return z.GetString(); +} + + +STRING SAL_CALL AnalysisAddIn::getImlog10( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE +{ + Complex z( aNum ); + + z.Log10(); + + return z.GetString(); +} + + +STRING SAL_CALL AnalysisAddIn::getImlog2( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE +{ + Complex z( aNum ); + + z.Log2(); + + return z.GetString(); +} + + +STRING SAL_CALL AnalysisAddIn::getImproduct( constREFXPS&, const STRING& aNum1, const STRING& aNum2 ) THROWDEF_RTE_IAE +{ + Complex z( aNum1 ); + + z.Mult( Complex( aNum2 ) ); + + return z.GetString(); +} + + +double SAL_CALL AnalysisAddIn::getImreal( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE +{ + return Complex( aNum ).Real(); +} + + +STRING SAL_CALL AnalysisAddIn::getImsin( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE +{ + Complex z( aNum ); + + z.Sin(); + + return z.GetString(); +} + + +STRING SAL_CALL AnalysisAddIn::getImsub( constREFXPS&, const STRING& aNum1, const STRING& aNum2 ) THROWDEF_RTE_IAE +{ + Complex z( aNum1 ); + + z.Sub( Complex( aNum2 ) ); + + return z.GetString(); +} + + +STRING SAL_CALL AnalysisAddIn::getImsum( constREFXPS&, const STRING& aNum1, const STRING& aNum2 ) THROWDEF_RTE_IAE +{ +/* ComplexList z_list; + + z_list.Append( aNumList ); + + const Complex* p = z_list.First(); + + if( p ) + { + Complex z( *p ); + + p = z_list.Next(); + + while( p ) + { + z.Add( *p ); + p = z_list.Next(); + } + + return z.GetString(); + } + else + THROW_IAE;*/ + + Complex z( aNum1 ); + + z.Add( Complex( aNum2 ) ); + + return z.GetString(); +} + + +STRING SAL_CALL AnalysisAddIn::getImsqrt( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE +{ + Complex z( aNum ); + + z.Power( 0.5 ); + + return z.GetString(); +} + + +STRING SAL_CALL AnalysisAddIn::getComplex( constREFXPS&, double fR, double fI, const STRING& rSuff ) THROWDEF_RTE_IAE +{ + sal_Bool bi = rSuff.compareToAscii( "i" ) == 0; + + if( bi || !rSuff.compareToAscii( "j" ) ) + return Complex( fR,fI ).GetString( bi ); + else + THROW_IAE; +} + + +double SAL_CALL AnalysisAddIn::getConvert( constREFXPS&, double f, const STRING& aFU, const STRING& aTU ) THROWDEF_RTE_IAE +{ + if( !pCDL ) + pCDL = new ConvertDataList(); + + return pCDL->Convert( f, aFU, aTU ); +} + + diff --git a/scaddins/source/analysis/analysis.hxx b/scaddins/source/analysis/analysis.hxx new file mode 100644 index 000000000000..18fa57290310 --- /dev/null +++ b/scaddins/source/analysis/analysis.hxx @@ -0,0 +1,206 @@ +/************************************************************************* + * + * $RCSfile: analysis.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: gt $ $Date: 2001-04-06 13:59:16 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef ANALYSIS_HXX +#define ANALYSIS_HXX + + +#include +#include +#include +#include + +#include // helper for implementations + +#include "analysisdefs.hxx" + + +class FuncDataList; +class ConvertDataList; + + +REF( CSS::uno::XInterface ) SAL_CALL AnalysisAddIn_CreateInstance( const REF( CSS::lang::XMultiServiceFactory )& ); + + +class AnalysisAddIn : public cppu::WeakImplHelper4< + CSS::sheet::XAddIn, + CSS::sheet::addin::XAnalysis, + CSS::lang::XServiceName, + CSS::lang::XServiceInfo > +{ +private: + CSS::lang::Locale aFuncLoc; + FuncDataList* pFD; + double* pFactDoubles; + ConvertDataList* pCDL; +public: + AnalysisAddIn(); + virtual ~AnalysisAddIn(); + + double FactDouble( sal_Int32 nNum ) THROWDEF_RTE_IAE; + + static STRING getImplementationName_Static(); + static SEQ( STRING ) getSupportedServiceNames_Static(); + + // XAddIn + virtual STRING SAL_CALL getProgrammaticFuntionName( const STRING& aDisplayName ) THROWDEF_RTE; + virtual STRING SAL_CALL getDisplayFunctionName( const STRING& aProgrammaticName ) THROWDEF_RTE; + virtual STRING SAL_CALL getFunctionDescription( const STRING& aProgrammaticName ) THROWDEF_RTE; + virtual STRING SAL_CALL getDisplayArgumentName( const STRING& aProgrammaticFunctionName, sal_Int32 nArgument ) THROWDEF_RTE; + virtual STRING SAL_CALL getArgumentDescription( const STRING& aProgrammaticFunctionName, sal_Int32 nArgument ) THROWDEF_RTE; + virtual STRING SAL_CALL getProgrammaticCategoryName( const STRING& aProgrammaticFunctionName ) THROWDEF_RTE; + virtual STRING SAL_CALL getDisplayCategoryName( const STRING& aProgrammaticFunctionName ) THROWDEF_RTE; + + // XLocalizable + virtual void SAL_CALL setLocale( const CSS::lang::Locale& eLocale ) THROWDEF_RTE; + virtual CSS::lang::Locale SAL_CALL getLocale( ) THROWDEF_RTE; + + // XServiceName + virtual STRING SAL_CALL getServiceName( ) THROWDEF_RTE; + + // XServiceInfo + virtual STRING SAL_CALL getImplementationName( ) THROWDEF_RTE; + virtual sal_Bool SAL_CALL supportsService( const STRING& ServiceName ) THROWDEF_RTE; + virtual CSS::uno::Sequence< STRING > SAL_CALL getSupportedServiceNames( ) THROWDEF_RTE; + + // methods from own interfaces start here + + // XAnalysis + virtual double SAL_CALL get_Test( constREFXPS&, sal_Int32 nMode, double f1, double f2, double f3 ) THROWDEF_RTE; + + virtual sal_Int32 SAL_CALL getWorkday( constREFXPS&, sal_Int32 nStartDate, sal_Int32 nDays, const SEQSEQ( sal_Int32 )& aHDay ) THROWDEF_RTE; + virtual double SAL_CALL getYearfrac( constREFXPS&, sal_Int32 nStartDate, sal_Int32 nEndDate, sal_Int32 nMode ) THROWDEF_RTE; + virtual sal_Int32 SAL_CALL getEdate( constREFXPS&, sal_Int32 nStartDate, sal_Int32 nMonths ) THROWDEF_RTE; + virtual sal_Int32 SAL_CALL getWeeknum( constREFXPS&, sal_Int32 nStartDate, sal_Int32 nMode ) THROWDEF_RTE; + virtual sal_Int32 SAL_CALL getEomonth( constREFXPS&, sal_Int32 nStartDate, sal_Int32 nMonths ) THROWDEF_RTE; + virtual sal_Int32 SAL_CALL getNetworkdays( constREFXPS&, sal_Int32 nStartDate, sal_Int32 nEndDate, const SEQSEQ( sal_Int32 )& aHDay ) THROWDEF_RTE; + + virtual sal_Int32 SAL_CALL getIseven( constREFXPS&, sal_Int32 nVal ) THROWDEF_RTE; + virtual sal_Int32 SAL_CALL getIsodd( constREFXPS&, sal_Int32 nVal ) THROWDEF_RTE; + + virtual double SAL_CALL getMultinomial( constREFXPS&, const SEQSEQ( sal_Int32 )& aValueList ) THROWDEF_RTE; + virtual double SAL_CALL getSeriessum( constREFXPS&, double fX, double fN, double fM, const SEQSEQ( double )& aCoeffList ) THROWDEF_RTE; + virtual double SAL_CALL getQuotient( constREFXPS&, double fNum, double fDenum ) THROWDEF_RTE; + + virtual double SAL_CALL getMround( constREFXPS&, double fNum, double fMult ) THROWDEF_RTE; + virtual double SAL_CALL getSqrtpi( constREFXPS&, double fNum ) THROWDEF_RTE; + + virtual double SAL_CALL getRandbetween( constREFXPS&, double fMin, double fMax ) THROWDEF_RTE; + + virtual double SAL_CALL getGcd( constREFXPS&, const SEQSEQ( double )& aCoeffList ) THROWDEF_RTE; + virtual double SAL_CALL getLcm( constREFXPS&, const SEQSEQ( double )& aCoeffList ) THROWDEF_RTE; + + virtual double SAL_CALL getBesseli( constREFXPS&, double fNum, sal_Int32 nOrder ) THROWDEF_RTE; + virtual double SAL_CALL getBesselj( constREFXPS&, double fNum, sal_Int32 nOrder ) THROWDEF_RTE; + virtual double SAL_CALL getBesselk( constREFXPS&, double fNum, sal_Int32 nOrder ) THROWDEF_RTE; + virtual double SAL_CALL getBessely( constREFXPS&, double fNum, sal_Int32 nOrder ) THROWDEF_RTE; + + virtual STRING SAL_CALL getBin2oct( constREFXPS&, const STRING& aNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE; + virtual double SAL_CALL getBin2dec( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getBin2hex( constREFXPS&, const STRING& aNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE; + + virtual STRING SAL_CALL getOct2bin( constREFXPS&, const STRING& aNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE; + virtual double SAL_CALL getOct2dec( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getOct2hex( constREFXPS&, const STRING& aNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE; + + virtual STRING SAL_CALL getDec2bin( constREFXPS&, sal_Int32 fNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getDec2oct( constREFXPS&, sal_Int32 fNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getDec2hex( constREFXPS&, double fNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE; + + virtual STRING SAL_CALL getHex2bin( constREFXPS&, const STRING& aNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE; + virtual double SAL_CALL getHex2dec( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getHex2oct( constREFXPS&, const STRING& aNum, sal_Int32 nPlaces ) THROWDEF_RTE_IAE; + + virtual sal_Int32 SAL_CALL getDelta( constREFXPS&, double fNum1, double fNum2 ) THROWDEF_RTE; + + virtual double SAL_CALL getErf( constREFXPS&, double fLowerLimit, double fUpperLimit ) THROWDEF_RTE; + virtual double SAL_CALL getErfc( constREFXPS&, double fLowerLimit ) THROWDEF_RTE; + + virtual sal_Int32 SAL_CALL getGestep( constREFXPS&, double fNum, double fStep ) THROWDEF_RTE; + + virtual double SAL_CALL getFactdouble( constREFXPS&, sal_Int32 nNum ) THROWDEF_RTE_IAE; + + virtual double SAL_CALL getImabs( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE; + virtual double SAL_CALL getImaginary( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getImpower( constREFXPS&, const STRING& aNum, double fPower ) THROWDEF_RTE_IAE; + virtual double SAL_CALL getImargument( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getImcos( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getImdiv( constREFXPS&, const STRING& aDivident, const STRING& aDivisor ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getImexp( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getImconjugate( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getImln( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getImlog10( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getImlog2( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getImproduct( constREFXPS&, const STRING& aNum1, const STRING& aNum2 ) THROWDEF_RTE_IAE; + virtual double SAL_CALL getImreal( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getImsin( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getImsub( constREFXPS&, const STRING& aNum1, const STRING& aNum2 ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getImsum( constREFXPS&, const STRING& aNum1, const STRING& aNum2 ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getImsqrt( constREFXPS&, const STRING& aNum ) THROWDEF_RTE_IAE; + virtual STRING SAL_CALL getComplex( constREFXPS&, double fReal, double fImaginary, const STRING& rSuffix ) THROWDEF_RTE_IAE; + + virtual double SAL_CALL getConvert( constREFXPS&, double fVal, const STRING& aFromUnit, const STRING& aToUnit ) THROWDEF_RTE_IAE; +}; + +//------------------------------------------------------------------ + +#endif + diff --git a/scaddins/source/analysis/analysisadd.idl b/scaddins/source/analysis/analysisadd.idl new file mode 100644 index 000000000000..241387bbaf88 --- /dev/null +++ b/scaddins/source/analysis/analysisadd.idl @@ -0,0 +1,379 @@ +/************************************************************************* + * + * $RCSfile: analysisadd.idl,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: gt $ $Date: 2001-04-06 13:59:16 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#include +#include + +module com +{ +module sun +{ +module star +{ +module sheet +{ +module addin +{ + /** + * Interface with analysis functions. + */ + [ uik(20D2C191-648C-11d4-9F8D0050-04D75D79), ident("XAnalysis", 1.0) ] + interface XAnalysis : com::sun::star::uno::XInterface + { + /// _test. + double get_Test( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] long Mode, [in] double f1, [in] double f2, [in] double f3 ); + + + /// workday. + long getWorkday( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] long nStartDate, [in] long nDays, [in] sequence< sequence > aHolidays ); + + /// yearfrac. + double getYearfrac( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] long nStartDate, [in] long nEndDate, [in] long nMode ); + + /// edate. + long getEdate( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] long nStartDate, [in] long nNumOfMonths ); + + /// weeknum. + long getWeeknum( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] long nStartDate, [in] long nMode ); + + /// eomonth. + long getEomonth( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] long nStartDate, [in] long nMonths ); + + /// networkdays. + long getNetworkdays( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] long nStartDate, [in] long nEndDate, [in] sequence< sequence > aHolidays ); + + /// iseven. + long getIseven( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] long nValue ); + + /// isodd. + long getIsodd( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] long nValue ); + + /// multinomial. + double getMultinomial( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] sequence< sequence > aValList ); + + /// seriessum. + double getSeriessum( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double X, [in] double N, [in] double M, [in] sequence< sequence > CoeffList ); + + // quotient. + double getQuotient( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double Num, [in] double Denum ); + + // mround. + double getMround( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double Number, [in] double Multiple ); + + // sqrtpi. + double getSqrtpi( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double Number ); + + // randbetween. + double getRandbetween( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double Min, [in] double Max ); + + /// gcd. + double getGcd( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] sequence< sequence > ValList ); + + /// lcm. + double getLcm( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] sequence< sequence > ValList ); + + /// besseli. + double getBesseli( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double Num, [in] long Order ); + + /// besselj. + double getBesselj( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double Num, [in] long Order ); + + /// besselk. + double getBesselk( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double Num, [in] long Order ); + + /// bessely. + double getBessely( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double Num, [in] long Order ); + + /// bin2oct. + string getBin2oct( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string BinaryNum, [in] long nPlaces ); + + /// bin2dec. + double getBin2dec( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string BinaryNum ); + + /// bin2hex. + string getBin2hex( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string BinaryNum, [in] long nPlaces ); + + /// oct2bin. + string getOct2bin( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string OctalNum, [in] long nPlaces ); + + /// oct2dec. + double getOct2dec( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string OctalNum ); + + /// oct2hex. + string getOct2hex( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string OctalNum, [in] long nPlaces ); + + /// dec2bin. + string getDec2bin( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] long Value, [in] long nPlaces ); + + /// dec2oct. + string getDec2oct( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] long Value, [in] long nPlaces ); + + /// dec2hex. + string getDec2hex( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double Value, [in] long nPlaces ); + + /// hex2bin. + string getHex2bin( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string HexadecimalValue, [in] long nPlaces ); + + /// hex2dec. + double getHex2dec( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string HexadecimalValue ); + + /// hex2oct. + string getHex2oct( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string HexadecimalValue, [in] long nPlaces ); + + /// delta. + long getDelta( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double Num1, [in] double Num2 ); + + /// erf. + double getErf( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double LowerLimit, [in] double UpperLimit ); + + /// erfc. + double getErfc( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double LowerLimit ); + + /// gestep. + long getGestep( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double Num, [in] double Step ); + + /// factdouble. + double getFactdouble( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] long Num ); + + /// imabs. + double getImabs( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num ); + + /// imaginary. + double getImaginary( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num ); + + /// impower. + string getImpower( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num, [in] double Power ); + + /// imargument. + double getImargument( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num ); + + /// imcos. + string getImcos( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num ); + + /// imdiv. + string getImdiv( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num1, [in] string Num2 ); + + /// imexp. + string getImexp( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num ); + + /// imconjugate. + string getImconjugate( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num ); + + /// imln. + string getImln( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num ); + + /// imlog10. + string getImlog10( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num ); + + /// imlog2. + string getImlog2( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num ); + + /// improduct. + string getImproduct( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num1, [in] string Num2 ); + + /// imreal. + double getImreal( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num ); + + /// imsin. + string getImsin( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num ); + + /// imsub. + string getImsub( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num1, [in] string Num2 ); + + /// imsum. + string getImsum( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num1, [in] string Num2 ); + + /// imsqrt. + string getImsqrt( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] string Num ); + + /// complex. + string getComplex( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double Real, [in] double Imaginary, [in] string Suffix ); + + /// convert. + double getConvert( + [in] com::sun::star::beans::XPropertySet xOptions, + [in] double Value, [in] string FromUnit, [in] string ToUnit ); + }; + + service Analysis + { + // exported interfaces: + interface XAnalysis; + }; +}; +}; +}; +}; +}; + diff --git a/scaddins/source/analysis/analysisdefs.hxx b/scaddins/source/analysis/analysisdefs.hxx new file mode 100644 index 000000000000..899954973cac --- /dev/null +++ b/scaddins/source/analysis/analysisdefs.hxx @@ -0,0 +1,78 @@ +/************************************************************************* + * + * $RCSfile: analysisdefs.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: gt $ $Date: 2001-04-06 13:59:16 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef ANALYSISDEFS_HXX +#define ANALYSISDEFS_HXX + +#define CSS ::com::sun::star +#define XPROPSET CSS::beans::XPropertySet +#define REF(c) CSS::uno::Reference< c > +#define constREFXPS const REF(XPROPSET) +#define SEQ(c) CSS::uno::Sequence< c > +#define SEQSEQ(c) CSS::uno::Sequence< CSS::uno::Sequence< c > > +#define STRING ::rtl::OUString +#define STRFROMASCII(s) STRING::createFromAscii( s ) +#define THROWDEF_RTE throw(CSS::uno::RuntimeException) +#define THROWDEF_RTE_IAE throw(CSS::uno::RuntimeException,CSS::lang::IllegalArgumentException) +#define THROW_IAE throw CSS::lang::IllegalArgumentException() + +#endif + diff --git a/scaddins/source/analysis/analysishelper.cxx b/scaddins/source/analysis/analysishelper.cxx new file mode 100644 index 000000000000..3aeb98464520 --- /dev/null +++ b/scaddins/source/analysis/analysishelper.cxx @@ -0,0 +1,1800 @@ +/************************************************************************* + * + * $RCSfile: analysishelper.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: gt $ $Date: 2001-04-06 13:59:16 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#include "analysishelper.hxx" + +#include +#include + + + +static const double nKorrVal[] = { + 0, 9e-1, 9e-2, 9e-3, 9e-4, 9e-5, 9e-6, 9e-7, 9e-8, + 9e-9, 9e-10, 9e-11, 9e-12, 9e-13, 9e-14, 9e-15 +}; + + +double Round( double fVal, short nDec ) +{ + if ( fVal == 0.0 ) + return fVal; + + // sign adjustment + sal_Bool bSign = fVal < 0.0; + if ( bSign ) + fVal = -fVal; + + double fFac; + if ( nDec != 0 ) + { + // max 20 decimals, we don't have unlimited precision + // #38810# and no overflow on fVal*=fFac + if ( nDec < -20 || 20 < nDec || fVal > (1.7976931348623158e+308 / 1e20) ) + return bSign ? -fVal : fVal; + + fFac = pow( 10.0, nDec ); + fVal *= fFac; + } + //else //! uninitialized fFac, not needed + + int nExp; // exponent for correction + if ( fVal > 0.0 ) + nExp = (int) floor( log10( fVal ) ); + else + nExp = 0; + int nIndex = 15 - nExp; + if ( nIndex > 15 ) + nIndex = 15; + else if ( nIndex <= 1 ) + nIndex = 0; + fVal = floor( fVal + 0.5 + nKorrVal[nIndex] ); + + if ( nDec != 0 ) + fVal /= fFac; + + return bSign ? -fVal : fVal; +} + + +double _Test( sal_Int32 nMode, double f1, double f2, double f3 ) +{ + double f = -1.0; + switch( nMode ) + { + case 0: f = GammaN( f1, sal_uInt32( f2 ) ); break; + case 1: f = Gamma( f1 ); break; + } + + return f; +} + + +static sal_uInt16 aDaysInMonth[ 13 ] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + +sal_uInt16 DaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear ) +{ + + if( nMonth != 2 ) + return aDaysInMonth[ nMonth ]; + else + { + if( IsLeapYear( nYear ) ) + return aDaysInMonth[ nMonth ] + 1; + else + return aDaysInMonth[ nMonth ]; + } +} + + +sal_uInt16 DaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear, sal_Bool bLeapYear ) +{ + + if( nMonth != 2 ) + return aDaysInMonth[ nMonth ]; + else + { + if( bLeapYear ) + return aDaysInMonth[ nMonth ] + 1; + else + return aDaysInMonth[ nMonth ]; + } +} + + +/** + * Convert a date to a count of days starting from 01/01/0001 + * + * The internal representation of a Date used in this Addin + * is the number of days between 01/01/0001 and the date + * this function converts a Day , Month, Year representation + * to this internal Date value. + * + */ + +sal_Int32 DateToDays( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear ) +{ + sal_Int32 nDays = ((sal_Int32)nYear-1) * 365; + nDays += ((nYear-1) / 4) - ((nYear-1) / 100) + ((nYear-1) / 400); + + for( sal_uInt16 i = 1; i < nMonth; i++ ) + nDays += DaysInMonth(i,nYear); + nDays += nDay; + + return nDays; +} + + +/** + * Convert a count of days starting from 01/01/0001 to a date + * + * The internal representation of a Date used in this Addin + * is the number of days between 01/01/0001 and the date + * this function converts this internal Date value + * to a Day , Month, Year representation of a Date. + * + */ + +void DaysToDate( sal_Int32 nDays, sal_uInt16& rDay, sal_uInt16& rMonth, sal_uInt16& rYear ) +{ + sal_Int32 nTempDays; + sal_Int32 i = 0; + sal_Bool bCalc; + + do + { + nTempDays = nDays; + rYear = (sal_uInt16)((nTempDays / 365) - i); + nTempDays -= ((sal_Int32) rYear -1) * 365; + nTempDays -= (( rYear -1) / 4) - (( rYear -1) / 100) + ((rYear -1) / 400); + bCalc = sal_False; + if ( nTempDays < 1 ) + { + i++; + bCalc = sal_True; + } + else + { + if ( nTempDays > 365 ) + { + if ( (nTempDays != 366) || !IsLeapYear( rYear ) ) + { + i--; + bCalc = sal_True; + } + } + } + } + while ( bCalc ); + + rMonth = 1; + while ( (sal_Int32)nTempDays > DaysInMonth( rMonth, rYear ) ) + { + nTempDays -= DaysInMonth( rMonth, rYear ); + rMonth++; + } + rDay = (sal_uInt16)nTempDays; +} + + +/** + * Get the null date used by the spreadsheet document + * + * The internal representation of a Date used in this Addin + * is the number of days between 01/01/0001 and the date + * this function returns this internal Date value for the document null date + * + */ + +sal_Int32 GetNullDate( constREFXPS& xOpt ) THROWDEF_RTE +{ + if( xOpt.is() ) + { + try + { + uno::Any aAny = xOpt->getPropertyValue( STRFROMASCII( "NullDate" ) ); + util::Date aDate; + if( aAny >>= aDate ) + return DateToDays( aDate.Day, aDate.Month, aDate.Year ); + } + catch( uno::Exception& ) + { + } + } + + // no null date available -> no calculations possible + throw uno::RuntimeException(); +} + + +sal_Int32 GetDiffDate360( + sal_uInt16 nDay1, sal_uInt16 nMonth1, sal_uInt16 nYear1, sal_Bool bLeapYear1, + sal_uInt16 nDay2, sal_uInt16 nMonth2, sal_uInt16 nYear2, + sal_Bool bUSAMethod ) +{ + if( nDay1 == 31 ) + nDay1--; + else if( bUSAMethod && ( nMonth1 == 2 && ( nDay1 == 29 || ( nDay1 == 28 && !bLeapYear1 ) ) ) ) + nDay1 = 30; + + if( nDay2 == 31 ) + { + if( bUSAMethod && nDay1 != 30 ) + { + //aDate2 += 1; -> 1.xx.yyyy + nDay2 = 1; + if( nMonth2 == 12 ) + { + nYear2++; + nMonth2 = 1; + } + else + nMonth2++; + } + else + nDay2 = 30; + } + + return nDay2 + nMonth2 * 30 + nYear2 * 360 - nDay1 - nMonth1 * 30 - nYear1 * 360; +} + + +sal_Int32 GetDaysInYears( sal_uInt16 nYear1, sal_uInt16 nYear2 ) +{ + sal_uInt16 nLeaps = 0; + for( sal_uInt16 n = nYear1 ; n <= nYear2 ; n++ ) + { + if( IsLeapYear( n ) ) + nLeaps++; + } + + sal_uInt32 nSum = 1; + nSum += nYear2; + nSum -= nYear1; + nSum *= 365; + nSum += nLeaps; + + return nSum; +} + + +double Fak( sal_Int32 n ) +{ + if( n > 0 ) + { + double fRet = n; + double f = n - 1; + + while( f >= 2.0 ) + { + fRet *= f; + f--; + } + + return fRet; + } + else if( !n ) + return 1.0; + else + return 0.0; +} + + +double GetGcd( double f1, double f2 ) +{ + double f = fmod( f1, f2 ); + while( f > 0.0 ) + { + f1 = f2; + f2 = f; + f = fmod( f1, f2 ); + } + + return f2; +} + + +double GammaHelp( double& x, sal_Bool& bReflect ) +{ + double c[6] = {76.18009173, -86.50532033, 24.01409822, + -1.231739516, 0.120858003E-2, -0.536382E-5}; + if (x >= 1.0) + { + bReflect = sal_False; + x -= 1.0; + } + else + { + bReflect = sal_True; + x = 1.0 - x; + } + double s, anum; + s = 1.0; + anum = x; + for (sal_uInt16 i = 0; i < 6; i++) + { + anum += 1.0; + s += c[i]/anum; + } + s *= 2.506628275; // sqrt(2*PI) + return s; +} + + +double Gamma( double x ) +{ + sal_Bool bReflect; + double G = GammaHelp(x, bReflect); + G = pow(x+5.5,x+0.5)*G/exp(x+5.5); + if (bReflect) + G = PI*x/(G*sin(PI*x)); + return G; +} + + +double GammaN( double x, sal_uInt32 nIter ) +{ + double n = nIter; + double f = pow( n, x ) / x; + double c = 1.0; + + while( nIter ) + { + x++; + + f /= x; + f *= c; + + nIter--; + c++; + } + + return f; +} + + +double Bessel( double fNum, sal_Int32 nOrder, sal_Bool bModfied ) THROWDEF_RTE +{ + if( nOrder < 0 ) + return -1.0; + + double fZ, fZm, fN1, fN2, fn1, fn2, fAct, fOld; + sal_Int16 nIterMax = 100; + + fZ = fNum * 0.5; // x/2 + fZm = fZ * fZ; // (x/2)^2 + fZ = pow( fZ, double( nOrder ) ); // (x/2)^n + + fN1 = Fak( nOrder ); // n! + fn1 = 0.0; + fN2 = 1.0; + fn2 = double( nOrder ); + + fAct = fZ / fN1; + fOld = fAct * 0.9; + + if( bModfied ) + { + while( fAct != fOld && nIterMax ) + { + fZ *= fZm; + + fn1++; + fN1 *= fn1; + + fn2++; + fN2 *= fn2; + + fOld = fAct; + + fAct += fZ / fN1 / fN2; + + nIterMax--; + } + } + else + { + sal_Bool bAdd = sal_False; // start with second term, so subtraction is first in loop + + while( fAct != fOld && nIterMax ) + { + fZ *= fZm; + + fn1++; + fN1 *= fn1; + + fn2++; + fN2 *= fn2; + + fOld = fAct; + + if( bAdd ) + fAct += fZ / fN1 / fN2; + else + fAct -= fZ / fN1 / fN2; + + nIterMax--; + bAdd = !bAdd; + } + } + + return fAct; +} + + +double BesselR( double fNum, double fOrder ) THROWDEF_RTE +{ + double fZ, fZm, fN, fn, fAct, fOld; + sal_Int16 nIterMax = 100; + + fZ = fNum * 0.5; // x/2 + fZm = fZ * fZ; // (x/2)^2 + fZ = pow( fZ, fOrder ); // (x/2)^n + + fN = 1.0; // effectiv: k! + fn = 1.0; + + fOrder++; + fAct = fZ / Gamma( fOrder ); + fOld = fAct * 0.9; + + while( fAct != fOld && nIterMax ) + { + fZ *= fZm; + + fN *= fn; + fn++; + + fOld = fAct; + + fOrder++; + double fG = Gamma( fOrder ); + fAct += fZ / fN / fG; + + nIterMax--; + } + + return fAct; +} + + +double ConvertToDec( const STRING& aStr, sal_uInt16 nBase, sal_uInt16 nCharLim ) THROWDEF_RTE_IAE +{ + if ( nBase < 2 || nBase > 36 ) + return -1.0; + + sal_uInt32 nStrLen = aStr.getLength(); + if( nStrLen > nCharLim ) + THROW_IAE; + else if( !nStrLen ) + return 0.0; + + double fVal = 0.0; + + register const sal_Unicode* p = aStr.getStr(); + + sal_uInt16 nFirstDig; + sal_Bool bFirstDig = sal_True; + double fBase = nBase; + + while ( *p ) + { + sal_uInt16 n; + + if( '0' <= *p && *p <= '9' ) + n = *p - '0'; + else if( 'A' <= *p && *p <= 'Z' ) + n = 10 + ( *p - 'A' ); + else if ( 'a' <= *p && *p <= 'z' ) + n = 10 + ( *p - 'a' ); + else + n = nBase; + + if( n < nBase ) + { + if( bFirstDig ) + { + bFirstDig = sal_False; + nFirstDig = n; + } + fVal = fVal * fBase + double( n ); + } + else + // illegal char! + THROW_IAE; + + p++; + + } + + if( nStrLen == nCharLim && !bFirstDig && nFirstDig == nBase - 1 ) + { // handling negativ values + fVal = ( pow( double( nBase ), double( nCharLim ) ) - fVal ); // complement + fVal *= -1.0; + } + + return fVal; +} + + +static inline sal_Char GetMaxChar( sal_uInt16 nBase ) +{ + const sal_Char* c = "--123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + return c[ nBase ]; +} + + +STRING ConvertFromDec( sal_Int64 nNum, sal_Int64 nMin, sal_Int64 nMax, sal_uInt16 nBase, + sal_Int32 nPlaces, sal_Int32 nMaxPlaces ) THROWDEF_RTE_IAE +{ + if( nNum < nMin || nNum > nMax || nPlaces <= 0 || nPlaces > nMaxPlaces ) + THROW_IAE; + + sal_Bool bNeg = nNum < 0; + if( bNeg ) + nNum = sal_Int64( pow( double( nBase ), double( nMaxPlaces ) ) ) + nNum; + + STRING aRet( STRING::valueOf( nNum, nBase ).toUpperCase() ); + + sal_Int32 nLen = aRet.len(); + if( !bNeg && nLen > nPlaces ) + THROW_IAE; + else if( ( bNeg && nLen < nMaxPlaces ) || ( !bNeg && nLen < nPlaces ) ) + { + sal_uInt32 nLeft = nPlaces - nLen; + sal_Char* p = new sal_Char[ nLeft + 1 ]; + memset( p, bNeg? GetMaxChar( nBase ) : '0', nLeft ); + p[ nLeft ] = 0x00; + STRING aTmp( p, nLeft, RTL_TEXTENCODING_MS_1252 ); + aTmp += aRet; + aRet = aTmp; + + delete[] p; + } + + return aRet; +} + + +double Erf( double x ) +{ + if( x == 0.0 ) + return 0.0; + + double f, fZm, fN2, fn1, fOld, fT; + sal_Bool bAdd = sal_True; + sal_Int32 nMaxIter = 1000; + + fZm = x; + fZm *= x; // x^2 + + fn1 = 2.0; + fN2 = 3.0; + + fT = x * fZm; + + f = x - fT / fN2; + + fOld = f * 0.9; + + while( f != fOld && nMaxIter ) + { + fOld = f; + + fN2 += 2.0; + + fT /= fn1; + fT *= fZm; + + fn1++; + + if( bAdd ) + f += fT / fN2; + else + f -= fT / fN2; + + bAdd = !bAdd; + + nMaxIter--; + } + + return f * 1.128379167095512573896; // * 2/sqrt(PI) +} + + +inline sal_Bool IsNum( sal_Unicode c ) +{ + return c >= '0' && c <= '9'; +} + + +inline sal_Bool IsComma( sal_Unicode c ) +{ + return c == '.' || c == ','; +} + + +inline sal_Bool IsExpStart( sal_Unicode c ) +{ + return c == 'e' || c == 'E'; +} + + +inline sal_Bool IsImagUnit( sal_Unicode c ) +{ + return c == 'i' || c == 'j'; +} + + +inline sal_uInt16 GetVal( sal_Unicode c ) +{ + return sal_uInt16( c - '0' ); +} + + +sal_Bool ParseDouble( const sal_Unicode*& rp, double& rRet ) +{ + double fInt = 0.0; + double fFrac = 0.0; + double fMult = 0.1; // multiplier to multiply digits with, when adding fractional ones + sal_Int32 nExp = 0; + sal_Int32 nMaxExp = 307; + sal_uInt16 nDigCnt = 18; // max. number of digits to read in, rest doesn't matter + + enum State { S_End = 0, S_Sign, S_IntStart, S_Int, S_IgnoreIntDigs, S_Frac, S_IgnoreFracDigs, S_ExpSign, S_Exp }; + + State eS = S_Sign; + + sal_Bool bNegNum = sal_False; + sal_Bool bNegExp = sal_False; + + const sal_Unicode* p = rp; + sal_Unicode c; + + while( eS ) + { + c = *p; + switch( eS ) + { + case S_Sign: + if( IsNum( c ) ) + { + fInt = GetVal( c ); + nDigCnt--; + eS = S_Int; + } + else if( c == '-' ) + { + bNegNum = sal_True; + eS = S_IntStart; + } + else if( c == '+' ) + eS = S_IntStart; + else if( IsComma( c ) ) + eS = S_Frac; + else + return sal_False; + break; + case S_IntStart: + if( IsNum( c ) ) + { + fInt = GetVal( c ); + nDigCnt--; + eS = S_Int; + } + else if( IsComma( c ) ) + eS = S_Frac; + else if( IsImagUnit( c ) ) + { + rRet = bNegNum? -1.0 : 1.0; + return sal_True; + } + else + return sal_False; + break; + case S_Int: + if( IsNum( c ) ) + { + fInt *= 10.0; + fInt += double( GetVal( c ) ); + nDigCnt--; + if( !nDigCnt ) + eS = S_IgnoreIntDigs; + } + else if( IsComma( c ) ) + eS = S_Frac; + else if( IsExpStart( c ) ) + eS = S_ExpSign; + else + eS = S_End; + break; + case S_IgnoreIntDigs: + if( IsNum( c ) ) + nExp++; // just multiply num with 10... ;-) + else if( IsComma( c ) ) + eS = S_Frac; + else if( IsExpStart( c ) ) + eS = S_ExpSign; + else + eS = S_End; + break; + case S_Frac: + if( IsNum( c ) ) + { + fFrac += double( GetVal( c ) ) * fMult; + nDigCnt--; + if( nDigCnt ) + fMult *= 0.1; + else + eS = S_IgnoreFracDigs; + } + else if( IsExpStart( c ) ) + eS = S_ExpSign; + else + eS = S_End; + break; + case S_IgnoreFracDigs: + if( IsExpStart( c ) ) + eS = S_ExpSign; + else if( !IsNum( c ) ) + eS = S_End; + break; + case S_ExpSign: + if( IsNum( c ) ) + { + nExp = GetVal( c ); + eS = S_Exp; + } + else if( c == '-' ) + { + bNegExp = sal_True; + eS = S_Exp; + } + else if( c != '+' ) + eS = S_End; + break; + case S_Exp: + if( IsNum( c ) ) + { + nExp *= 10; + nExp += GetVal( c ); + if( nExp > nMaxExp ) + return sal_False; + } + else + eS = S_End; + break; + } + + p++; + } + + p--; // set pointer back to last + rp = p; + + fInt += fFrac; + sal_Int32 nLog10 = sal_Int32( log( fInt ) ); + + if( bNegExp ) + nExp = -nExp; + + if( nLog10 + nExp > nMaxExp ) + return sal_False; + + fInt *= pow( 10.0, nExp ); + + if( bNegNum ) + fInt = -fInt; + + rRet = fInt; + + return sal_True; +} + + +STRING GetString( double f, sal_Bool bLeadingSign, sal_uInt16 nMaxDig ) +{ + const int nBuff = 256; + sal_Char* pBuff = new sal_Char[ nBuff + 1 ]; + const char* pFormStr = bLeadingSign? "%+.*g" : "%.*g"; + int nLen = sprintf( pBuff, pFormStr, int( nMaxDig ), f ); + + STRING aRet( pBuff, nLen, RTL_TEXTENCODING_MS_1252 ); + + delete pBuff; + + return aRet; +} + + +double Exp10( sal_Int16 n ) +{ + return pow( 10.0, double( n ) ); +} + + + + +const sal_uInt32 List::nStartSize = 16; +const sal_uInt32 List::nIncrSize = 16; + + +void List::_Grow( void ) +{ + nSize += nIncrSize; + + void** pNewData = new void*[ nSize ]; + memcpy( pNewData, pData, nNew * sizeof( void* ) ); + + delete pData; + pData = pNewData; +} + + +List::List( void ) +{ + nSize = nStartSize; + pData = new void*[ nSize ]; + nNew = nAct = 0; +} + + +List::~List() +{ + delete pData; +} + + +void List::Insert( void* p, sal_uInt32 n ) +{ + if( n >= nNew ) + Append( p ); + else + { + Grow(); + + void** pIns = pData + n; + memmove( pIns, pIns + 1, 1 ); + + *pIns = p; + + nNew++; + } +} + + + + +FuncData::FuncData( void ) +{ + pIntName = ""; + pGerman = "KEIN_NAME_ZUGEWIESEN"; + pEnglish = "NO_NAME_ASSIGNED"; + pDescr = ""; + ppParam = ppParamDescr = NULL; + nParam = nParamDescr = 0; +} + + +FuncData::~FuncData() +{ + if( ppParam ) + delete[] ppParam; + if( ppParamDescr ) + delete[] ppParamDescr; +} + + +const sal_Char* FuncData::GetParam( sal_uInt32 nInd ) const +{ + if( !nInd ) + return "(internal)"; + + nInd--; + + if( nInd < nParam ) + return ppParam[ nInd ]; + else + return ""; +} + + +const sal_Char* FuncData::GetParamDescr( sal_uInt32 nInd ) const +{ + if( !nInd ) + return "(internal)"; + + nInd--; + + if( nInd < nParamDescr ) + return ppParamDescr[ nInd ]; + else + return ""; +} + + +FuncData* FuncData::CloneFromList( const sal_Char**& rpp ) +{ + const sal_Char** pp = rpp; + const sal_Char* pAct = *pp; + + if( pAct == EOL ) + return NULL; + + FuncData* p = new FuncData; + sal_Bool bRead = sal_True; + CStrList aPNList; + CStrList aPDList; + + while( bRead ) + { + if( pAct == EOE ) + bRead = sal_False; + else + { + switch( *pAct ) + { + case 'i': p->pIntName = pAct + 1; break; + case '1': p->pGerman = pAct + 1; break; + case '2': p->pEnglish = pAct + 1; break; + case 'd': p->pDescr = pAct + 1; break; + case 'p': aPNList.Append( pAct + 1 ); break; + case 'P': aPDList.Append( pAct + 1 ); break; + } + + } + + pp++; + pAct = *pp; + } + + sal_uInt32 nE = aPNList.Count(); + sal_uInt32 n; + if( nE ) + { + if( nE > 255 ) + nE = 255; + + p->nParam = nE; + const sal_Char** pArray = new const sal_Char*[ nE ]; + p->ppParam = pArray; + + for( n = 0 ; n < nE ; n++ ) + pArray[ n ] = aPNList.Get( n ); + } + + nE = aPDList.Count(); + if( nE ) + { + if( nE > 255 ) + nE = 255; + + p->nParamDescr = nE; + const sal_Char** pArray = new const sal_Char*[ nE ]; + p->ppParamDescr = pArray; + + for( n = 0 ; n < nE ; n++ ) + pArray[ n ] = aPDList.Get( n ); + } + + rpp = pp; + + return p; +} + + + + +FuncDataList::FuncDataList( const sal_Char** pFD ) +{ + nLast = 0xFFFFFFFF; + + const sal_Char** pp = pFD; + FuncData* p = FuncData::CloneFromList( pp ); + + while( p ) + { + Append( p ); + p = FuncData::CloneFromList( pp ); + } + +} + + +FuncDataList::~FuncDataList() +{ + for( FuncData* p = ( FuncData* ) First() ; p ; p = ( FuncData* ) Next() ) + delete p; +} + + +const FuncData* FuncDataList::Get( const OUString& aProgrammaticName ) const +{ + if( aLastName == aProgrammaticName ) + return Get( nLast ); + + ( ( FuncDataList* ) this )->aLastName = aProgrammaticName; + + sal_uInt32 nE = Count(); + for( sal_uInt32 n = 0 ; n < nE ; n++ ) + { + const FuncData* p = Get( n ); + if( aProgrammaticName.compareToAscii( p->pIntName ) == 0 ) + { + ( ( FuncDataList* ) this )->nLast = n; + return p; + } + } + + ( ( FuncDataList* ) this )->nLast = 0xFFFFFFFF; + return NULL; +} + + + + +SortedIndividualInt32List::SortedIndividualInt32List() +{ +} + + +SortedIndividualInt32List::~SortedIndividualInt32List() +{ +} + + +void SortedIndividualInt32List::Insert( sal_Int32 nVal ) +{ + sal_Int32 n = Count(); + + while( n ) + { + n--; + sal_Int32 nRef = Get( n ); + if( nVal == nRef ) + return; + else if( nVal > nRef ) + { + List::Insert( ( void* ) nVal, n + 1 ); + return; + } + } + + // smalest (or first) element + List::Insert( ( void* ) nVal, sal_uInt32( 0 ) ); +} + + +sal_Int32 SortedIndividualInt32List::CountCondition( sal_Int32 nMinVal, sal_Int32 nMaxVal ) const +{ + sal_uInt32 nE = Count(); + + if( !nE || nMaxVal < Get( 0 ) || nMinVal > Get( nE - 1 ) ) + // don't care if list is empty + // ~ if nMaxVal is smaler than smalest value in list + // ~ if nMinVal is bigger than biggest value in list + return 0; + + sal_uInt32 n; + sal_Int32 nCnt = 0; + + for( n = 0 ; n < nE && Get( n ) < nMinVal ; n++); // skip values less than nMinVal + + for( ; n < nE ; n++ ) + { + if( Get( n ) <= nMaxVal ) + nCnt++; + else + break; + } + + return nCnt; +} + + +sal_Bool SortedIndividualInt32List::Find( sal_Int32 nVal ) const +{ + sal_uInt32 nE = Count(); + + if( !nE || nVal < Get( 0 ) || nVal > Get( nE - 1 ) ) + return sal_False; + + // linear search + + for( sal_uInt32 n = 0 ; n < nE ; n++ ) + { + sal_Int32 nRef = Get( n ); + + if( nRef == nVal ) + return sal_True; + else if( nRef > nVal ) + return sal_False; + } + return sal_False; +} + + +void SortedIndividualInt32List::InsertHolidayList( const SEQSEQ( sal_Int32 )& aHD, sal_Int32 nND, sal_Bool bInsOnWE ) +{ + sal_Int32 n1, n2; + sal_Int32 nE1 = aHD.getLength(); + sal_Int32 nE2; + + for( n1 = 0 ; n1 < nE1 ; n1++ ) + { + const SEQ( sal_Int32 )& rList = aHD[ n1 ]; + nE2 = rList.getLength(); + const sal_Int32* pList = rList.getConstArray(); + + for( n2 = 0 ; n2 < nE2 ; n2++ ) + { + sal_Int32 n = pList[ n2 ]; + + if( n ) + { + n += nND; + if( bInsOnWE || GetDayOfWeek( n ) < 5 ) + Insert( n ); + } + } + } +} + + + + +DoubleList::~DoubleList() +{ + for( double* p = ( double* ) List::First(); p ; p = ( double* ) List::Next() ) + delete p; +} + + +sal_Bool DoubleList::Append( const SEQSEQ( double )& aVLst ) +{ + sal_Int32 n1, n2; + sal_Int32 nE1 = aVLst.getLength(); + sal_Int32 nE2; + sal_Int32 nZ = 0; + + for( n1 = 0 ; n1 < nE1 ; n1++ ) + { + const SEQ( double )& rList = aVLst[ n1 ]; + nE2 = rList.getLength(); + const double* pList = rList.getConstArray(); + + for( n2 = 0 ; n2 < nE2 ; n2++ ) + { + double f = pList[ n2 ]; + if( IsFaulty( f ) ) + return sal_False; + if( IsProper( f ) ) + _Append( f ); + } + } + + return sal_True; +} + + +sal_Bool DoubleList::IsProper( double ) const +{ + return sal_True; +} + + +sal_Bool DoubleList::IsFaulty( double ) const +{ + return sal_False; +} + + + + +sal_Bool ChkDoubleList1::IsProper( double f ) const +{ + return f > 0.0; +} + +sal_Bool ChkDoubleList1::IsFaulty( double f ) const +{ + return f < 0.0; +} + + + + +Complex::Complex( const STRING& r ) THROWDEF_RTE_IAE +{ + if( !ParseString( r, *this ) ) + THROW_IAE; +} + + +sal_Bool Complex::ParseString( const STRING& rStr, Complex& rCompl ) +{ + const sal_Unicode* pStr = ( const sal_Unicode * ) rStr; + double f; + + if( !ParseDouble( pStr, f ) ) + return sal_False; + + switch( *pStr ) + { + case '-': // imag part follows + case '+': + { + double r = f; + if( ParseDouble( pStr, f ) && ( *pStr == 'j' || *pStr == 'i' ) ) + { + pStr++; + if( *pStr == 0 ) + { + rCompl.r = r; + rCompl.i = f; + return sal_True; + } + } + } + break; + case 'j': + case 'i': + pStr++; + if( *pStr == 0 ) + { + rCompl.i = f; + rCompl.r = 0.0; + return sal_True; + } + break; + case 0: // only real-part + rCompl.r = f; + rCompl.i = 0.0; + return sal_True; + } + + return sal_False; +} + + +STRING Complex::GetString( sal_Bool bi ) const +{ + static const STRING aI( "i", 1, RTL_TEXTENCODING_MS_1252 ); + static const STRING aJ( "j", 1, RTL_TEXTENCODING_MS_1252 ); + static const STRING aPlus( "+", 1, RTL_TEXTENCODING_MS_1252 ); + static const STRING aMinus( "-", 1, RTL_TEXTENCODING_MS_1252 ); + + STRING aRet( ::GetString( r ) ); + + if( i == 1.0 ) + aRet += aPlus; + else if( i == -1.0 ) + aRet += aMinus; + else + aRet += ::GetString( i, sal_True ); + + aRet += bi? aI : aJ; + + return aRet; +} + + +double Complex::Arg( void ) const THROWDEF_RTE_IAE +{ + if( r == 0.0 && i == 0.0 ) + THROW_IAE; + + double phi = acos( r / Abs() ); + + if( i < 0.0 ) + phi = -phi; + + return phi; +} + + +void Complex::Power( double fPower ) THROWDEF_RTE_IAE +{ + if( r == 0.0 && i == 0.0 ) + { + if( fPower > 0 ) + r = i = 0.0; + else + THROW_IAE; + } + + double p, phi; + + p = Abs(); + + phi = acos( r / p ); + if( i < 0.0 ) + phi = -phi; + + p = pow( p, fPower ); + phi *= fPower; + + r = cos( phi ) * p; + i = sin( phi ) * p; +} + + +void Complex::Sin( void ) THROWDEF_RTE_IAE +{ + double r_; + + r_ = sin( r ) * cosh( i ); + i = -cos( r ) * sinh( i ); + r = r_; +} + + +void Complex::Cos( void ) THROWDEF_RTE_IAE +{ + double r_; + + r_ = cos( r ) * cosh( i ); + i = -sin( r ) * sinh( i ); + r = r_; +} + + +void Complex::Div( const Complex& z ) THROWDEF_RTE_IAE +{ + if( z.r == 0 && z.i == 0 ) + THROW_IAE; + + double a1 = r; + double a2 = z.r; + double b1 = i; + double b2 = z.i; + + double f = 1.0 / ( a2 * a2 + b2 * b2 ); + + r = ( a1 * a2 + b1 * b2 ) * f; + i = ( a2 * b1 - a1 * b2 ) * f; +} + + +void Complex::Exp( void ) +{ + Mult( exp( r ) ); +} + + +void Complex::Ln( void ) THROWDEF_RTE_IAE +{ + if( r == 0.0 && i == 0.0 ) + THROW_IAE; + + double r_; + + r_ = log( Abs() ); + + i = atan( i / r ); + r = r_; +} + + +void Complex::Log10( void ) THROWDEF_RTE_IAE +{ + Ln(); + Mult( 0.434294481903251828 ); // * log10( e ) +} + + +void Complex::Log2( void ) THROWDEF_RTE_IAE +{ + Ln(); + Mult( 1.442695040888963407 ); // * log2( e ) +} + + + + +ComplexList::~ComplexList() +{ + for( Complex* p = ( Complex* ) First() ; p ; p = ( Complex* ) Next() ) + delete p; +} + + +void ComplexList::Append( const SEQSEQ( STRING )& r ) THROWDEF_RTE_IAE +{ + sal_Int32 n1, n2; + sal_Int32 nE1 = r.getLength(); + sal_Int32 nE2; + + for( n1 = 0 ; n1 < nE1 ; n1++ ) + { + const SEQ( STRING )& rList = r[ n1 ]; + nE2 = rList.getLength(); + + for( n2 = 0 ; n2 < nE2 ; n2++ ) + Append( new Complex( rList[ n2 ] ) ); + } +} + + + + +ConvertData::ConvertData( const sal_Char p[], double fC, ConvertDataClass e ) : aName( p, strlen( p ), RTL_TEXTENCODING_MS_1252 ) +{ + fConst = fC; + eClass = e; +} + + +sal_Int16 ConvertData::GetMatchingLevel( const STRING& rRef ) const +{ + if( aName.equals( rRef ) ) + return 0; + else + { + const sal_Unicode* p = rRef.getStr(); + + if( wcscmp( aName.getStr(), p + 1 ) == 0 ) + { + sal_Int16 n; + switch( *p ) + { + case 'y': n = -24; break; // yocto + case 'z': n = -21; break; // zepto + case 'a': n = -18; break; + case 'f': n = -15; break; + case 'p': n = -12; break; + case 'n': n = -9; break; + case 'u': n = -6; break; + case 'm': n = -3; break; + case 'c': n = -2; break; + case 'd': n = -1; break; + case 'e': n = 1; break; + case 'h': n = 2; break; + case 'k': n = 3; break; + case 'M': n = 6; break; + case 'G': n = 9; break; + case 'T': n = 12; break; + case 'P': n = 15; break; + case 'E': n = 18; break; + case 'Z': n = 21; break; // zetta + case 'Y': n = 24; break; // yotta + default: + n = INV_MATCHLEV; + } + + return n; + } + else + return INV_MATCHLEV; + } +} + + +double ConvertData::Convert( + double f, const ConvertData& r, sal_Int16 nLevFrom, sal_Int16 nLevTo ) const THROWDEF_RTE_IAE +{ + if( Class() != r.Class() ) + THROW_IAE; + + nLevFrom -= nLevTo; // effectiv level + + f *= r.fConst / fConst; + + if( nLevFrom ) + f *= Exp10( nLevFrom ); + + return f; +} + + +double ConvertData::ConvertToBase( double f, sal_Int16 n ) const +{ + return f / fConst * Exp10( n ); +} + + +double ConvertData::ConvertFromBase( double f, sal_Int16 n ) const +{ + return f * fConst * Exp10( -n ); +} + + + + +double ConvertDataLinear::Convert( + double f, const ConvertData& r, sal_Int16 nLevFrom, sal_Int16 nLevTo ) const THROWDEF_RTE_IAE +{ + if( Class() != r.Class() ) + THROW_IAE; + +// return Round( r.ConvertFromBase( ConvertToBase( f, nLevFrom ), nLevTo ), 13 ); + return r.ConvertFromBase( ConvertToBase( f, nLevFrom ), nLevTo ); +} + + +double ConvertDataLinear::ConvertToBase( double f, sal_Int16 n ) const +{ + if( n ) + f *= Exp10( n ); + + f /= fConst; + f -= fOffs; + + return f; +} + + +double ConvertDataLinear::ConvertFromBase( double f, sal_Int16 n ) const +{ + f += fOffs; + f *= fConst; + + if( n ) + f *= Exp10( -n ); + + return f; +} + + + + +ConvertDataList::ConvertDataList( void ) +{ +#define NEWD(str,unit,cl) Append(new ConvertData(str,unit,cl)) +#define NEWL(str,unit,offs,cl) Append(new ConvertDataLinear(str,unit,offs,cl)) + + // *** are extra and not standard Excel Analysis Addin! + + // Gramm -> + NEWD( "g", 1.0000000000000000E00, CDC_Mass ); // Gramm + NEWD( "sg", 6.8522050005347800E-05, CDC_Mass ); // Stueck + NEWD( "lbm", 2.2046229146913400E-03, CDC_Mass ); // Pfund (Handelsgewicht) +// NEWD( "u", 6.0221700000000000E23, CDC_Mass ); // U (atomare Masseinheit) + NEWD( "u", 6.0221370000000000E23, CDC_Mass ); // U (atomare Masseinheit) + NEWD( "ozm", 3.5273971800362700E-02, CDC_Mass ); // Unze (Handelsgewicht) + NEWD( "stone", 1.574730e-04, CDC_Mass ); // Stone *** + NEWD( "ton", 1.102311e-06, CDC_Mass ); // ton *** + NEWD( "grain", 1.543236E01, CDC_Mass ); // grain *** + NEWD( "pweight", 7.054792E-01, CDC_Mass ); // Pennyweight *** + NEWD( "hweight", 1.968413E-05, CDC_Mass ); // Hundredweight *** + NEWD( "shweight", 2.204623e-05, CDC_Mass ); // Shorthundredweight *** + + // Meter -> + NEWD( "m", 1.0000000000000000E00, CDC_Length ); // Meter + NEWD( "mi", 6.2137119223733397E-04, CDC_Length ); // Britsche Meile 6,21371192237333969617434184363e-4 + NEWD( "Nmi", 5.3995680345572354E-04, CDC_Length ); // Nautische Meile 5,39956803455723542116630669546e-4 + NEWD( "in", 3.9370078740157480E01, CDC_Length ); // Zoll 39,37007874015748031496062992126 + NEWD( "ft", 3.2808398950131234E00, CDC_Length ); // Fuss 3,2808398950131233595800524934383 + NEWD( "yd", 1.0936132983377078E00, CDC_Length ); // Yard 1,0936132983377077865266841644794 + NEWD( "ang", 1.0000000000000000E10, CDC_Length ); // Angstroem + NEWD( "Pica", 2.8346456692913386E03, CDC_Length ); // Pica (1/72 Zoll) 2834,6456692913385826771653543307 + NEWD( "ell", 8.748906E-01, CDC_Length ); // Elle? *** + + // Sekunde -> + NEWD( "yr", 3.1688087814028950E-08, CDC_Time ); // Jahr + NEWD( "day", 1.1574074074074074E-05, CDC_Time ); // Tag + NEWD( "hr", 2.7777777777777778E-04, CDC_Time ); // Stunde + NEWD( "mn", 1.6666666666666667E-02, CDC_Time ); // Minute + NEWD( "sec", 1.0000000000000000E00, CDC_Time ); // Sekunde + + // Pascal -> + NEWD( "Pa", 1.0000000000000000E00, CDC_Pressure ); // Pascal + NEWD( "atm", 9.8692329999819300E-06, CDC_Pressure ); // Atmoshpaere + NEWD( "mmHg", 7.5006170799862700E-03, CDC_Pressure ); // mm Quecksilbersaeule + NEWD( "Torr", 7.5006380000000000E-03, CDC_Pressure ); // Torr *** + NEWD( "psi", 1.4503770000000000E-04, CDC_Pressure ); // psi *** + + // Newton -> + NEWD( "N", 1.0000000000000000E00, CDC_Force ); // Newton + NEWD( "dyn", 1.0000000000000000E05, CDC_Force ); // Dyn + NEWD( "pond", 1.019716E02, CDC_Force ); // Pond + + // Joule -> + NEWD( "J", 1.0000000000000000E00, CDC_Energy ); // Joule +// NEWD( "e", 9.99999519343231E06, CDC_Energy ); // Erg + NEWD( "e", 1.0000000000000000E07, CDC_Energy ); // Erg -> http://www.chemie.fu-berlin.de/chemistry/general/si.html + NEWD( "c", 2.3900624947346700E-01, CDC_Energy ); // Thermodynamische Kalorie + NEWD( "cal", 2.3884619064201700E-01, CDC_Energy ); // Kalorie + NEWD( "eV", 6.2414570000000000E18, CDC_Energy ); // Elektronenvolt +// NEWD( "HPh", 3.72506430801000E-07, CDC_Energy ); // Pferdestaerke mal Stunde + NEWD( "HPh", 3.7250611111111111E-07, CDC_Energy ); // Horsepower mal Stunde + NEWD( "Wh", 2.7777777777777778E-04, CDC_Energy ); // Watt mal Stunde + NEWD( "BTU", 9.4781506734901500E-04, CDC_Energy ); // BTU + + // Watt -> + NEWD( "W", 1.0000000000000000E00, CDC_Power ); // Watt + NEWD( "HP", 1.341022E-03, CDC_Power ); // Horsepower + NEWD( "PS", 1.359622E-03, CDC_Power ); // Pferdestaerke *** +//EWD( "HP", 1.4102006031908E-03, CDC_Power ); // PS ->Excel seams to be a little bit wrong... + // either this doesn't fit to J -> HPh.... + + // Tesla -> + NEWD( "T", 1.0000000000000000E00, CDC_Magnetism ); // Tesla + NEWD( "ga", 1.0000000000000000E04, CDC_Magnetism ); // Gauss + + // Grad Kelvin -> + NEWL( "C", 1.0000000000000000E00, -2.7315000000000000E02, CDC_Temperature ); // Grad Celsius + NEWL( "F", 1.8000000000000000E00, -2.5537222222222222E02, CDC_Temperature ); // Grad Fahrenheit + NEWL( "K", 1.0000000000000000E00, +0.0000000000000000E00, CDC_Temperature ); // Grad Kelvin + NEWL( "Reau", 8.0000000000000000E-01, -2.7315000000000000E02, CDC_Temperature ); // Grad Reaumur *** + NEWL( "Rank", 1.8000000000000000E00, +0.0000000000000000E00, CDC_Temperature ); // Grad Rankine *** + + // Liter -> + NEWD( "tsp", 2.0284000000000000E02, CDC_Volume ); // Teeloeffel (Teaspoon) + NEWD( "tbs", 6.7613333333333333E01, CDC_Volume ); // Essloeffel (Tablespoon) + NEWD( "oz", 3.3806666666666667E01, CDC_Volume ); // Unze (Fluessigkeit) + NEWD( "cup", 4.2258333333333333E00, CDC_Volume ); // Tasse (Cup) + NEWD( "pt", 2.1129166666666667E00, CDC_Volume ); // Pint + NEWD( "qt", 1.0564583333333333E00, CDC_Volume ); // Quart + NEWD( "gal", 2.6411458333333333E-01, CDC_Volume ); // Gallone + NEWD( "l", 1.0000000000000000E00, CDC_Volume ); // Liter + NEWD( "m3", 1.0000000000000000E03, CDC_Volume ); // Meter^3 *** + NEWD( "mi3", 2.3991275857892772E-10, CDC_Volume ); // Britsche Meile^3 *** + NEWD( "Nmi3", 1.5742621468581148E-10, CDC_Volume ); // Nautische Meile^3 *** + NEWD( "in3", 6.1023744094732284E04, CDC_Volume ); // Zoll^3 *** + NEWD( "ft3", 3.5314666721488590E01, CDC_Volume ); // Fuss^3 *** + NEWD( "yd3", 1.3079506193143922E00, CDC_Volume ); // Yard^3 *** + NEWD( "ang3", 1.0000000000000000E30, CDC_Volume ); // Angstroem^3 *** + NEWD( "Pica3", 2.2776990435870636E10, CDC_Volume ); // Pica^3 *** + NEWD( "barrel", 6.289811E-03, CDC_Volume ); // Barrel (=42gal?) *** + NEWD( "bushel", 2.837759E-02, CDC_Volume ); // Bushel *** + NEWD( "regton", 3.531467E-04, CDC_Volume ); // Register ton *** + NEWD( "Sixpack",2.0, CDC_Volume ); // Sixpack *** + + // Meter^2 -> + NEWD( "m2", 1.0000000000000000E00, CDC_Area ); // Meter^2 *** + NEWD( "mi2", 3.8610215854244585E-07, CDC_Area ); // Britsche Meile^2 *** + NEWD( "Nmi2", 2.9155334959812286E-07, CDC_Area ); // Nautische Meile^2 *** + NEWD( "in2", 1.5500031000062000E03, CDC_Area ); // Zoll^2 *** + NEWD( "ft2", 1.0763910416709722E01, CDC_Area ); // Fuss^2 *** + NEWD( "yd2", 1.0936132983377078E00, CDC_Area ); // Yard^2 *** + NEWD( "ang2", 1.0000000000000000E20, CDC_Area ); // Angstroem^2 *** + NEWD( "Pica2", 8.0352160704321409E06, CDC_Area ); // Pica^2 *** + NEWD( "Morgen", 2.553167E03, CDC_Area ); // Morgen *** + NEWD( "ar", 1.000000E02, CDC_Area ); // Ar *** + NEWD( "acre", 4.046856E03, CDC_Area ); // acre (oder auch Acker) *** + NEWD( "ha", 1.000000E04, CDC_Area ); // Hektar *** + NEWD( "Quadratlatschen", 0.1764, CDC_Area ); // *** + + // Meter/Sekunde -> + NEWD( "m/s", 1.0000000000000000E00, CDC_Speed ); // Meter/Sekunde *** + NEWD( "m/h", 3.6000000000000000E03, CDC_Speed ); // Meter/Stunde -> km/h *** + NEWD( "mph", 2.2369362920544023E00, CDC_Speed ); // (Britsche) Meilen/Stunde *** + NEWD( "kn", 1.9438444924406048E00, CDC_Speed ); // Knoten = (Nautische) Meilen/Stunde *** + NEWD( "admkn", 1.9438446603753486E00, CDC_Speed ); // Admiraltyknot *** + + // +// Append( new ConvertData( "", , CDC_Length ) ); // +// NEWD( "", , ); // +} + + +ConvertDataList::~ConvertDataList() +{ + for( ConvertData* p = First() ; p ; p = Next() ) + delete p; +} + + +double ConvertDataList::Convert( double fVal, const STRING& rFrom, const STRING& rTo ) THROWDEF_RTE_IAE +{ + if( rFrom == rTo ) + return fVal; + + ConvertData* pFrom = NULL; + ConvertData* pTo = NULL; + sal_Bool bSearchFrom = sal_True; + sal_Bool bSearchTo = sal_True; + sal_Int16 nLevelFrom = 0; + sal_Int16 nLevelTo = 0; + + ConvertData* p = First(); + while( p && ( bSearchFrom || bSearchTo ) ) + { +#define CHECKIT(part) + + if( bSearchFrom ) + { + sal_Int16 n = p->GetMatchingLevel( rFrom ); + if( n != INV_MATCHLEV ) + { + if( n ) + { // only first match for partial equality rulz a little bit more + pFrom = p; + nLevelFrom = n; + } + else + { // ... but exact match rulz most + pFrom = p; + bSearchFrom = sal_False; + nLevelFrom = n; + } + } + } + + if( bSearchTo ) + { + sal_Int16 n = p->GetMatchingLevel( rTo ); + if( n != INV_MATCHLEV ) + { + if( n ) + { // only first match for partial equality rulz a little bit more + pTo = p; + nLevelTo = n; + } + else + { // ... but exact match rulz most + pTo = p; + bSearchTo = sal_False; + nLevelTo = n; + } + } + } + + p = Next(); + } + + if( pFrom && pTo ) + return pFrom->Convert( fVal, *pTo, nLevelFrom, nLevelTo ); + else + THROW_IAE; +} + diff --git a/scaddins/source/analysis/analysishelper.hxx b/scaddins/source/analysis/analysishelper.hxx new file mode 100644 index 000000000000..4acd5acd4b43 --- /dev/null +++ b/scaddins/source/analysis/analysishelper.hxx @@ -0,0 +1,697 @@ +/************************************************************************* + * + * $RCSfile: analysishelper.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: gt $ $Date: 2001-04-06 13:59:16 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef ANALYSISHELPER_HXX +#define ANALYSISHELPER_HXX + + +#include +#include +#include +#include +#include + +#include +//#include +//#include + +#include "analysisdefs.hxx" +//#include "analysis_solmath.hxx" + + +using namespace com::sun::star; +using namespace rtl; + + +class SortedIndividualInt32List; + + +#define PI 3.1415926535897932 +#define PI_2 (PI/2.0) +//#define EULER 2.7182818284590452 +#define EOL ( ( const sal_Char* ) 1 ) +#define EOE ( ( const sal_Char* ) 2 ) + + +double _Test( sal_Int32 nMode, double f1, double f2, double f3 ); +inline sal_Bool IsLeapYear( sal_uInt16 nYear ); +sal_uInt16 DaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear ); +sal_uInt16 DaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear, sal_Bool bLeapYear ); +sal_Int32 DateToDays( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear ); +void DaysToDate( sal_Int32 nDays, sal_uInt16& rDay, sal_uInt16& rMonth, sal_uInt16& rYear ); +sal_Int32 GetNullDate( const REF( beans::XPropertySet )& xOptions ) THROWDEF_RTE; +sal_Int32 GetDiffDate360( + sal_uInt16 nDay1, sal_uInt16 nMonth1, sal_uInt16 nYear1, sal_Bool bLeapYear1, + sal_uInt16 nDay2, sal_uInt16 nMonth2, sal_uInt16 nYear2, + sal_Bool bUSAMethod ); +sal_Int32 GetDaysInYears( sal_uInt16 nYear1, sal_uInt16 nYear2 ); +inline sal_Int16 GetDayOfWeek( sal_Int32 nDate ); +double Fak( sal_Int32 n ); +double GetGcd( double f1, double f2 ); +double GammaHelp( double& x, sal_Bool& bReflect ); +double Gamma( double f ); +double GammaN( double f, sal_uInt32 nIter ); +double Bessel( double fNum, sal_Int32 nOrder, sal_Bool bModfied ) THROWDEF_RTE; +double BesselR( double fNum, double fOrder ) THROWDEF_RTE; +double ConvertToDec( const STRING& rFromNum, sal_uInt16 nBaseFrom, sal_uInt16 nCharLim ) THROWDEF_RTE_IAE; +STRING ConvertFromDec( + sal_Int64 nNum, sal_Int64 nMin, sal_Int64 nMax, sal_uInt16 nBase, + sal_Int32 nPlaces, sal_Int32 nMaxPlaces ) THROWDEF_RTE_IAE; +double Erf( double fX ); +sal_Bool ParseDouble( const sal_Unicode*& rpDoubleAsString, double& rReturn ); +STRING GetString( double fNumber, sal_Bool bLeadingSign = sal_False, sal_uInt16 nMaxNumOfDigits = 15 ); +inline double Exp10( sal_Int16 nPower ); // 10 ^ nPower + + + + +class List +{ +private: + static const sal_uInt32 nStartSize; + static const sal_uInt32 nIncrSize; + + void** pData; // pointer array + sal_uInt32 nSize; // array size + sal_uInt32 nNew; // next index to be inserted at + sal_uInt32 nAct; // actual for iterations + + void _Grow( void ); + inline void Grow( void ); +protected: +public: + List( void ); + virtual ~List(); + + inline const void* GetObject( sal_uInt32 nIndex ) const; + inline const void* First( void ); + inline const void* Next( void ); + + inline void Append( void* pNewElement ); + void Insert( void* pNewLement, sal_uInt32 nPlace ); + + inline sal_uInt32 Count( void ) const; +}; + + + + +class FuncData +{ +public: + const sal_Char* pIntName; + const sal_Char* pGerman; + const sal_Char* pEnglish; + const sal_Char* pDescr; +private: + const sal_Char** ppParam; // list with naming of the parameters + sal_uInt32 nParam; // len of ~ + const sal_Char** ppParamDescr; // list with description the parameters + sal_uInt32 nParamDescr; // len of ~ + +public: + FuncData( void ); + virtual ~FuncData(); + static FuncData* CloneFromList( const sal_Char**& rppStringList ); + // returns the first ** to first string after actual readed + + const sal_Char* GetParam( sal_uInt32 nInd ) const; + const sal_Char* GetParamDescr( sal_uInt32 nInd ) const; +}; + + + + +class CStrList : private List +{ +public: + inline void Append( const sal_Char* pNew ); + inline const sal_Char* Get( sal_uInt32 nIndex ) const; + List::Count; +}; + + + + +class FuncDataList : private List +{ + OUString aLastName; + sal_uInt32 nLast; +public: + FuncDataList( const sal_Char** pFuncDatas ); + virtual ~FuncDataList(); + inline void Append( FuncData* pNew ); + inline const FuncData* Get( sal_uInt32 nIndex ) const; + List::Count; + +// AnalysisFunc GetFunc( const OUString& aProgrammaticName ) const; + const FuncData* Get( const OUString& aProgrammaticName ) const; +}; + + + + +class SortedIndividualInt32List : private List +{ + // sorted list were values are unique +private: +protected: +public: + SortedIndividualInt32List(); + virtual ~SortedIndividualInt32List(); + + void Insert( sal_Int32 nNewVal ); + + List::Count; + + inline sal_Int32 Get( sal_uInt32 nIndex ) const; // reterns a value in every situation, + // even if nIndex is invalid, + // so care about nIndex _before_ using Get() + + sal_Int32 CountCondition( sal_Int32 nMinVal, sal_Int32 nMaxVal ) const; + // count number of elements, which are in the range + // of nMinVal ... nMaxVal (both included) + sal_Bool Find( sal_Int32 nVal ) const; + + void InsertHolidayList( + const SEQSEQ( sal_Int32 )& aHDay, + sal_Int32 nNullDate, sal_Bool bInsertAlsoOnWeekends ); +}; + + + + +class DoubleList : protected List +{ +protected: + inline void _Append( double fVal ); +public: + virtual ~DoubleList(); + + + inline const double* Get( sal_uInt32 nIndex ) const; + inline const double* First( void ); + inline const double* Next( void ); + + List::Count; + + inline sal_Bool Append( double fVal ); + sal_Bool Append( const SEQSEQ( double )& aValList ); + // return = FALSE if one or more values don't match IsValid() + // but, even if an error occur, the list might be changed! + virtual sal_Bool IsProper( double fVal ) const; + virtual sal_Bool IsFaulty( double fVal ) const; +}; + + + + +class ChkDoubleList1 : public DoubleList +{ +public: + virtual sal_Bool IsProper( double fVal ) const; + virtual sal_Bool IsFaulty( double fVal ) const; +}; + + + + +class Complex +{ + double r; + double i; + +public: +// inline Complex( void ); + inline Complex( double fReal, double fImag = 0.0 ); + inline Complex( const Complex& rCopy ); + Complex( const STRING& rComplexAsString ) THROWDEF_RTE_IAE; + + static sal_Bool ParseString( const STRING& rComplexAsString, Complex& rReturn ); + STRING GetString( sal_Bool bUse_i = sal_True ) const; + + inline double Real( void ) const; + inline double Imag( void ) const; + + double Arg( void ) const THROWDEF_RTE_IAE; + inline double Abs( void ) const; + + // following functions change the complex number itself to avoid unnecessary copy actions! + void Power( double fPower ) THROWDEF_RTE_IAE; + void Sin( void ) THROWDEF_RTE_IAE; + void Cos( void ) THROWDEF_RTE_IAE; + void Div( const Complex& rDivisor ) THROWDEF_RTE_IAE; + void Exp( void ); + inline void Conjugate( void ); + void Ln( void ) THROWDEF_RTE_IAE; + void Log10( void ) THROWDEF_RTE_IAE; + void Log2( void ) THROWDEF_RTE_IAE; + inline void Mult( double fFact ); + inline void Mult( const Complex& rMult ); + inline void Sub( const Complex& rMult ); + inline void Add( const Complex& rAdd ); +}; + + + + +class ComplexList : protected List +{ +public: + virtual ~ComplexList(); + + inline const Complex* Get( sal_uInt32 nIndex ) const; + inline const Complex* First( void ); + inline const Complex* Next( void ); + + List::Count; + + inline void Append( Complex* pNew ); + void Append( const SEQSEQ( STRING )& rComplexNumList ) THROWDEF_RTE_IAE; +}; + + + + +enum ConvertDataClass +{ + CDC_Mass, CDC_Length, CDC_Time, CDC_Pressure, CDC_Force, CDC_Energy, CDC_Power, CDC_Magnetism, + CDC_Temperature, CDC_Volume, CDC_Area, CDC_Speed +}; + + +#define INV_MATCHLEV 1764 // guess, what this is... :-) + + +class ConvertDataList; + + + + +class ConvertData +{ +protected: + friend ConvertDataList; + double fConst; + STRING aName; + ConvertDataClass eClass; +public: + ConvertData( + const sal_Char pUnitName[], + double fConvertConstant, + ConvertDataClass eClass ); + + sal_Int16 GetMatchingLevel( const STRING& rRef ) const; + // 0.0 = no equality + // 1.0 = matches exact + // rest = matches without an assumed prefix of one character + // rest gives power for 10 represented by the prefix (e.g. 3 for k or -9 for n + + virtual double Convert( double fVal, const ConvertData& rTo, + sal_Int16 nMatchLevelFrom, sal_Int16 nMatchLevelTo ) const THROWDEF_RTE_IAE; + // converts fVal from this unit to rFrom unit + // throws exception if not from same class + // this implementation is for proportional cases only + virtual double ConvertToBase( double fVal, sal_Int16 nMatchLevel ) const; + virtual double ConvertFromBase( double fVal, sal_Int16 nMatchLevel ) const; + + inline ConvertDataClass Class( void ) const; +}; + + + + +class ConvertDataLinear : public ConvertData +{ +protected: + double fOffs; +public: + inline ConvertDataLinear( + const sal_Char pUnitName[], + double fConvertConstant, + double fConvertOffset, + ConvertDataClass eClass ); + + virtual double Convert( double fVal, const ConvertData& rTo, + sal_Int16 nMatchLevelFrom, sal_Int16 nMatchLevelTo ) const THROWDEF_RTE_IAE; + // for cases where f(x) = a + bx applies (e.g. Temperatures) + + virtual double ConvertToBase( double fVal, sal_Int16 nMatchLevel ) const; + virtual double ConvertFromBase( double fVal, sal_Int16 nMatchLevel ) const; +}; + + + + +class ConvertDataList : protected List +{ +private: +protected: + inline ConvertData* First( void ); + inline ConvertData* Next( void ); +public: + ConvertDataList( void ); + virtual ~ConvertDataList(); + + double Convert( double fVal, const STRING& rFrom, const STRING& rTo ) THROWDEF_RTE_IAE; +}; + + + + +inline sal_Bool IsLeapYear( sal_uInt16 n ) +{ + return ( ( ( n % 4 ) == 0 ) && ( ( n % 100 ) != 0) || ( ( n % 400 ) == 0 ) ); +} + + +inline sal_Int16 GetDayOfWeek( sal_Int32 n ) +{ // monday = 0, ..., sunday = 6 + return ( n - 1 ) % 7; +} + + + + +inline void List::Grow( void ) +{ + if( nNew >= nSize ) + _Grow(); +} + + +inline const void* List::GetObject( sal_uInt32 n ) const +{ + if( n < nNew ) + return pData[ n ]; + else + return NULL; +} + + +inline const void* List::First( void ) +{ + nAct = 0; + if( nNew ) + return pData[ 0 ]; + else + return NULL; +} + + +inline const void* List::Next( void ) +{ + nAct++; + if( nAct < nNew ) + return pData[ nAct ]; + else + { + nAct--; + return NULL; + } +} + + +inline void List::Append( void* p ) +{ + Grow(); + pData[ nNew ] = p; + nNew++; +} + + +inline sal_uInt32 List::Count( void ) const +{ + return nNew; +} + + + + +inline void CStrList::Append( const sal_Char* p ) +{ +// List::Insert( ( void* ) p, LIST_APPEND ); + List::Append( ( void* ) p ); +} + + +inline const sal_Char* CStrList::Get( sal_uInt32 n ) const +{ + return ( const sal_Char* ) List::GetObject( n ); +} + + + + +inline void FuncDataList::Append( FuncData* p ) +{ +// List::Insert( p, LIST_APPEND ); + List::Append( p ); +} + + +inline const FuncData* FuncDataList::Get( sal_uInt32 n ) const +{ + return ( const FuncData* ) List::GetObject( n ); +} + + + + +inline sal_Int32 SortedIndividualInt32List::Get( sal_uInt32 n ) const +{ + return ( sal_Int32 ) List::GetObject( n ); +} + + + + +inline void DoubleList::_Append( double f ) +{ +// List::Insert( new double( f ), LIST_APPEND ); + List::Append( new double( f ) ); +} + + +inline const double* DoubleList::Get( sal_uInt32 n ) const +{ + return ( const double* ) List::GetObject( n ); +} + + +inline const double* DoubleList::First( void ) +{ + return ( const double* ) List::First(); +} + + +inline const double* DoubleList::Next( void ) +{ + return ( const double* ) List::Next(); +} + + +inline sal_Bool DoubleList::Append( double f ) +{ + if( IsFaulty( f ) ) + return sal_False; + if( IsProper( f ) ) + _Append( f ); + return sal_True; +} + + + + +/*inline Complex::Complex( void ) +{ +//#ifdef DEBUG +// SetNAN( i ); +// r = i; +//#endif +}*/ + + +inline Complex::Complex( double fReal, double fImag ) : r( fReal ), i( fImag ) +{ +} + + +inline Complex::Complex( const Complex& rCpy ) : r( rCpy.r ), i( rCpy.i ) +{ +} + + +inline double Complex::Real( void ) const +{ + return r; +} + + +inline double Complex::Imag( void ) const +{ + return i; +} + + +inline double Complex::Abs( void ) const +{ + return sqrt( r * r + i * i ); +} + + +void Complex::Conjugate( void ) +{ + i = -i; +} + + +inline void Complex::Mult( double f ) +{ + i *= f; + r *= f; +} + + +inline void Complex::Mult( const Complex& rM ) +{ + double r_ = r; + double i_ = i; + + r = r_ * rM.r - i_ * rM.i; + i = r_ * rM.i + i_ * rM.r; +} + + +inline void Complex::Sub( const Complex& rC ) +{ + r -= rC.r; + i -= rC.i; +} + + +inline void Complex::Add( const Complex& rAdd ) +{ + r += rAdd.r; + i += rAdd.i; +} + + + + +inline const Complex* ComplexList::Get( sal_uInt32 n ) const +{ + return ( const Complex* ) List::GetObject( n ); +} + + +inline const Complex* ComplexList::First( void ) +{ + return ( const Complex* ) List::First(); +} + + +inline const Complex* ComplexList::Next( void ) +{ + return ( const Complex* ) List::Next(); +} + + +inline void ComplexList::Append( Complex* p ) +{ +// List::Insert( p, LIST_APPEND ); + List::Append( p ); +} + + + + +inline ConvertDataClass ConvertData::Class( void ) const +{ + return eClass; +} + + + + +inline ConvertDataLinear::ConvertDataLinear( const sal_Char* p, double fC, double fO, ConvertDataClass e ) : + ConvertData( p, fC, e ), + fOffs( fO ) +{ +} + + + + +inline ConvertData* ConvertDataList::First( void ) +{ + return ( ConvertData* ) List::First(); +} + + +inline ConvertData* ConvertDataList::Next( void ) +{ + return ( ConvertData* ) List::Next(); +} + + +#endif + diff --git a/scaddins/source/analysis/makefile.mk b/scaddins/source/analysis/makefile.mk new file mode 100644 index 000000000000..4c0f9e2c281a --- /dev/null +++ b/scaddins/source/analysis/makefile.mk @@ -0,0 +1,144 @@ +#************************************************************************** +# +# $Header: /zpool/svn/migration/cvs_rep_09_09_08/code/scaddins/source/analysis/makefile.mk,v 1.1 2001-04-06 13:59:16 gt Exp $ +# +# $Date: 2001-04-06 13:59:16 $ +# $Author: gt $ +# $Revision: 1.1 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +#************************************************************************** + +PRJ=..$/.. +PRJNAME=addin + +TARGET=analysis + + +ENABLE_EXCEPTIONS=TRUE +USE_DEFFILE=TRUE +LIBTARGET=NO + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Types ------------------------------------- + +UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb $(BIN)$/analysisadd.rdb +UNOUCRDEP=$(UNOUCRRDB) + +UNOUCROUT=$(OUT)$/inc$/$(PRJNAME)$/$(TARGET) +INCPRE+=$(UNOUCROUT) + +# --- Types ------------------------------------- + +# comprehensive type info, so rdb needn't be installed +CPPUMAKERFLAGS*=-C + +UNOTYPES=\ + com.sun.star.sheet.addin.XAnalysis \ + com.sun.star.lang.XComponent \ + com.sun.star.lang.XMultiServiceFactory \ + com.sun.star.lang.XSingleServiceFactory \ + com.sun.star.uno.TypeClass \ + com.sun.star.uno.XInterface \ + com.sun.star.registry.XImplementationRegistration \ + com.sun.star.sheet.XAddIn \ + com.sun.star.lang.XServiceName \ + com.sun.star.lang.XServiceInfo \ + com.sun.star.lang.XTypeProvider \ + com.sun.star.uno.XWeak \ + com.sun.star.uno.XAggregation \ + com.sun.star.util.Date + +# --- Files ------------------------------------- + +SLOFILES=\ + $(SLO)$/analysis.obj \ + $(SLO)$/analysishelper.obj + +# SCO and MACOSX: the linker does know about weak symbols, but we can't ignore multiple defined symbols +.IF "$(OS)"=="SCO" || "$(OS)$(COM)"=="OS2GCC" || "$(OS)"=="MACOSX" +SLOFILES+=$(SLO)$/staticmb.obj +.ENDIF + +ALLIDLFILES=\ + analysisadd.idl + +# --- Library ----------------------------------- + +SHL1TARGET=$(TARGET)$(UPD)$(DLLPOSTFIX) +SHL1OBJS=$(SLOFILES) +SHL1STDLIBS= \ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(VOSLIB) \ + $(TOOLSLIB) \ + $(SALLIB) + +SHL1DEPN=makefile.mk +SHL1DEF=$(MISC)$/$(SHL1TARGET).def +DEF1NAME=$(SHL1TARGET) +DEF1EXPORTFILE=exports.dxp + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + +$(BIN)$/analysisadd.rdb: $(ALLIDLFILES) + +unoidl -I$(PRJ) -I$(SOLARIDLDIR) -Burd -OH$(BIN) $? + +regmerge $@ /UCR $(BIN)$/{$(?:f:s/.idl/.urd/)} + touch $@ + +