LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/scaddins/source/pricing - pricing.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 55 56 98.2 %
Date: 2013-07-09 Functions: 32 32 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : //------------------------------------------------------------------
      21             : //
      22             : // option pricing functions add in
      23             : //
      24             : // most parts of this files are technical UNO details which are
      25             : // all copied from ../datefunc/datefunc.hxx
      26             : // to avoid having to rename all classes to do with UNO
      27             : // technicalities we use our own namespace
      28             : //
      29             : //------------------------------------------------------------------
      30             : 
      31             : #ifndef _SCA_PRICING_HXX
      32             : #define _SCA_PRICING_HXX
      33             : 
      34             : 
      35             : #include <string.h>
      36             : #include <com/sun/star/lang/XServiceName.hpp>
      37             : #include <com/sun/star/lang/XServiceInfo.hpp>
      38             : #include <com/sun/star/sheet/XAddIn.hpp>
      39             : #include <com/sun/star/sheet/XCompatibilityNames.hpp>
      40             : #include <com/sun/star/sheet/addin/XPricingFunctions.hpp>
      41             : #include <cppuhelper/implbase5.hxx>             // helper for implementations
      42             : #include <tools/resid.hxx>
      43             : #include <tools/rc.hxx>
      44             : #include <tools/resary.hxx>
      45             : 
      46             : #define RETURN_FINITE(d)    if( ::rtl::math::isFinite( d ) ) return d; else throw css::lang::IllegalArgumentException()
      47             : 
      48             : 
      49             : 
      50             : //------------------------------------------------------------------
      51             : 
      52             : namespace sca {
      53             : namespace pricing {
      54             : 
      55             : class ScaList
      56             : {
      57             : private:
      58             :     static const sal_uInt32     nStartSize;
      59             :     static const sal_uInt32     nIncrSize;
      60             : 
      61             :     void**                      pData;          // pointer array
      62             :     sal_uInt32                  nSize;          // array size
      63             :     sal_uInt32                  nCount;         // next index to be inserted at
      64             :     sal_uInt32                  nCurr;          // current pos for iterations
      65             : 
      66             :     void                        _Grow();
      67             :     inline void                 Grow();
      68             : 
      69             : public:
      70             :                                 ScaList();
      71             :     virtual                     ~ScaList();
      72             : 
      73          54 :     inline sal_uInt32           Count() const       { return nCount; }
      74             : 
      75         390 :     inline const void*          GetObject( sal_uInt32 nIndex ) const
      76         390 :                                     { return (nIndex < nCount) ? pData[ nIndex ] : NULL; }
      77             : 
      78          20 :     inline void*                First() { return nCount ? pData[ nCurr = 0 ] : NULL; }
      79          32 :     inline void*                Next()  { return (nCurr + 1 < nCount) ? pData[ ++nCurr ] : NULL; }
      80             : 
      81             :     inline void                 Append( void* pNew );
      82             : };
      83             : 
      84             : 
      85          32 : inline void ScaList::Grow()
      86             : {
      87          32 :     if( nCount >= nSize )
      88           0 :         _Grow();
      89          32 : }
      90             : 
      91          32 : inline void ScaList::Append( void* pNew )
      92             : {
      93          32 :     Grow();
      94          32 :     pData[ nCount++ ] = pNew;
      95          32 : }
      96             : 
      97             : 
      98             : //------------------------------------------------------------------
      99             : 
     100             : class ScaStringList : protected ScaList
     101             : {
     102             : public:
     103          16 :     inline                      ScaStringList() : ScaList() {};
     104             :     virtual                     ~ScaStringList();
     105             : 
     106             :                                 using ScaList::Count;
     107             : 
     108             :     inline const OUString* Get( sal_uInt32 nIndex ) const;
     109             : 
     110             :     inline OUString*     First();
     111             :     inline OUString*     Next();
     112             : 
     113             :     using ScaList::Append;
     114             :     inline void                 Append( OUString* pNew );
     115             :     inline void                 Append( const OUString& rNew );
     116             : };
     117             : 
     118             : 
     119           4 : inline const OUString* ScaStringList::Get( sal_uInt32 nIndex ) const
     120             : {
     121           4 :     return static_cast< const OUString* >( ScaList::GetObject( nIndex ) );
     122             : }
     123             : 
     124          16 : inline OUString* ScaStringList::First()
     125             : {
     126          16 :     return static_cast< OUString* >( ScaList::First() );
     127             : }
     128             : 
     129          16 : inline OUString* ScaStringList::Next()
     130             : {
     131          16 :     return static_cast< OUString* >( ScaList::Next() );
     132             : }
     133             : 
     134             : inline void ScaStringList::Append( OUString* pNew )
     135             : {
     136             :     ScaList::Append( pNew );
     137             : }
     138             : 
     139          16 : inline void ScaStringList::Append( const OUString& rNew )
     140             : {
     141          16 :     ScaList::Append( new OUString( rNew ) );
     142          16 : }
     143             : 
     144             : 
     145             : //------------------------------------------------------------------
     146             : 
     147             : class ScaResId : public ResId
     148             : {
     149             : public:
     150             :                                 ScaResId( sal_uInt16 nResId, ResMgr& rResMgr );
     151             : };
     152             : 
     153             : 
     154             : //------------------------------------------------------------------
     155             : 
     156          16 : class ScaResStringLoader : public Resource
     157             : {
     158             : private:
     159             :     String                      aStr;
     160             : 
     161             : public:
     162             :     inline                      ScaResStringLoader( sal_uInt16 nResId, sal_uInt16 nStrId, ResMgr& rResMgr );
     163             : 
     164          16 :     inline const String&        GetString() const   { return aStr; }
     165             : 
     166             : };
     167             : 
     168             : 
     169          16 : inline ScaResStringLoader::ScaResStringLoader( sal_uInt16 nResId, sal_uInt16 nStrId, ResMgr& rResMgr ) :
     170             :     Resource( ScaResId( nResId, rResMgr ) ),
     171          16 :     aStr( ScaResId( nStrId, rResMgr ) )
     172             : {
     173          16 :     FreeResource();
     174          16 : }
     175             : 
     176             : 
     177             : //------------------------------------------------------------------
     178             : 
     179          16 : class ScaResStringArrLoader : public Resource
     180             : {
     181             : private:
     182             :     ResStringArray              aStrArray;
     183             : 
     184             : public:
     185             :     inline                      ScaResStringArrLoader( sal_uInt16 nResId, sal_uInt16 nArrayId, ResMgr& rResMgr );
     186             : 
     187          16 :     inline const ResStringArray& GetStringArray() const { return aStrArray; }
     188             : };
     189             : 
     190             : 
     191             : 
     192          16 : inline ScaResStringArrLoader::ScaResStringArrLoader( sal_uInt16 nResId, sal_uInt16 nArrayId, ResMgr& rResMgr ) :
     193             :     Resource( ScaResId( nResId, rResMgr ) ),
     194          16 :     aStrArray( ScaResId( nArrayId, rResMgr ) )
     195             : {
     196          16 :     FreeResource();
     197          16 : }
     198             : 
     199             : 
     200             : //------------------------------------------------------------------
     201             : 
     202         320 : class ScaResPublisher : public Resource
     203             : {
     204             : public:
     205         320 :     inline                      ScaResPublisher( const ScaResId& rResId ) : Resource( rResId ) {}
     206             : 
     207         320 :     inline sal_Bool             IsAvailableRes( const ResId& rResId ) const
     208         320 :                                     { return Resource::IsAvailableRes( rResId ); }
     209         320 :     inline void                 FreeResource()
     210         320 :                                     { Resource::FreeResource(); }
     211             : };
     212             : 
     213             : 
     214             : //------------------------------------------------------------------
     215             : 
     216         320 : class ScaFuncRes : public Resource
     217             : {
     218             : public:
     219             :                                 ScaFuncRes( ResId& rResId, ResMgr& rResMgr, sal_uInt16 nIndex, OUString& rRet );
     220             : };
     221             : 
     222             : 
     223             : //------------------------------------------------------------------
     224             : 
     225             : enum ScaCategory
     226             : {
     227             :     ScaCat_AddIn,
     228             :     ScaCat_DateTime,
     229             :     ScaCat_Text,
     230             :     ScaCat_Finance,
     231             :     ScaCat_Inf,
     232             :     ScaCat_Math,
     233             :     ScaCat_Tech
     234             : };
     235             : 
     236             : struct ScaFuncDataBase
     237             : {
     238             :     const sal_Char*             pIntName;           // internal name (get***)
     239             :     sal_uInt16                  nUINameID;          // resource ID to UI name
     240             :     sal_uInt16                  nDescrID;           // resource ID to description, parameter names and ~ description
     241             :     sal_uInt16                  nCompListID;        // resource ID to list of valid names
     242             :     sal_uInt16                  nParamCount;        // number of named / described parameters
     243             :     ScaCategory                 eCat;               // function category
     244             :     sal_Bool                    bDouble;            // name already exist in Calc
     245             :     sal_Bool                    bWithOpt;           // first parameter is internal
     246             : };
     247             : 
     248             : class ScaFuncData
     249             : {
     250             : private:
     251             :     OUString             aIntName;           // internal name (get***)
     252             :     sal_uInt16                  nUINameID;          // resource ID to UI name
     253             :     sal_uInt16                  nDescrID;           // leads also to parameter descriptions!
     254             :     sal_uInt16                  nCompListID;        // resource ID to list of valid names
     255             :     sal_uInt16                  nParamCount;        // num of parameters
     256             :     ScaStringList               aCompList;          // list of all valid names
     257             :     ScaCategory                 eCat;               // function category
     258             :     sal_Bool                    bDouble;            // name already exist in Calc
     259             :     sal_Bool                    bWithOpt;           // first parameter is internal
     260             : 
     261             : public:
     262             :                                 ScaFuncData( const ScaFuncDataBase& rBaseData, ResMgr& rRscMgr );
     263             :     virtual                     ~ScaFuncData();
     264             : 
     265          16 :     inline sal_uInt16           GetUINameID() const     { return nUINameID; }
     266         320 :     inline sal_uInt16           GetDescrID() const      { return nDescrID; }
     267          16 :     inline ScaCategory          GetCategory() const     { return eCat; }
     268          16 :     inline sal_Bool             IsDouble() const        { return bDouble; }
     269             :     inline sal_Bool             HasIntParam() const     { return bWithOpt; }
     270             : 
     271             :     sal_uInt16                  GetStrIndex( sal_uInt16 nParam ) const;
     272          50 :     inline sal_Bool             Is( const OUString& rCompare ) const
     273          50 :                                                     { return aIntName == rCompare; }
     274             : 
     275           4 :     inline const ScaStringList& GetCompNameList() const { return aCompList; }
     276             : };
     277             : 
     278             : 
     279             : //------------------------------------------------------------------
     280             : 
     281             : class ScaFuncDataList : private ScaList
     282             : {
     283             :     OUString             aLastName;
     284             :     sal_uInt32                  nLast;
     285             : 
     286             : public:
     287             :                                 ScaFuncDataList( ResMgr& rResMgr );
     288             :     virtual                     ~ScaFuncDataList();
     289             : 
     290             :                                 using ScaList::Count;
     291             : 
     292             :     inline const ScaFuncData*   Get( sal_uInt32 nIndex ) const;
     293             :     const ScaFuncData*          Get( const OUString& rProgrammaticName ) const;
     294             :     inline ScaFuncData*         First();
     295             :     inline ScaFuncData*         Next();
     296             : 
     297             :     using ScaList::Append;
     298          16 :     inline void                 Append( ScaFuncData* pNew ) { ScaList::Append( pNew ); }
     299             : };
     300             : 
     301             : 
     302         386 : inline const ScaFuncData* ScaFuncDataList::Get( sal_uInt32 nIndex ) const
     303             : {
     304         386 :     return static_cast< const ScaFuncData* >( ScaList::GetObject( nIndex ) );
     305             : }
     306             : 
     307           4 : inline ScaFuncData* ScaFuncDataList::First()
     308             : {
     309           4 :     return static_cast< ScaFuncData* >( ScaList::First() );
     310             : }
     311             : 
     312          16 : inline ScaFuncData* ScaFuncDataList::Next()
     313             : {
     314          16 :     return static_cast< ScaFuncData* >( ScaList::Next() );
     315             : }
     316             : 
     317             : } // namespace pricing
     318             : } // namespace sca
     319             : 
     320             : 
     321             : 
     322             : //------------------------------------------------------------------
     323             : //------------------------------------------------------------------
     324             : 
     325             : css::uno::Reference< css::uno::XInterface > SAL_CALL PricingFunctionAddIn_CreateInstance(
     326             :     const css::uno::Reference< css::lang::XMultiServiceFactory >& );
     327             : 
     328             : 
     329             : // AddIn class for pricing functions
     330             : 
     331             : class ScaPricingAddIn : public ::cppu::WeakImplHelper5<
     332             :                                 css::sheet::XAddIn,
     333             :                                 css::sheet::XCompatibilityNames,
     334             :                                 css::sheet::addin::XPricingFunctions,
     335             :                                 css::lang::XServiceName,
     336             :                                 css::lang::XServiceInfo >
     337             : {
     338             : private:
     339             :     css::lang::Locale  aFuncLoc;
     340             :     css::lang::Locale* pDefLocales;
     341             :     ResMgr*                     pResMgr;
     342             :     sca::pricing::ScaFuncDataList*            pFuncDataList;
     343             : 
     344             : 
     345             :     void                        InitDefLocales();
     346             :     const css::lang::Locale& GetLocale( sal_uInt32 nIndex );
     347             :     ResMgr&                     GetResMgr() throw( css::uno::RuntimeException );
     348             :     void                        InitData();
     349             : 
     350             :     OUString             GetDisplFuncStr( sal_uInt16 nResId ) throw( css::uno::RuntimeException );
     351             :     OUString             GetFuncDescrStr( sal_uInt16 nResId, sal_uInt16 nStrIndex ) throw( css::uno::RuntimeException );
     352             : 
     353             : public:
     354             :                                 ScaPricingAddIn();
     355             :     virtual                     ~ScaPricingAddIn();
     356             : 
     357             :     static OUString      getImplementationName_Static();
     358             :     static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
     359             : 
     360             :                                 // XAddIn
     361             :     virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) throw( css::uno::RuntimeException );
     362             :     virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) throw( css::uno::RuntimeException );
     363             :     virtual OUString SAL_CALL getFunctionDescription( const OUString& aProgrammaticName ) throw( css::uno::RuntimeException );
     364             :     virtual OUString SAL_CALL getDisplayArgumentName( const OUString& aProgrammaticName, sal_Int32 nArgument ) throw( css::uno::RuntimeException );
     365             :     virtual OUString SAL_CALL getArgumentDescription( const OUString& aProgrammaticName, sal_Int32 nArgument ) throw( css::uno::RuntimeException );
     366             :     virtual OUString SAL_CALL getProgrammaticCategoryName( const OUString& aProgrammaticName ) throw( css::uno::RuntimeException );
     367             :     virtual OUString SAL_CALL getDisplayCategoryName( const OUString& aProgrammaticName ) throw( css::uno::RuntimeException );
     368             : 
     369             :                                 // XCompatibilityNames
     370             :     virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames( const OUString& aProgrammaticName ) throw( css::uno::RuntimeException );
     371             : 
     372             :                                 // XLocalizable
     373             :     virtual void SAL_CALL       setLocale( const css::lang::Locale& eLocale ) throw( css::uno::RuntimeException );
     374             :     virtual css::lang::Locale SAL_CALL getLocale() throw( css::uno::RuntimeException );
     375             : 
     376             :                                 // XServiceName
     377             :     virtual OUString SAL_CALL getServiceName() throw( css::uno::RuntimeException );
     378             : 
     379             :                                 // XServiceInfo
     380             :     virtual OUString SAL_CALL getImplementationName() throw( css::uno::RuntimeException );
     381             :     virtual sal_Bool SAL_CALL   supportsService( const OUString& ServiceName ) throw( css::uno::RuntimeException );
     382             :     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw( css::uno::RuntimeException );
     383             : 
     384             :     // ----------------------------------------
     385             :     //  methods from own interfaces start here
     386             :     // ----------------------------------------
     387             : 
     388             :     virtual double SAL_CALL getOptBarrier( double spot, double vol,
     389             :             double r, double rf, double T, double strike,
     390             :             double barrier_low, double barrier_up, double rebate,
     391             :             const OUString& put_call, const OUString& in_out,
     392             :             const OUString& continuous, const css::uno::Any& greek ) throw( css::uno::RuntimeException, css::lang::IllegalArgumentException );
     393             : 
     394             :    virtual double SAL_CALL getOptTouch( double spot, double vol,
     395             :             double r, double rf, double T,
     396             :             double barrier_low, double barrier_up,
     397             :             const OUString& for_dom, const OUString& in_out,
     398             :             const OUString& barriercont, const css::uno::Any& greekstr ) throw( css::uno::RuntimeException, css::lang::IllegalArgumentException );
     399             : 
     400             :    virtual double SAL_CALL getOptProbHit( double spot, double vol,
     401             :             double mu, double T,
     402             :             double barrier_low, double barrier_up ) throw( css::uno::RuntimeException, css::lang::IllegalArgumentException );
     403             : 
     404             :    virtual double SAL_CALL getOptProbInMoney( double spot, double vol,
     405             :             double mu, double T,
     406             :             double barrier_low, double barrier_up,
     407             :             const css::uno::Any& strikeval, const css::uno::Any& put_call ) throw( css::uno::RuntimeException, css::lang::IllegalArgumentException );
     408             : 
     409             : };
     410             : //------------------------------------------------------------------
     411             : 
     412             : #endif
     413             : 
     414             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10