Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/scaddins/source/pricing/pricing.hxx
Line
Count
Source
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
// option pricing functions add in
21
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
26
27
#pragma once
28
29
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>
39
40
41
namespace sca::pricing {
42
43
enum class ScaCategory
44
{
45
    DateTime,
46
    Text,
47
    Finance,
48
    Inf,
49
    Math,
50
    Tech
51
};
52
53
struct ScaFuncDataBase
54
{
55
    const char*                 pIntName;           // internal name (get***)
56
    TranslateId                 pUINameID;          // resource ID to UI name
57
    const TranslateId*          pDescrID;           // resource ID to description, parameter names and ~ description
58
    // pCompName was originally meant to be able to load Excel documents that for
59
    // some time were stored with localized function names.
60
    // This is not relevant to this add-in, so we only supply the
61
    // English function name.
62
    // see also: GetExcelName() or GetCompNames() or getCompatibilityNames()
63
    const char*                 pCompName;
64
    sal_uInt16                  nParamCount;        // number of named / described parameters
65
    ScaCategory                 eCat;               // function category
66
    bool                        bDouble;            // name already exist in Calc
67
    bool                        bWithOpt;           // first parameter is internal
68
};
69
70
class ScaFuncData final
71
{
72
private:
73
    OUString                aIntName;           // internal name (get***)
74
    TranslateId             pUINameID;          // resource ID to UI name
75
    const TranslateId*      pDescrID;           // leads also to parameter descriptions!
76
    sal_uInt16              nParamCount;        // num of parameters
77
    std::vector<OUString>   aCompList;          // list of all valid names
78
    ScaCategory             eCat;               // function category
79
    bool                    bDouble;            // name already exist in Calc
80
    bool                    bWithOpt;           // first parameter is internal
81
82
public:
83
    ScaFuncData(const ScaFuncDataBase& rBaseData);
84
85
40
    const TranslateId&   GetUINameID() const     { return pUINameID; }
86
400
    const TranslateId*   GetDescrID() const      { return pDescrID; }
87
20
    ScaCategory          GetCategory() const     { return eCat; }
88
40
    bool                 IsDouble() const        { return bDouble; }
89
90
    sal_uInt16                  GetStrIndex( sal_uInt16 nParam ) const;
91
    bool                 Is( std::u16string_view rCompare ) const
92
1.07k
                                                    { return aIntName == rCompare; }
93
94
8
    const std::vector<OUString>& GetCompNameList() const { return aCompList; }
95
};
96
97
98
typedef std::vector<ScaFuncData> ScaFuncDataList;
99
100
void InitScaFuncDataList(ScaFuncDataList& rMap);
101
102
// Predicate for use with std::find_if
103
struct FindScaFuncData
104
{
105
    const OUString& m_rId;
106
468
    explicit FindScaFuncData( const OUString& rId ) : m_rId(rId) {}
107
1.07k
    bool operator() ( ScaFuncData const & rCandidate ) const { return rCandidate.Is(m_rId); }
108
};
109
110
} // namespace sca::pricing
111
112
113
// AddIn class for pricing functions
114
115
class ScaPricingAddIn : public ::cppu::WeakImplHelper<
116
                                css::sheet::XAddIn,
117
                                css::sheet::XCompatibilityNames,
118
                                css::sheet::addin::XPricingFunctions,
119
                                css::lang::XServiceName,
120
                                css::lang::XServiceInfo >
121
{
122
private:
123
    css::lang::Locale  aFuncLoc;
124
    std::unique_ptr<css::lang::Locale[]> pDefLocales;
125
    std::locale        aResLocale;
126
    std::unique_ptr<sca::pricing::ScaFuncDataList> pFuncDataList;
127
128
129
    void                        InitDefLocales();
130
    const css::lang::Locale& GetLocale( sal_uInt32 nIndex );
131
    void                        InitData();
132
133
    /// @throws css::uno::RuntimeException
134
    OUString             GetFuncDescrStr(const TranslateId* pResId, sal_uInt16 nStrIndex);
135
136
public:
137
                                ScaPricingAddIn();
138
    virtual                     ~ScaPricingAddIn() override;
139
140
    OUString ScaResId(TranslateId aResId);
141
142
                                // XAddIn
143
    virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) override;
144
    virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) override;
145
    virtual OUString SAL_CALL getFunctionDescription( const OUString& aProgrammaticName ) override;
146
    virtual OUString SAL_CALL getDisplayArgumentName( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
147
    virtual OUString SAL_CALL getArgumentDescription( const OUString& aProgrammaticName, sal_Int32 nArgument ) override;
148
    virtual OUString SAL_CALL getProgrammaticCategoryName( const OUString& aProgrammaticName ) override;
149
    virtual OUString SAL_CALL getDisplayCategoryName( const OUString& aProgrammaticName ) override;
150
151
                                // XCompatibilityNames
152
    virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames( const OUString& aProgrammaticName ) override;
153
154
                                // XLocalizable
155
    virtual void SAL_CALL       setLocale( const css::lang::Locale& eLocale ) override;
156
    virtual css::lang::Locale SAL_CALL getLocale() override;
157
158
                                // XServiceName
159
    virtual OUString SAL_CALL getServiceName() override;
160
161
                                // XServiceInfo
162
    virtual OUString SAL_CALL getImplementationName() override;
163
    virtual sal_Bool SAL_CALL   supportsService( const OUString& ServiceName ) override;
164
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
165
166
167
    //  methods from own interfaces start here
168
169
170
    virtual double SAL_CALL getOptBarrier( double spot, double vol,
171
            double r, double rf, double T, double strike,
172
            double barrier_low, double barrier_up, double rebate,
173
            const OUString& put_call, const OUString& in_out,
174
            const OUString& continuous, const css::uno::Any& greek ) override;
175
176
   virtual double SAL_CALL getOptTouch( double spot, double vol,
177
            double r, double rf, double T,
178
            double barrier_low, double barrier_up,
179
            const OUString& for_dom, const OUString& in_out,
180
            const OUString& barriercont, const css::uno::Any& greekstr ) override;
181
182
   virtual double SAL_CALL getOptProbHit( double spot, double vol,
183
            double mu, double T,
184
            double barrier_low, double barrier_up ) override;
185
186
   virtual double SAL_CALL getOptProbInMoney( double spot, double vol,
187
            double mu, double T,
188
            double barrier_low, double barrier_up,
189
            const css::uno::Any& strikeval, const css::uno::Any& put_call ) override;
190
191
};
192
193
194
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */