Bump version to 6.0-36
[LibreOffice.git] / scaddins / source / pricing / pricing.hxx
blobeb353e0a2235f309fdf5f18d955fbd3646f3a0a3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
31 #include <string.h>
32 #include <vector>
33 #include <com/sun/star/lang/XServiceName.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/sheet/XAddIn.hpp>
37 #include <com/sun/star/sheet/XCompatibilityNames.hpp>
38 #include <com/sun/star/sheet/addin/XPricingFunctions.hpp>
39 #include <cppuhelper/implbase.hxx>
41 #define RETURN_FINITE(d) if( !::rtl::math::isFinite( d ) ) throw css::lang::IllegalArgumentException(); return d;
44 namespace sca {
45 namespace pricing {
47 enum class ScaCategory
49 DateTime,
50 Text,
51 Finance,
52 Inf,
53 Math,
54 Tech
57 struct ScaFuncDataBase
59 const sal_Char* pIntName; // internal name (get***)
60 const char* pUINameID; // resource ID to UI name
61 const char** pDescrID; // resource ID to description, parameter names and ~ description
62 // pCompName was originally meant to be able to load Excel documents that for
63 // some time were stored with localized function names.
64 // This is not relevant to this add-in, so we only supply the same
65 // (English) function names again.
66 // see also: GetExcelName() or GetCompNames() or getCompatibilityNames()
67 const char* pCompName;
68 sal_uInt16 nParamCount; // number of named / described parameters
69 ScaCategory eCat; // function category
70 bool bDouble; // name already exist in Calc
71 bool bWithOpt; // first parameter is internal
74 class ScaFuncData final
76 private:
77 OUString aIntName; // internal name (get***)
78 const char* pUINameID; // resource ID to UI name
79 const char** pDescrID; // leads also to parameter descriptions!
80 sal_uInt16 nParamCount; // num of parameters
81 std::vector<OUString> aCompList; // list of all valid names
82 ScaCategory eCat; // function category
83 bool bDouble; // name already exist in Calc
84 bool bWithOpt; // first parameter is internal
86 public:
87 ScaFuncData(const ScaFuncDataBase& rBaseData);
88 ~ScaFuncData();
90 const char* GetUINameID() const { return pUINameID; }
91 const char** GetDescrID() const { return pDescrID; }
92 ScaCategory GetCategory() const { return eCat; }
93 bool IsDouble() const { return bDouble; }
95 sal_uInt16 GetStrIndex( sal_uInt16 nParam ) const;
96 bool Is( const OUString& rCompare ) const
97 { return aIntName == rCompare; }
99 const std::vector<OUString>& GetCompNameList() const { return aCompList; }
103 typedef std::vector<ScaFuncData> ScaFuncDataList;
105 void InitScaFuncDataList(ScaFuncDataList& rMap);
107 // Predicate for use with std::find_if
108 struct FindScaFuncData
110 const OUString& m_rId;
111 explicit FindScaFuncData( const OUString& rId ) : m_rId(rId) {}
112 bool operator() ( ScaFuncData const & rCandidate ) const { return rCandidate.Is(m_rId); }
115 } // namespace pricing
116 } // namespace sca
119 css::uno::Reference< css::uno::XInterface > SAL_CALL PricingFunctionAddIn_CreateInstance(
120 const css::uno::Reference< css::lang::XMultiServiceFactory >& );
123 // AddIn class for pricing functions
125 class ScaPricingAddIn : public ::cppu::WeakImplHelper<
126 css::sheet::XAddIn,
127 css::sheet::XCompatibilityNames,
128 css::sheet::addin::XPricingFunctions,
129 css::lang::XServiceName,
130 css::lang::XServiceInfo >
132 private:
133 css::lang::Locale aFuncLoc;
134 css::lang::Locale* pDefLocales;
135 std::locale aResLocale;
136 sca::pricing::ScaFuncDataList* pFuncDataList;
139 void InitDefLocales();
140 const css::lang::Locale& GetLocale( sal_uInt32 nIndex );
141 void InitData();
143 /// @throws css::uno::RuntimeException
144 OUString GetFuncDescrStr(const char** pResId, sal_uInt16 nStrIndex);
146 public:
147 ScaPricingAddIn();
148 virtual ~ScaPricingAddIn() override;
150 OUString ScaResId(const char* pResId);
152 static OUString getImplementationName_Static();
153 static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
155 // XAddIn
156 virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) override;
157 virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) override;
158 virtual OUString SAL_CALL getFunctionDescription( const OUString& aProgrammaticName ) override;
159 virtual OUString SAL_CALL getDisplayArgumentName( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
160 virtual OUString SAL_CALL getArgumentDescription( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
161 virtual OUString SAL_CALL getProgrammaticCategoryName( const OUString& aProgrammaticName ) override;
162 virtual OUString SAL_CALL getDisplayCategoryName( const OUString& aProgrammaticName ) override;
164 // XCompatibilityNames
165 virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames( const OUString& aProgrammaticName ) override;
167 // XLocalizable
168 virtual void SAL_CALL setLocale( const css::lang::Locale& eLocale ) override;
169 virtual css::lang::Locale SAL_CALL getLocale() override;
171 // XServiceName
172 virtual OUString SAL_CALL getServiceName() override;
174 // XServiceInfo
175 virtual OUString SAL_CALL getImplementationName() override;
176 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
177 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
180 // methods from own interfaces start here
183 virtual double SAL_CALL getOptBarrier( double spot, double vol,
184 double r, double rf, double T, double strike,
185 double barrier_low, double barrier_up, double rebate,
186 const OUString& put_call, const OUString& in_out,
187 const OUString& continuous, const css::uno::Any& greek ) override;
189 virtual double SAL_CALL getOptTouch( double spot, double vol,
190 double r, double rf, double T,
191 double barrier_low, double barrier_up,
192 const OUString& for_dom, const OUString& in_out,
193 const OUString& barriercont, const css::uno::Any& greekstr ) override;
195 virtual double SAL_CALL getOptProbHit( double spot, double vol,
196 double mu, double T,
197 double barrier_low, double barrier_up ) override;
199 virtual double SAL_CALL getOptProbInMoney( double spot, double vol,
200 double mu, double T,
201 double barrier_low, double barrier_up,
202 const css::uno::Any& strikeval, const css::uno::Any& put_call ) override;
207 #endif
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */