1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 // option pricing functions add in
22 // most parts of this files are technical UNO details which are
23 // all copied from ../datefunc/datefunc.hxx
24 // to avoid having to rename all classes to do with UNO
25 // technicalities we use our own namespace
27 #ifndef INCLUDED_SCADDINS_SOURCE_PRICING_PRICING_HXX
28 #define INCLUDED_SCADDINS_SOURCE_PRICING_PRICING_HXX
33 #include <com/sun/star/lang/XServiceName.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/sheet/XAddIn.hpp>
36 #include <com/sun/star/sheet/XCompatibilityNames.hpp>
37 #include <com/sun/star/sheet/addin/XPricingFunctions.hpp>
38 #include <cppuhelper/implbase.hxx>
40 namespace com::sun::star::lang
{ class XMultiServiceFactory
; }
42 #define RETURN_FINITE(d) if( !::rtl::math::isFinite( d ) ) throw css::lang::IllegalArgumentException(); return d;
48 enum class ScaCategory
58 struct ScaFuncDataBase
60 const sal_Char
* pIntName
; // internal name (get***)
61 const char* pUINameID
; // resource ID to UI name
62 const char** pDescrID
; // resource ID to description, parameter names and ~ description
63 // pCompName was originally meant to be able to load Excel documents that for
64 // some time were stored with localized function names.
65 // This is not relevant to this add-in, so we only supply the same
66 // (English) function names again.
67 // see also: GetExcelName() or GetCompNames() or getCompatibilityNames()
68 const char* pCompName
;
69 sal_uInt16
const nParamCount
; // number of named / described parameters
70 ScaCategory
const eCat
; // function category
71 bool const bDouble
; // name already exist in Calc
72 bool const bWithOpt
; // first parameter is internal
75 class ScaFuncData final
78 OUString
const aIntName
; // internal name (get***)
79 const char* pUINameID
; // resource ID to UI name
80 const char** pDescrID
; // leads also to parameter descriptions!
81 sal_uInt16
const nParamCount
; // num of parameters
82 std::vector
<OUString
> aCompList
; // list of all valid names
83 ScaCategory
const eCat
; // function category
84 bool const bDouble
; // name already exist in Calc
85 bool const bWithOpt
; // first parameter is internal
88 ScaFuncData(const ScaFuncDataBase
& rBaseData
);
91 const char* GetUINameID() const { return pUINameID
; }
92 const char** GetDescrID() const { return pDescrID
; }
93 ScaCategory
GetCategory() const { return eCat
; }
94 bool IsDouble() const { return bDouble
; }
96 sal_uInt16
GetStrIndex( sal_uInt16 nParam
) const;
97 bool Is( const OUString
& rCompare
) const
98 { return aIntName
== rCompare
; }
100 const std::vector
<OUString
>& GetCompNameList() const { return aCompList
; }
104 typedef std::vector
<ScaFuncData
> ScaFuncDataList
;
106 void InitScaFuncDataList(ScaFuncDataList
& rMap
);
108 // Predicate for use with std::find_if
109 struct FindScaFuncData
111 const OUString
& m_rId
;
112 explicit FindScaFuncData( const OUString
& rId
) : m_rId(rId
) {}
113 bool operator() ( ScaFuncData
const & rCandidate
) const { return rCandidate
.Is(m_rId
); }
116 } // namespace pricing
120 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
PricingFunctionAddIn_CreateInstance(
121 const css::uno::Reference
< css::lang::XMultiServiceFactory
>& );
124 // AddIn class for pricing functions
126 class ScaPricingAddIn
: public ::cppu::WeakImplHelper
<
128 css::sheet::XCompatibilityNames
,
129 css::sheet::addin::XPricingFunctions
,
130 css::lang::XServiceName
,
131 css::lang::XServiceInfo
>
134 css::lang::Locale aFuncLoc
;
135 std::unique_ptr
<css::lang::Locale
[]> pDefLocales
;
136 std::locale aResLocale
;
137 std::unique_ptr
<sca::pricing::ScaFuncDataList
> pFuncDataList
;
140 void InitDefLocales();
141 const css::lang::Locale
& GetLocale( sal_uInt32 nIndex
);
144 /// @throws css::uno::RuntimeException
145 OUString
GetFuncDescrStr(const char** pResId
, sal_uInt16 nStrIndex
);
149 virtual ~ScaPricingAddIn() override
;
151 OUString
ScaResId(const char* pResId
);
153 static OUString
getImplementationName_Static();
154 static css::uno::Sequence
< OUString
> getSupportedServiceNames_Static();
157 virtual OUString SAL_CALL
getProgrammaticFuntionName( const OUString
& aDisplayName
) override
;
158 virtual OUString SAL_CALL
getDisplayFunctionName( const OUString
& aProgrammaticName
) override
;
159 virtual OUString SAL_CALL
getFunctionDescription( const OUString
& aProgrammaticName
) override
;
160 virtual OUString SAL_CALL
getDisplayArgumentName( const OUString
& aProgrammaticName
, sal_Int32 nArgument
) override
;
161 virtual OUString SAL_CALL
getArgumentDescription( const OUString
& aProgrammaticName
, sal_Int32 nArgument
) override
;
162 virtual OUString SAL_CALL
getProgrammaticCategoryName( const OUString
& aProgrammaticName
) override
;
163 virtual OUString SAL_CALL
getDisplayCategoryName( const OUString
& aProgrammaticName
) override
;
165 // XCompatibilityNames
166 virtual css::uno::Sequence
< css::sheet::LocalizedName
> SAL_CALL
getCompatibilityNames( const OUString
& aProgrammaticName
) override
;
169 virtual void SAL_CALL
setLocale( const css::lang::Locale
& eLocale
) override
;
170 virtual css::lang::Locale SAL_CALL
getLocale() override
;
173 virtual OUString SAL_CALL
getServiceName() override
;
176 virtual OUString SAL_CALL
getImplementationName() override
;
177 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
178 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
181 // methods from own interfaces start here
184 virtual double SAL_CALL
getOptBarrier( double spot
, double vol
,
185 double r
, double rf
, double T
, double strike
,
186 double barrier_low
, double barrier_up
, double rebate
,
187 const OUString
& put_call
, const OUString
& in_out
,
188 const OUString
& continuous
, const css::uno::Any
& greek
) override
;
190 virtual double SAL_CALL
getOptTouch( double spot
, double vol
,
191 double r
, double rf
, double T
,
192 double barrier_low
, double barrier_up
,
193 const OUString
& for_dom
, const OUString
& in_out
,
194 const OUString
& barriercont
, const css::uno::Any
& greekstr
) override
;
196 virtual double SAL_CALL
getOptProbHit( double spot
, double vol
,
198 double barrier_low
, double barrier_up
) override
;
200 virtual double SAL_CALL
getOptProbInMoney( double spot
, double vol
,
202 double barrier_low
, double barrier_up
,
203 const css::uno::Any
& strikeval
, const css::uno::Any
& put_call
) override
;
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */