tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / scaddins / source / pricing / pricing.hxx
blob92f2e553a9f0fbb70caecb1899b11ae24e888b61
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 #pragma once
30 #include <vector>
31 #include <memory>
32 #include <com/sun/star/lang/XServiceName.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/sheet/XAddIn.hpp>
35 #include <com/sun/star/sheet/XCompatibilityNames.hpp>
36 #include <com/sun/star/sheet/addin/XPricingFunctions.hpp>
37 #include <cppuhelper/implbase.hxx>
38 #include <unotools/resmgr.hxx>
40 namespace com::sun::star::lang { class XMultiServiceFactory; }
43 namespace sca::pricing {
45 enum class ScaCategory
47 DateTime,
48 Text,
49 Finance,
50 Inf,
51 Math,
52 Tech
55 struct ScaFuncDataBase
57 const char* pIntName; // internal name (get***)
58 TranslateId pUINameID; // resource ID to UI name
59 const TranslateId* pDescrID; // resource ID to description, parameter names and ~ description
60 // pCompName was originally meant to be able to load Excel documents that for
61 // some time were stored with localized function names.
62 // This is not relevant to this add-in, so we only supply the
63 // English function name.
64 // see also: GetExcelName() or GetCompNames() or getCompatibilityNames()
65 const char* pCompName;
66 sal_uInt16 nParamCount; // number of named / described parameters
67 ScaCategory eCat; // function category
68 bool bDouble; // name already exist in Calc
69 bool bWithOpt; // first parameter is internal
72 class ScaFuncData final
74 private:
75 OUString aIntName; // internal name (get***)
76 TranslateId pUINameID; // resource ID to UI name
77 const TranslateId* pDescrID; // leads also to parameter descriptions!
78 sal_uInt16 nParamCount; // num of parameters
79 std::vector<OUString> aCompList; // list of all valid names
80 ScaCategory eCat; // function category
81 bool bDouble; // name already exist in Calc
82 bool bWithOpt; // first parameter is internal
84 public:
85 ScaFuncData(const ScaFuncDataBase& rBaseData);
87 const TranslateId& GetUINameID() const { return pUINameID; }
88 const TranslateId* GetDescrID() const { return pDescrID; }
89 ScaCategory GetCategory() const { return eCat; }
90 bool IsDouble() const { return bDouble; }
92 sal_uInt16 GetStrIndex( sal_uInt16 nParam ) const;
93 bool Is( std::u16string_view rCompare ) const
94 { return aIntName == rCompare; }
96 const std::vector<OUString>& GetCompNameList() const { return aCompList; }
100 typedef std::vector<ScaFuncData> ScaFuncDataList;
102 void InitScaFuncDataList(ScaFuncDataList& rMap);
104 // Predicate for use with std::find_if
105 struct FindScaFuncData
107 const OUString& m_rId;
108 explicit FindScaFuncData( const OUString& rId ) : m_rId(rId) {}
109 bool operator() ( ScaFuncData const & rCandidate ) const { return rCandidate.Is(m_rId); }
112 } // namespace sca::pricing
115 // AddIn class for pricing functions
117 class ScaPricingAddIn : public ::cppu::WeakImplHelper<
118 css::sheet::XAddIn,
119 css::sheet::XCompatibilityNames,
120 css::sheet::addin::XPricingFunctions,
121 css::lang::XServiceName,
122 css::lang::XServiceInfo >
124 private:
125 css::lang::Locale aFuncLoc;
126 std::unique_ptr<css::lang::Locale[]> pDefLocales;
127 std::locale aResLocale;
128 std::unique_ptr<sca::pricing::ScaFuncDataList> pFuncDataList;
131 void InitDefLocales();
132 const css::lang::Locale& GetLocale( sal_uInt32 nIndex );
133 void InitData();
135 /// @throws css::uno::RuntimeException
136 OUString GetFuncDescrStr(const TranslateId* pResId, sal_uInt16 nStrIndex);
138 public:
139 ScaPricingAddIn();
140 virtual ~ScaPricingAddIn() override;
142 OUString ScaResId(TranslateId aResId);
144 // XAddIn
145 virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) override;
146 virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) override;
147 virtual OUString SAL_CALL getFunctionDescription( const OUString& aProgrammaticName ) override;
148 virtual OUString SAL_CALL getDisplayArgumentName( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
149 virtual OUString SAL_CALL getArgumentDescription( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
150 virtual OUString SAL_CALL getProgrammaticCategoryName( const OUString& aProgrammaticName ) override;
151 virtual OUString SAL_CALL getDisplayCategoryName( const OUString& aProgrammaticName ) override;
153 // XCompatibilityNames
154 virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames( const OUString& aProgrammaticName ) override;
156 // XLocalizable
157 virtual void SAL_CALL setLocale( const css::lang::Locale& eLocale ) override;
158 virtual css::lang::Locale SAL_CALL getLocale() override;
160 // XServiceName
161 virtual OUString SAL_CALL getServiceName() override;
163 // XServiceInfo
164 virtual OUString SAL_CALL getImplementationName() override;
165 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
166 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
169 // methods from own interfaces start here
172 virtual double SAL_CALL getOptBarrier( double spot, double vol,
173 double r, double rf, double T, double strike,
174 double barrier_low, double barrier_up, double rebate,
175 const OUString& put_call, const OUString& in_out,
176 const OUString& continuous, const css::uno::Any& greek ) override;
178 virtual double SAL_CALL getOptTouch( double spot, double vol,
179 double r, double rf, double T,
180 double barrier_low, double barrier_up,
181 const OUString& for_dom, const OUString& in_out,
182 const OUString& barriercont, const css::uno::Any& greekstr ) override;
184 virtual double SAL_CALL getOptProbHit( double spot, double vol,
185 double mu, double T,
186 double barrier_low, double barrier_up ) override;
188 virtual double SAL_CALL getOptProbInMoney( double spot, double vol,
189 double mu, double T,
190 double barrier_low, double barrier_up,
191 const css::uno::Any& strikeval, const css::uno::Any& put_call ) override;
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */