diff options
Diffstat (limited to 'scaddins/source/pricing')
-rw-r--r-- | scaddins/source/pricing/pricing.cxx | 51 | ||||
-rw-r--r-- | scaddins/source/pricing/pricing.hrc | 41 | ||||
-rw-r--r-- | scaddins/source/pricing/pricing.hxx | 36 | ||||
-rw-r--r-- | scaddins/source/pricing/pricing.src | 153 |
4 files changed, 28 insertions, 253 deletions
diff --git a/scaddins/source/pricing/pricing.cxx b/scaddins/source/pricing/pricing.cxx index 466c0e78fd44..3df3fe78a061 100644 --- a/scaddins/source/pricing/pricing.cxx +++ b/scaddins/source/pricing/pricing.cxx @@ -25,6 +25,7 @@ #include "pricing.hxx" #include "black_scholes.hxx" #include "pricing.hrc" +#include "strings.hrc" #include <cppuhelper/factory.hxx> #include <cppuhelper/supportsservice.hxx> @@ -32,7 +33,6 @@ #include <algorithm> #include <rtl/math.hxx> #include <rtl/ustrbuf.hxx> -#include <tools/rcid.h> #include <tools/resmgr.hxx> using namespace ::com::sun::star; @@ -43,11 +43,6 @@ using namespace sca::pricing; #define MY_SERVICE "com.sun.star.sheet.addin.PricingFunctions" #define MY_IMPLNAME "com.sun.star.sheet.addin.PricingFunctionsImpl" -ScaResId::ScaResId( sal_uInt16 nId, ResMgr& rResMgr ) : - ResId( nId, rResMgr ) -{ -} - #define UNIQUE false // function name does not exist in Calc #define STDPAR false // all parameters are described @@ -67,8 +62,8 @@ const ScaFuncDataBase pFuncDataArr[] = ScaFuncData::ScaFuncData( const ScaFuncDataBase& rBaseData ) : aIntName( OUString::createFromAscii( rBaseData.pIntName ) ), - nUINameID( rBaseData.nUINameID ), - nDescrID( rBaseData.nDescrID ), + pUINameID( rBaseData.pUINameID ), + pDescrID( rBaseData.pDescrID ), nParamCount( rBaseData.nParamCount ), eCat( rBaseData.eCat ), bDouble( rBaseData.bDouble ), @@ -132,7 +127,6 @@ SAL_DLLPUBLIC_EXPORT void * SAL_CALL pricing_component_getFactory( // "normal" service implementation ScaPricingAddIn::ScaPricingAddIn() : pDefLocales( nullptr ), - pResMgr( nullptr ), pFuncDataList( nullptr ) { } @@ -140,7 +134,6 @@ ScaPricingAddIn::ScaPricingAddIn() : ScaPricingAddIn::~ScaPricingAddIn() { delete pFuncDataList; - delete pResMgr; delete[] pDefLocales; } @@ -167,32 +160,13 @@ const lang::Locale& ScaPricingAddIn::GetLocale( sal_uInt32 nIndex ) return (nIndex < sizeof( pLang )) ? pDefLocales[ nIndex ] : aFuncLoc; } -ResMgr& ScaPricingAddIn::GetResMgr() -{ - if( !pResMgr ) - { - InitData(); // try to get resource manager - if( !pResMgr ) - throw uno::RuntimeException(); - } - return *pResMgr; -} - void ScaPricingAddIn::InitData() { - delete pResMgr; - pResMgr = ResMgr::CreateResMgr("pricing", LanguageTag( aFuncLoc) ); + aResLocale = Translate::Create("sca", LanguageTag(aFuncLoc)); delete pFuncDataList; - if(pResMgr) - { - pFuncDataList = new ScaFuncDataList; - InitScaFuncDataList(*pFuncDataList); - } - else - { - pFuncDataList = nullptr; - } + pFuncDataList = new ScaFuncDataList; + InitScaFuncDataList(*pFuncDataList); if( pDefLocales ) { @@ -201,10 +175,9 @@ void ScaPricingAddIn::InitData() } } -OUString ScaPricingAddIn::GetFuncDescrStr( sal_uInt16 nResId, sal_uInt16 nStrIndex ) +OUString ScaPricingAddIn::GetFuncDescrStr(const char** pResId, sal_uInt16 nStrIndex) { - ResStringArray aArr(ScaResId(nResId, GetResMgr())); - return aArr.GetString(nStrIndex - 1); + return ScaResId(pResId[nStrIndex - 1]); } OUString ScaPricingAddIn::getImplementationName_Static() @@ -271,9 +244,9 @@ OUString SAL_CALL ScaPricingAddIn::getDisplayFunctionName( const OUString& aProg auto fDataIt = std::find_if(pFuncDataList->begin(), pFuncDataList->end(), FindScaFuncData( aProgrammaticName ) ); - if(fDataIt != pFuncDataList->end() ) + if (fDataIt != pFuncDataList->end() ) { - aRet = ScaResId(fDataIt->GetUINameID(), GetResMgr()); + aRet = ScaResId(fDataIt->GetUINameID()); if( fDataIt->IsDouble() ) aRet += "_ADD"; } @@ -583,5 +556,9 @@ double SAL_CALL ScaPricingAddIn::getOptProbInMoney( double spot, double vol, RETURN_FINITE( fRet ); } +OUString ScaPricingAddIn::ScaResId(const char* pResId) +{ + return Translate::get(pResId, aResLocale); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/scaddins/source/pricing/pricing.hrc b/scaddins/source/pricing/pricing.hrc deleted file mode 100644 index af516650eb75..000000000000 --- a/scaddins/source/pricing/pricing.hrc +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_SCADDINS_SOURCE_PRICING_PRICING_HRC -#define INCLUDED_SCADDINS_SOURCE_PRICING_PRICING_HRC - -#define PRICING_RESOURCE_START 1000 - -#define PRICING_FUNCDESC_START PRICING_RESOURCE_START - -#define PRICING_FUNCDESC_OptBarrier (PRICING_FUNCDESC_START) -#define PRICING_FUNCDESC_OptTouch (PRICING_FUNCDESC_START+1) -#define PRICING_FUNCDESC_OptProbHit (PRICING_FUNCDESC_START+2) -#define PRICING_FUNCDESC_OptProbInMoney (PRICING_FUNCDESC_START+3) - -#define PRICING_FUNCNAME_START (PRICING_RESOURCE_START+1000) - -#define PRICING_FUNCNAME_OptBarrier (PRICING_FUNCNAME_START) -#define PRICING_FUNCNAME_OptTouch (PRICING_FUNCNAME_START+1) -#define PRICING_FUNCNAME_OptProbHit (PRICING_FUNCNAME_START+2) -#define PRICING_FUNCNAME_OptProbInMoney (PRICING_FUNCNAME_START+3) - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/scaddins/source/pricing/pricing.hxx b/scaddins/source/pricing/pricing.hxx index 18acc54c811f..82fbbb6cacc5 100644 --- a/scaddins/source/pricing/pricing.hxx +++ b/scaddins/source/pricing/pricing.hxx @@ -37,8 +37,6 @@ #include <com/sun/star/sheet/XCompatibilityNames.hpp> #include <com/sun/star/sheet/addin/XPricingFunctions.hpp> #include <cppuhelper/implbase.hxx> -#include <tools/resid.hxx> -#include <tools/resary.hxx> #define RETURN_FINITE(d) if( ::rtl::math::isFinite( d ) ) return d; else throw css::lang::IllegalArgumentException() @@ -46,12 +44,6 @@ namespace sca { namespace pricing { -class ScaResId : public ResId -{ -public: - ScaResId( sal_uInt16 nResId, ResMgr& rResMgr ); -}; - enum class ScaCategory { DateTime, @@ -65,8 +57,8 @@ enum class ScaCategory struct ScaFuncDataBase { const sal_Char* pIntName; // internal name (get***) - sal_uInt16 nUINameID; // resource ID to UI name - sal_uInt16 nDescrID; // resource ID to description, parameter names and ~ description + const char* pUINameID; // resource ID to UI name + const char** pDescrID; // resource ID to description, parameter names and ~ description // pCompName was originally meant to be able to load Excel documents that for // some time were stored with localized function names. // This is not relevant to this add-in, so we only supply the same @@ -82,12 +74,12 @@ struct ScaFuncDataBase class ScaFuncData final { private: - OUString aIntName; // internal name (get***) - sal_uInt16 nUINameID; // resource ID to UI name - sal_uInt16 nDescrID; // leads also to parameter descriptions! - sal_uInt16 nParamCount; // num of parameters - std::vector<OUString> aCompList; // list of all valid names - ScaCategory eCat; // function category + OUString aIntName; // internal name (get***) + const char* pUINameID; // resource ID to UI name + const char** pDescrID; // leads also to parameter descriptions! + sal_uInt16 nParamCount; // num of parameters + std::vector<OUString> aCompList; // list of all valid names + ScaCategory eCat; // function category bool bDouble; // name already exist in Calc bool bWithOpt; // first parameter is internal @@ -95,8 +87,8 @@ public: ScaFuncData(const ScaFuncDataBase& rBaseData); ~ScaFuncData(); - sal_uInt16 GetUINameID() const { return nUINameID; } - sal_uInt16 GetDescrID() const { return nDescrID; } + const char* GetUINameID() const { return pUINameID; } + const char** GetDescrID() const { return pDescrID; } ScaCategory GetCategory() const { return eCat; } bool IsDouble() const { return bDouble; } @@ -140,23 +132,23 @@ class ScaPricingAddIn : public ::cppu::WeakImplHelper< private: css::lang::Locale aFuncLoc; css::lang::Locale* pDefLocales; - ResMgr* pResMgr; + std::locale aResLocale; sca::pricing::ScaFuncDataList* pFuncDataList; void InitDefLocales(); const css::lang::Locale& GetLocale( sal_uInt32 nIndex ); - /// @throws css::uno::RuntimeException - ResMgr& GetResMgr(); void InitData(); /// @throws css::uno::RuntimeException - OUString GetFuncDescrStr( sal_uInt16 nResId, sal_uInt16 nStrIndex ); + OUString GetFuncDescrStr(const char** pResId, sal_uInt16 nStrIndex); public: ScaPricingAddIn(); virtual ~ScaPricingAddIn() override; + OUString ScaResId(const char* pResId); + static OUString getImplementationName_Static(); static css::uno::Sequence< OUString > getSupportedServiceNames_Static(); diff --git a/scaddins/source/pricing/pricing.src b/scaddins/source/pricing/pricing.src deleted file mode 100644 index d1ed46a08898..000000000000 --- a/scaddins/source/pricing/pricing.src +++ /dev/null @@ -1,153 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include "pricing.hrc" - -// function and parameter description -StringArray PRICING_FUNCDESC_OptBarrier -{ - ItemList [ en-US ] = - { - < "Pricing of a barrier option"; > ; - < "spot"; > ; - < "Price/value of the underlying asset"; > ; - < "vol"; > ; - < "Annual volatility of the underlying asset"; > ; - < "r"; > ; - < "Interest rate (continuously compounded)"; > ; - < "rf"; > ; - < "Foreign interest rate (continuously compounded)"; > ; - < "T"; > ; - < "Time to maturity of the option in years"; > ; - < "strike"; > ; - < "Strike level of the option"; > ; - < "barrier_low"; > ; - < "Lower barrier (set to 0 for no lower barrier)"; > ; - < "barrier_up"; > ; - < "Upper barrier (set to 0 for no upper barrier)"; > ; - < "rebate"; > ; - < "Amount of money paid at maturity if barrier was hit"; > ; - < "put/call"; > ; - < "String to define if the option is a (p)ut or a (c)all"; > ; - < "knock in/out"; > ; - < "String to define if the option is of type knock-(i)n or knock-(o)ut"; > ; - < "barrier_type"; > ; - < "String to define whether the barrier is observed (c)ontinuously or only at the (e)nd/maturity"; > ; - < "greek"; > ; - < "Optional parameter, if left out then the function simply returns the option price; if set, the function returns price sensitivities (Greeks) to one of the input parameters; possible values are (d)elta, (g)amma, (t)heta, v(e)ga, v(o)lga, v(a)nna, (r)ho, rho(f)"; > ; - }; -}; - -StringArray PRICING_FUNCDESC_OptTouch -{ - ItemList [ en-US ] = - { - < "Pricing of a touch/no-touch option"; > ; - < "spot"; > ; - < "Price/value of the underlying asset"; > ; - < "vol"; > ; - < "Annual volatility of the underlying asset"; > ; - < "r"; > ; - < "Interest rate (continuously compounded)"; > ; - < "rf"; > ; - < "Foreign interest rate (continuously compounded)"; > ; - < "T"; > ; - < "Time to maturity of the option in years"; > ; - < "barrier_low"; > ; - < "Lower barrier (set to 0 for no lower barrier)"; > ; - < "barrier_up"; > ; - < "Upper barrier (set to 0 for no upper barrier)"; > ; - < "foreign/domestic"; > ; - < "String to define if the option pays one unit of (d)omestic currency (cash or nothing) or (f)oreign currency (asset or nothing)"; > ; - < "knock in/out"; > ; - < "String to define if the option is of type knock-(i)n (touch) or knock-(o)ut (no-touch)"; > ; - < "barrier_type"; > ; - < "String to define whether the barrier is observed (c)ontinuously or only at the (e)nd/maturity"; > ; - < "greek"; > ; - < "Optional parameter, if left out then the function simply returns the option price; if set, the function returns price sensitivities (Greeks) to one of the input parameters; possible values are (d)elta, (g)amma, (t)heta, v(e)ga, v(o)lga, v(a)nna, (r)ho, rho(f)"; > ; - }; -}; - -StringArray PRICING_FUNCDESC_OptProbHit -{ - ItemList [ en-US ] = - { - < "Probability that an asset hits a barrier assuming it follows dS/S = mu dt + vol dW"; > ; - < "spot"; > ; - < "Price/value S of the underlying asset"; > ; - < "vol"; > ; - < "Annual volatility of the underlying asset"; > ; - < "drift"; > ; - < "Parameter mu in dS/S = mu dt + vol dW"; > ; - < "T"; > ; - < "Time to maturity"; > ; - < "barrier_low"; > ; - < "Lower barrier (set to 0 for no lower barrier)"; > ; - < "barrier_up"; > ; - < "Upper barrier (set to 0 for no upper barrier)"; > ; - }; -}; - -StringArray PRICING_FUNCDESC_OptProbInMoney -{ - ItemList [ en-US ] = - { - < "Probability that an asset will at maturity end up between two barrier levels, assuming it follows dS/S = mu dt + vol dW (if the last two optional parameters (strike, put/call) are specified, the probability of S_T in [strike, upper barrier] for a call and S_T in [lower barrier, strike] for a put will be returned)"; > ; - < "spot"; > ; - < "Price/value of the asset"; > ; - < "vol"; > ; - < "Annual volatility of the asset"; > ; - < "drift"; > ; - < "Parameter mu from dS/S = mu dt + vol dW"; > ; - < "T"; > ; - < "Time to maturity in years"; > ; - < "barrier_low"; > ; - < "Lower barrier (set to 0 for no lower barrier)"; > ; - < "barrier_up"; > ; - < "Upper barrier (set to 0 for no upper barrier)"; > ; - < "put/call"; > ; - < "Optional (p)ut/(c)all indicator"; > ; - < "strike"; > ; - < "Optional strike level"; > ; - }; -}; - -// function names as accessible from cells - -String PRICING_FUNCNAME_OptBarrier -{ - Text [ en-US ] = "OPT_BARRIER"; -}; - -String PRICING_FUNCNAME_OptTouch -{ - Text [ en-US ] = "OPT_TOUCH"; -}; - -String PRICING_FUNCNAME_OptProbHit -{ - Text [ en-US ] = "OPT_PROB_HIT"; -}; - -String PRICING_FUNCNAME_OptProbInMoney -{ - Text [ en-US ] = "OPT_PROB_INMONEY"; -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |