LCOV - code coverage report
Current view: top level - libreoffice/scaddins/source/pricing - pricing.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 56 0.0 %
Date: 2012-12-27 Functions: 0 32 0.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 ANY                 ::com::sun::star::uno::Any
      47             : #define STRING              ::rtl::OUString
      48             : #define THROWDEF_RTE_IAE    throw(::com::sun::star::uno::RuntimeException,::com::sun::star::lang::IllegalArgumentException)
      49             : #define THROW_IAE           throw ::com::sun::star::lang::IllegalArgumentException()
      50             : #define RETURN_FINITE(d)    if( ::rtl::math::isFinite( d ) ) return d; else THROW_IAE
      51             : 
      52             : 
      53             : 
      54             : //------------------------------------------------------------------
      55             : 
      56             : namespace sca {
      57             : namespace pricing {
      58             : 
      59             : class ScaList
      60             : {
      61             : private:
      62             :     static const sal_uInt32     nStartSize;
      63             :     static const sal_uInt32     nIncrSize;
      64             : 
      65             :     void**                      pData;          // pointer array
      66             :     sal_uInt32                  nSize;          // array size
      67             :     sal_uInt32                  nCount;         // next index to be inserted at
      68             :     sal_uInt32                  nCurr;          // current pos for iterations
      69             : 
      70             :     void                        _Grow();
      71             :     inline void                 Grow();
      72             : 
      73             : public:
      74             :                                 ScaList();
      75             :     virtual                     ~ScaList();
      76             : 
      77           0 :     inline sal_uInt32           Count() const       { return nCount; }
      78             : 
      79           0 :     inline const void*          GetObject( sal_uInt32 nIndex ) const
      80           0 :                                     { return (nIndex < nCount) ? pData[ nIndex ] : NULL; }
      81             : 
      82           0 :     inline void*                First() { return nCount ? pData[ nCurr = 0 ] : NULL; }
      83           0 :     inline void*                Next()  { return (nCurr + 1 < nCount) ? pData[ ++nCurr ] : NULL; }
      84             : 
      85             :     inline void                 Append( void* pNew );
      86             : };
      87             : 
      88             : 
      89           0 : inline void ScaList::Grow()
      90             : {
      91           0 :     if( nCount >= nSize )
      92           0 :         _Grow();
      93           0 : }
      94             : 
      95           0 : inline void ScaList::Append( void* pNew )
      96             : {
      97           0 :     Grow();
      98           0 :     pData[ nCount++ ] = pNew;
      99           0 : }
     100             : 
     101             : 
     102             : //------------------------------------------------------------------
     103             : 
     104             : class ScaStringList : protected ScaList
     105             : {
     106             : public:
     107           0 :     inline                      ScaStringList() : ScaList() {};
     108             :     virtual                     ~ScaStringList();
     109             : 
     110             :                                 using ScaList::Count;
     111             : 
     112             :     inline const ::rtl::OUString* Get( sal_uInt32 nIndex ) const;
     113             : 
     114             :     inline ::rtl::OUString*     First();
     115             :     inline ::rtl::OUString*     Next();
     116             : 
     117             :     using ScaList::Append;
     118             :     inline void                 Append( ::rtl::OUString* pNew );
     119             :     inline void                 Append( const ::rtl::OUString& rNew );
     120             : };
     121             : 
     122             : 
     123           0 : inline const ::rtl::OUString* ScaStringList::Get( sal_uInt32 nIndex ) const
     124             : {
     125           0 :     return static_cast< const ::rtl::OUString* >( ScaList::GetObject( nIndex ) );
     126             : }
     127             : 
     128           0 : inline ::rtl::OUString* ScaStringList::First()
     129             : {
     130           0 :     return static_cast< ::rtl::OUString* >( ScaList::First() );
     131             : }
     132             : 
     133           0 : inline ::rtl::OUString* ScaStringList::Next()
     134             : {
     135           0 :     return static_cast< ::rtl::OUString* >( ScaList::Next() );
     136             : }
     137             : 
     138             : inline void ScaStringList::Append( ::rtl::OUString* pNew )
     139             : {
     140             :     ScaList::Append( pNew );
     141             : }
     142             : 
     143           0 : inline void ScaStringList::Append( const ::rtl::OUString& rNew )
     144             : {
     145           0 :     ScaList::Append( new ::rtl::OUString( rNew ) );
     146           0 : }
     147             : 
     148             : 
     149             : //------------------------------------------------------------------
     150             : 
     151             : class ScaResId : public ResId
     152             : {
     153             : public:
     154             :                                 ScaResId( sal_uInt16 nResId, ResMgr& rResMgr );
     155             : };
     156             : 
     157             : 
     158             : //------------------------------------------------------------------
     159             : 
     160           0 : class ScaResStringLoader : public Resource
     161             : {
     162             : private:
     163             :     String                      aStr;
     164             : 
     165             : public:
     166             :     inline                      ScaResStringLoader( sal_uInt16 nResId, sal_uInt16 nStrId, ResMgr& rResMgr );
     167             : 
     168           0 :     inline const String&        GetString() const   { return aStr; }
     169             : 
     170             : };
     171             : 
     172             : 
     173           0 : inline ScaResStringLoader::ScaResStringLoader( sal_uInt16 nResId, sal_uInt16 nStrId, ResMgr& rResMgr ) :
     174             :     Resource( ScaResId( nResId, rResMgr ) ),
     175           0 :     aStr( ScaResId( nStrId, rResMgr ) )
     176             : {
     177           0 :     FreeResource();
     178           0 : }
     179             : 
     180             : 
     181             : //------------------------------------------------------------------
     182             : 
     183           0 : class ScaResStringArrLoader : public Resource
     184             : {
     185             : private:
     186             :     ResStringArray              aStrArray;
     187             : 
     188             : public:
     189             :     inline                      ScaResStringArrLoader( sal_uInt16 nResId, sal_uInt16 nArrayId, ResMgr& rResMgr );
     190             : 
     191           0 :     inline const ResStringArray& GetStringArray() const { return aStrArray; }
     192             : };
     193             : 
     194             : 
     195             : 
     196           0 : inline ScaResStringArrLoader::ScaResStringArrLoader( sal_uInt16 nResId, sal_uInt16 nArrayId, ResMgr& rResMgr ) :
     197             :     Resource( ScaResId( nResId, rResMgr ) ),
     198           0 :     aStrArray( ScaResId( nArrayId, rResMgr ) )
     199             : {
     200           0 :     FreeResource();
     201           0 : }
     202             : 
     203             : 
     204             : //------------------------------------------------------------------
     205             : 
     206           0 : class ScaResPublisher : public Resource
     207             : {
     208             : public:
     209           0 :     inline                      ScaResPublisher( const ScaResId& rResId ) : Resource( rResId ) {}
     210             : 
     211           0 :     inline sal_Bool             IsAvailableRes( const ResId& rResId ) const
     212           0 :                                     { return Resource::IsAvailableRes( rResId ); }
     213           0 :     inline void                 FreeResource()
     214           0 :                                     { Resource::FreeResource(); }
     215             : };
     216             : 
     217             : 
     218             : //------------------------------------------------------------------
     219             : 
     220           0 : class ScaFuncRes : public Resource
     221             : {
     222             : public:
     223             :                                 ScaFuncRes( ResId& rResId, ResMgr& rResMgr, sal_uInt16 nIndex, ::rtl::OUString& rRet );
     224             : };
     225             : 
     226             : 
     227             : //------------------------------------------------------------------
     228             : 
     229             : enum ScaCategory
     230             : {
     231             :     ScaCat_AddIn,
     232             :     ScaCat_DateTime,
     233             :     ScaCat_Text,
     234             :     ScaCat_Finance,
     235             :     ScaCat_Inf,
     236             :     ScaCat_Math,
     237             :     ScaCat_Tech
     238             : };
     239             : 
     240             : struct ScaFuncDataBase
     241             : {
     242             :     const sal_Char*             pIntName;           // internal name (get***)
     243             :     sal_uInt16                  nUINameID;          // resource ID to UI name
     244             :     sal_uInt16                  nDescrID;           // resource ID to description, parameter names and ~ description
     245             :     sal_uInt16                  nCompListID;        // resource ID to list of valid names
     246             :     sal_uInt16                  nParamCount;        // number of named / described parameters
     247             :     ScaCategory                 eCat;               // function category
     248             :     sal_Bool                    bDouble;            // name already exist in Calc
     249             :     sal_Bool                    bWithOpt;           // first parameter is internal
     250             : };
     251             : 
     252             : class ScaFuncData
     253             : {
     254             : private:
     255             :     ::rtl::OUString             aIntName;           // internal name (get***)
     256             :     sal_uInt16                  nUINameID;          // resource ID to UI name
     257             :     sal_uInt16                  nDescrID;           // leads also to parameter descriptions!
     258             :     sal_uInt16                  nCompListID;        // resource ID to list of valid names
     259             :     sal_uInt16                  nParamCount;        // num of parameters
     260             :     ScaStringList               aCompList;          // list of all valid names
     261             :     ScaCategory                 eCat;               // function category
     262             :     sal_Bool                    bDouble;            // name already exist in Calc
     263             :     sal_Bool                    bWithOpt;           // first parameter is internal
     264             : 
     265             : public:
     266             :                                 ScaFuncData( const ScaFuncDataBase& rBaseData, ResMgr& rRscMgr );
     267             :     virtual                     ~ScaFuncData();
     268             : 
     269           0 :     inline sal_uInt16           GetUINameID() const     { return nUINameID; }
     270           0 :     inline sal_uInt16           GetDescrID() const      { return nDescrID; }
     271           0 :     inline ScaCategory          GetCategory() const     { return eCat; }
     272           0 :     inline sal_Bool             IsDouble() const        { return bDouble; }
     273             :     inline sal_Bool             HasIntParam() const     { return bWithOpt; }
     274             : 
     275             :     sal_uInt16                  GetStrIndex( sal_uInt16 nParam ) const;
     276           0 :     inline sal_Bool             Is( const ::rtl::OUString& rCompare ) const
     277           0 :                                                     { return aIntName == rCompare; }
     278             : 
     279           0 :     inline const ScaStringList& GetCompNameList() const { return aCompList; }
     280             : };
     281             : 
     282             : 
     283             : //------------------------------------------------------------------
     284             : 
     285             : class ScaFuncDataList : private ScaList
     286             : {
     287             :     ::rtl::OUString             aLastName;
     288             :     sal_uInt32                  nLast;
     289             : 
     290             : public:
     291             :                                 ScaFuncDataList( ResMgr& rResMgr );
     292             :     virtual                     ~ScaFuncDataList();
     293             : 
     294             :                                 using ScaList::Count;
     295             : 
     296             :     inline const ScaFuncData*   Get( sal_uInt32 nIndex ) const;
     297             :     const ScaFuncData*          Get( const ::rtl::OUString& rProgrammaticName ) const;
     298             :     inline ScaFuncData*         First();
     299             :     inline ScaFuncData*         Next();
     300             : 
     301             :     using ScaList::Append;
     302           0 :     inline void                 Append( ScaFuncData* pNew ) { ScaList::Append( pNew ); }
     303             : };
     304             : 
     305             : 
     306           0 : inline const ScaFuncData* ScaFuncDataList::Get( sal_uInt32 nIndex ) const
     307             : {
     308           0 :     return static_cast< const ScaFuncData* >( ScaList::GetObject( nIndex ) );
     309             : }
     310             : 
     311           0 : inline ScaFuncData* ScaFuncDataList::First()
     312             : {
     313           0 :     return static_cast< ScaFuncData* >( ScaList::First() );
     314             : }
     315             : 
     316           0 : inline ScaFuncData* ScaFuncDataList::Next()
     317             : {
     318           0 :     return static_cast< ScaFuncData* >( ScaList::Next() );
     319             : }
     320             : 
     321             : } // namespace pricing
     322             : } // namespace sca
     323             : 
     324             : 
     325             : 
     326             : //------------------------------------------------------------------
     327             : //------------------------------------------------------------------
     328             : 
     329             : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL PricingFunctionAddIn_CreateInstance(
     330             :     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& );
     331             : 
     332             : 
     333             : // AddIn class for pricing functions
     334             : 
     335             : class ScaPricingAddIn : public ::cppu::WeakImplHelper5<
     336             :                                 ::com::sun::star::sheet::XAddIn,
     337             :                                 ::com::sun::star::sheet::XCompatibilityNames,
     338             :                                 ::com::sun::star::sheet::addin::XPricingFunctions,
     339             :                                 ::com::sun::star::lang::XServiceName,
     340             :                                 ::com::sun::star::lang::XServiceInfo >
     341             : {
     342             : private:
     343             :     ::com::sun::star::lang::Locale  aFuncLoc;
     344             :     ::com::sun::star::lang::Locale* pDefLocales;
     345             :     ResMgr*                     pResMgr;
     346             :     sca::pricing::ScaFuncDataList*            pFuncDataList;
     347             : 
     348             : 
     349             :     void                        InitDefLocales();
     350             :     const ::com::sun::star::lang::Locale& GetLocale( sal_uInt32 nIndex );
     351             :     ResMgr&                     GetResMgr() throw( ::com::sun::star::uno::RuntimeException );
     352             :     void                        InitData();
     353             : 
     354             :     ::rtl::OUString             GetDisplFuncStr( sal_uInt16 nResId ) throw( ::com::sun::star::uno::RuntimeException );
     355             :     ::rtl::OUString             GetFuncDescrStr( sal_uInt16 nResId, sal_uInt16 nStrIndex ) throw( ::com::sun::star::uno::RuntimeException );
     356             : 
     357             : public:
     358             :                                 ScaPricingAddIn();
     359             :     virtual                     ~ScaPricingAddIn();
     360             : 
     361             :     static ::rtl::OUString      getImplementationName_Static();
     362             :     static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static();
     363             : 
     364             :                                 // XAddIn
     365             :     virtual ::rtl::OUString SAL_CALL getProgrammaticFuntionName( const ::rtl::OUString& aDisplayName ) throw( ::com::sun::star::uno::RuntimeException );
     366             :     virtual ::rtl::OUString SAL_CALL getDisplayFunctionName( const ::rtl::OUString& aProgrammaticName ) throw( ::com::sun::star::uno::RuntimeException );
     367             :     virtual ::rtl::OUString SAL_CALL getFunctionDescription( const ::rtl::OUString& aProgrammaticName ) throw( ::com::sun::star::uno::RuntimeException );
     368             :     virtual ::rtl::OUString SAL_CALL getDisplayArgumentName( const ::rtl::OUString& aProgrammaticName, sal_Int32 nArgument ) throw( ::com::sun::star::uno::RuntimeException );
     369             :     virtual ::rtl::OUString SAL_CALL getArgumentDescription( const ::rtl::OUString& aProgrammaticName, sal_Int32 nArgument ) throw( ::com::sun::star::uno::RuntimeException );
     370             :     virtual ::rtl::OUString SAL_CALL getProgrammaticCategoryName( const ::rtl::OUString& aProgrammaticName ) throw( ::com::sun::star::uno::RuntimeException );
     371             :     virtual ::rtl::OUString SAL_CALL getDisplayCategoryName( const ::rtl::OUString& aProgrammaticName ) throw( ::com::sun::star::uno::RuntimeException );
     372             : 
     373             :                                 // XCompatibilityNames
     374             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::LocalizedName > SAL_CALL getCompatibilityNames( const ::rtl::OUString& aProgrammaticName ) throw( ::com::sun::star::uno::RuntimeException );
     375             : 
     376             :                                 // XLocalizable
     377             :     virtual void SAL_CALL       setLocale( const ::com::sun::star::lang::Locale& eLocale ) throw( ::com::sun::star::uno::RuntimeException );
     378             :     virtual ::com::sun::star::lang::Locale SAL_CALL getLocale() throw( ::com::sun::star::uno::RuntimeException );
     379             : 
     380             :                                 // XServiceName
     381             :     virtual ::rtl::OUString SAL_CALL getServiceName() throw( ::com::sun::star::uno::RuntimeException );
     382             : 
     383             :                                 // XServiceInfo
     384             :     virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
     385             :     virtual sal_Bool SAL_CALL   supportsService( const ::rtl::OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException );
     386             :     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException );
     387             : 
     388             :     // ----------------------------------------
     389             :     //  methods from own interfaces start here
     390             :     // ----------------------------------------
     391             : 
     392             :     virtual double SAL_CALL getOptBarrier( double spot, double vol,
     393             :             double r, double rf, double T, double strike,
     394             :             double barrier_low, double barrier_up, double rebate,
     395             :             const STRING& put_call, const STRING& in_out,
     396             :             const STRING& continuous, const ANY& greek ) THROWDEF_RTE_IAE;
     397             : 
     398             :    virtual double SAL_CALL getOptTouch( double spot, double vol,
     399             :             double r, double rf, double T,
     400             :             double barrier_low, double barrier_up,
     401             :             const STRING& for_dom, const STRING& in_out,
     402             :             const STRING& barriercont, const ANY& greekstr ) THROWDEF_RTE_IAE;
     403             : 
     404             :    virtual double SAL_CALL getOptProbHit( double spot, double vol,
     405             :             double mu, double T,
     406             :             double barrier_low, double barrier_up ) THROWDEF_RTE_IAE;
     407             : 
     408             :    virtual double SAL_CALL getOptProbInMoney( double spot, double vol,
     409             :             double mu, double T,
     410             :             double barrier_low, double barrier_up,
     411             :             const ANY& strikeval, const ANY& put_call ) THROWDEF_RTE_IAE;
     412             : 
     413             : };
     414             : //------------------------------------------------------------------
     415             : 
     416             : #endif
     417             : 
     418             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10