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
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/implbase5.hxx>
38 #include <tools/resid.hxx>
39 #include <tools/rc.hxx>
40 #include <tools/resary.hxx>
42 #define RETURN_FINITE(d) if( ::rtl::math::isFinite( d ) ) return d; else throw css::lang::IllegalArgumentException()
52 static const sal_uInt32 nStartSize
;
53 static const sal_uInt32 nIncrSize
;
55 void** pData
; // pointer array
56 sal_uInt32 nSize
; // array size
57 sal_uInt32 nCount
; // next index to be inserted at
58 sal_uInt32 nCurr
; // current pos for iterations
67 inline sal_uInt32
Count() const { return nCount
; }
69 inline const void* GetObject( sal_uInt32 nIndex
) const
70 { return (nIndex
< nCount
) ? pData
[ nIndex
] : NULL
; }
72 inline void* First() { return nCount
? pData
[ nCurr
= 0 ] : NULL
; }
73 inline void* Next() { return (nCurr
+ 1 < nCount
) ? pData
[ ++nCurr
] : NULL
; }
75 inline void Append( void* pNew
);
79 inline void ScaList::Grow()
85 inline void ScaList::Append( void* pNew
)
88 pData
[ nCount
++ ] = pNew
;
92 class ScaStringList
: protected ScaList
95 inline ScaStringList() : ScaList() {};
96 virtual ~ScaStringList();
100 inline const OUString
* Get( sal_uInt32 nIndex
) const;
102 inline OUString
* First();
103 inline OUString
* Next();
105 using ScaList::Append
;
106 inline void Append( OUString
* pNew
);
107 inline void Append( const OUString
& rNew
);
111 inline const OUString
* ScaStringList::Get( sal_uInt32 nIndex
) const
113 return static_cast< const OUString
* >( ScaList::GetObject( nIndex
) );
116 inline OUString
* ScaStringList::First()
118 return static_cast< OUString
* >( ScaList::First() );
121 inline OUString
* ScaStringList::Next()
123 return static_cast< OUString
* >( ScaList::Next() );
126 inline void ScaStringList::Append( OUString
* pNew
)
128 ScaList::Append( pNew
);
131 inline void ScaStringList::Append( const OUString
& rNew
)
133 ScaList::Append( new OUString( rNew
) );
137 class ScaResId
: public ResId
140 ScaResId( sal_uInt16 nResId
, ResMgr
& rResMgr
);
144 class ScaResStringLoader
: public Resource
150 inline ScaResStringLoader( sal_uInt16 nResId
, sal_uInt16 nStrId
, ResMgr
& rResMgr
);
152 inline const OUString
& GetString() const { return aStr
; }
157 inline ScaResStringLoader::ScaResStringLoader( sal_uInt16 nResId
, sal_uInt16 nStrId
, ResMgr
& rResMgr
) :
158 Resource( ScaResId( nResId
, rResMgr
) ),
159 aStr( ScaResId( nStrId
, rResMgr
) )
165 class ScaResStringArrLoader
: public Resource
168 ResStringArray aStrArray
;
171 inline ScaResStringArrLoader( sal_uInt16 nResId
, sal_uInt16 nArrayId
, ResMgr
& rResMgr
);
173 inline const ResStringArray
& GetStringArray() const { return aStrArray
; }
176 inline ScaResStringArrLoader::ScaResStringArrLoader( sal_uInt16 nResId
, sal_uInt16 nArrayId
, ResMgr
& rResMgr
) :
177 Resource( ScaResId( nResId
, rResMgr
) ),
178 aStrArray( ScaResId( nArrayId
, rResMgr
) )
184 class ScaResPublisher
: public Resource
187 inline ScaResPublisher( const ScaResId
& rResId
) : Resource( rResId
) {}
189 inline bool IsAvailableRes( const ResId
& rResId
) const
190 { return Resource::IsAvailableRes( rResId
); }
191 inline void FreeResource()
192 { Resource::FreeResource(); }
196 class ScaFuncRes
: public Resource
199 ScaFuncRes( ResId
& rResId
, ResMgr
& rResMgr
, sal_uInt16 nIndex
, OUString
& rRet
);
214 struct ScaFuncDataBase
216 const sal_Char
* pIntName
; // internal name (get***)
217 sal_uInt16 nUINameID
; // resource ID to UI name
218 sal_uInt16 nDescrID
; // resource ID to description, parameter names and ~ description
219 sal_uInt16 nCompListID
; // resource ID to list of valid names
220 sal_uInt16 nParamCount
; // number of named / described parameters
221 ScaCategory eCat
; // function category
222 bool bDouble
; // name already exist in Calc
223 bool bWithOpt
; // first parameter is internal
229 OUString aIntName
; // internal name (get***)
230 sal_uInt16 nUINameID
; // resource ID to UI name
231 sal_uInt16 nDescrID
; // leads also to parameter descriptions!
232 sal_uInt16 nCompListID
; // resource ID to list of valid names
233 sal_uInt16 nParamCount
; // num of parameters
234 ScaStringList aCompList
; // list of all valid names
235 ScaCategory eCat
; // function category
236 bool bDouble
; // name already exist in Calc
237 bool bWithOpt
; // first parameter is internal
240 ScaFuncData( const ScaFuncDataBase
& rBaseData
, ResMgr
& rRscMgr
);
241 virtual ~ScaFuncData();
243 inline sal_uInt16
GetUINameID() const { return nUINameID
; }
244 inline sal_uInt16
GetDescrID() const { return nDescrID
; }
245 inline ScaCategory
GetCategory() const { return eCat
; }
246 inline bool IsDouble() const { return bDouble
; }
247 inline bool HasIntParam() const { return bWithOpt
; }
249 sal_uInt16
GetStrIndex( sal_uInt16 nParam
) const;
250 inline bool Is( const OUString
& rCompare
) const
251 { return aIntName
== rCompare
; }
253 inline const ScaStringList
& GetCompNameList() const { return aCompList
; }
257 class ScaFuncDataList
: private ScaList
263 ScaFuncDataList( ResMgr
& rResMgr
);
264 virtual ~ScaFuncDataList();
266 using ScaList::Count
;
268 inline const ScaFuncData
* Get( sal_uInt32 nIndex
) const;
269 const ScaFuncData
* Get( const OUString
& rProgrammaticName
) const;
270 inline ScaFuncData
* First();
271 inline ScaFuncData
* Next();
273 using ScaList::Append
;
274 inline void Append( ScaFuncData
* pNew
) { ScaList::Append( pNew
); }
278 inline const ScaFuncData
* ScaFuncDataList::Get( sal_uInt32 nIndex
) const
280 return static_cast< const ScaFuncData
* >( ScaList::GetObject( nIndex
) );
283 inline ScaFuncData
* ScaFuncDataList::First()
285 return static_cast< ScaFuncData
* >( ScaList::First() );
288 inline ScaFuncData
* ScaFuncDataList::Next()
290 return static_cast< ScaFuncData
* >( ScaList::Next() );
293 } // namespace pricing
299 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
PricingFunctionAddIn_CreateInstance(
300 const css::uno::Reference
< css::lang::XMultiServiceFactory
>& );
303 // AddIn class for pricing functions
305 class ScaPricingAddIn
: public ::cppu::WeakImplHelper5
<
307 css::sheet::XCompatibilityNames
,
308 css::sheet::addin::XPricingFunctions
,
309 css::lang::XServiceName
,
310 css::lang::XServiceInfo
>
313 css::lang::Locale aFuncLoc
;
314 css::lang::Locale
* pDefLocales
;
316 sca::pricing::ScaFuncDataList
* pFuncDataList
;
319 void InitDefLocales();
320 const css::lang::Locale
& GetLocale( sal_uInt32 nIndex
);
321 ResMgr
& GetResMgr() throw( css::uno::RuntimeException
);
324 OUString
GetDisplFuncStr( sal_uInt16 nResId
) throw( css::uno::RuntimeException
);
325 OUString
GetFuncDescrStr( sal_uInt16 nResId
, sal_uInt16 nStrIndex
) throw( css::uno::RuntimeException
);
329 virtual ~ScaPricingAddIn();
331 static OUString
getImplementationName_Static();
332 static css::uno::Sequence
< OUString
> getSupportedServiceNames_Static();
335 virtual OUString SAL_CALL
getProgrammaticFuntionName( const OUString
& aDisplayName
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
336 virtual OUString SAL_CALL
getDisplayFunctionName( const OUString
& aProgrammaticName
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
337 virtual OUString SAL_CALL
getFunctionDescription( const OUString
& aProgrammaticName
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
338 virtual OUString SAL_CALL
getDisplayArgumentName( const OUString
& aProgrammaticName
, sal_Int32 nArgument
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
339 virtual OUString SAL_CALL
getArgumentDescription( const OUString
& aProgrammaticName
, sal_Int32 nArgument
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
340 virtual OUString SAL_CALL
getProgrammaticCategoryName( const OUString
& aProgrammaticName
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
341 virtual OUString SAL_CALL
getDisplayCategoryName( const OUString
& aProgrammaticName
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
343 // XCompatibilityNames
344 virtual css::uno::Sequence
< css::sheet::LocalizedName
> SAL_CALL
getCompatibilityNames( const OUString
& aProgrammaticName
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
347 virtual void SAL_CALL
setLocale( const css::lang::Locale
& eLocale
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
348 virtual css::lang::Locale SAL_CALL
getLocale() throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
351 virtual OUString SAL_CALL
getServiceName() throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
354 virtual OUString SAL_CALL
getImplementationName() throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
355 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
356 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
359 // methods from own interfaces start here
362 virtual double SAL_CALL
getOptBarrier( double spot
, double vol
,
363 double r
, double rf
, double T
, double strike
,
364 double barrier_low
, double barrier_up
, double rebate
,
365 const OUString
& put_call
, const OUString
& in_out
,
366 const OUString
& continuous
, const css::uno::Any
& greek
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
, std::exception
) SAL_OVERRIDE
;
368 virtual double SAL_CALL
getOptTouch( double spot
, double vol
,
369 double r
, double rf
, double T
,
370 double barrier_low
, double barrier_up
,
371 const OUString
& for_dom
, const OUString
& in_out
,
372 const OUString
& barriercont
, const css::uno::Any
& greekstr
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
, std::exception
) SAL_OVERRIDE
;
374 virtual double SAL_CALL
getOptProbHit( double spot
, double vol
,
376 double barrier_low
, double barrier_up
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
, std::exception
) SAL_OVERRIDE
;
378 virtual double SAL_CALL
getOptProbInMoney( double spot
, double vol
,
380 double barrier_low
, double barrier_up
,
381 const css::uno::Any
& strikeval
, const css::uno::Any
& put_call
) throw( css::uno::RuntimeException
, css::lang::IllegalArgumentException
, std::exception
) SAL_OVERRIDE
;
388 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */