Bump version to 5.0-14
[LibreOffice.git] / scaddins / source / pricing / pricing.hxx
blob316d0129dd9862351678cb08d47dff366fad875c
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 <com/sun/star/lang/XServiceName.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.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/implbase5.hxx>
39 #include <tools/resid.hxx>
40 #include <tools/rc.hxx>
41 #include <tools/resary.hxx>
43 #define RETURN_FINITE(d) if( ::rtl::math::isFinite( d ) ) return d; else throw css::lang::IllegalArgumentException()
47 namespace sca {
48 namespace pricing {
50 class ScaList
52 private:
53 static const sal_uInt32 nStartSize;
54 static const sal_uInt32 nIncrSize;
56 void** pData; // pointer array
57 sal_uInt32 nSize; // array size
58 sal_uInt32 nCount; // next index to be inserted at
59 sal_uInt32 nCurr; // current pos for iterations
61 void _Grow();
62 inline void Grow();
64 public:
65 ScaList();
66 virtual ~ScaList();
68 inline sal_uInt32 Count() const { return nCount; }
70 inline const void* GetObject( sal_uInt32 nIndex ) const
71 { return (nIndex < nCount) ? pData[ nIndex ] : NULL; }
73 inline void* First() { return nCount ? pData[ nCurr = 0 ] : NULL; }
74 inline void* Next() { return (nCurr + 1 < nCount) ? pData[ ++nCurr ] : NULL; }
76 inline void Append( void* pNew );
80 inline void ScaList::Grow()
82 if( nCount >= nSize )
83 _Grow();
86 inline void ScaList::Append( void* pNew )
88 Grow();
89 pData[ nCount++ ] = pNew;
93 class ScaStringList : protected ScaList
95 public:
96 inline ScaStringList() : ScaList() {};
97 virtual ~ScaStringList();
99 using ScaList::Count;
101 inline const OUString* Get( sal_uInt32 nIndex ) const;
103 inline OUString* First();
104 inline OUString* Next();
106 using ScaList::Append;
107 inline void Append( OUString* pNew );
108 inline void Append( const OUString& rNew );
112 inline const OUString* ScaStringList::Get( sal_uInt32 nIndex ) const
114 return static_cast< const OUString* >( ScaList::GetObject( nIndex ) );
117 inline OUString* ScaStringList::First()
119 return static_cast< OUString* >( ScaList::First() );
122 inline OUString* ScaStringList::Next()
124 return static_cast< OUString* >( ScaList::Next() );
127 inline void ScaStringList::Append( OUString* pNew )
129 ScaList::Append( pNew );
132 inline void ScaStringList::Append( const OUString& rNew )
134 ScaList::Append( new OUString( rNew ) );
138 class ScaResId : public ResId
140 public:
141 ScaResId( sal_uInt16 nResId, ResMgr& rResMgr );
145 class ScaResStringLoader : public Resource
147 private:
148 OUString aStr;
150 public:
151 inline ScaResStringLoader( sal_uInt16 nResId, sal_uInt16 nStrId, ResMgr& rResMgr );
153 inline const OUString& GetString() const { return aStr; }
158 inline ScaResStringLoader::ScaResStringLoader( sal_uInt16 nResId, sal_uInt16 nStrId, ResMgr& rResMgr ) :
159 Resource( ScaResId( nResId, rResMgr ) ),
160 aStr( ScaResId( nStrId, rResMgr ) )
162 FreeResource();
166 class ScaResStringArrLoader : public Resource
168 private:
169 ResStringArray aStrArray;
171 public:
172 inline ScaResStringArrLoader( sal_uInt16 nResId, sal_uInt16 nArrayId, ResMgr& rResMgr );
174 inline const ResStringArray& GetStringArray() const { return aStrArray; }
177 inline ScaResStringArrLoader::ScaResStringArrLoader( sal_uInt16 nResId, sal_uInt16 nArrayId, ResMgr& rResMgr ) :
178 Resource( ScaResId( nResId, rResMgr ) ),
179 aStrArray( ScaResId( nArrayId, rResMgr ) )
181 FreeResource();
185 class ScaResPublisher : public Resource
187 public:
188 inline ScaResPublisher( const ScaResId& rResId ) : Resource( rResId ) {}
190 inline bool IsAvailableRes( const ResId& rResId ) const
191 { return Resource::IsAvailableRes( rResId ); }
192 inline void FreeResource()
193 { Resource::FreeResource(); }
197 class ScaFuncRes : public Resource
199 public:
200 ScaFuncRes( ResId& rResId, ResMgr& rResMgr, sal_uInt16 nIndex, OUString& rRet );
204 enum ScaCategory
206 ScaCat_AddIn,
207 ScaCat_DateTime,
208 ScaCat_Text,
209 ScaCat_Finance,
210 ScaCat_Inf,
211 ScaCat_Math,
212 ScaCat_Tech
215 struct ScaFuncDataBase
217 const sal_Char* pIntName; // internal name (get***)
218 sal_uInt16 nUINameID; // resource ID to UI name
219 sal_uInt16 nDescrID; // resource ID to description, parameter names and ~ description
220 sal_uInt16 nCompListID; // resource ID to list of valid names
221 sal_uInt16 nParamCount; // number of named / described parameters
222 ScaCategory eCat; // function category
223 bool bDouble; // name already exist in Calc
224 bool bWithOpt; // first parameter is internal
227 class ScaFuncData
229 private:
230 OUString aIntName; // internal name (get***)
231 sal_uInt16 nUINameID; // resource ID to UI name
232 sal_uInt16 nDescrID; // leads also to parameter descriptions!
233 sal_uInt16 nCompListID; // resource ID to list of valid names
234 sal_uInt16 nParamCount; // num of parameters
235 ScaStringList aCompList; // list of all valid names
236 ScaCategory eCat; // function category
237 bool bDouble; // name already exist in Calc
238 bool bWithOpt; // first parameter is internal
240 public:
241 ScaFuncData( const ScaFuncDataBase& rBaseData, ResMgr& rRscMgr );
242 virtual ~ScaFuncData();
244 inline sal_uInt16 GetUINameID() const { return nUINameID; }
245 inline sal_uInt16 GetDescrID() const { return nDescrID; }
246 inline ScaCategory GetCategory() const { return eCat; }
247 inline bool IsDouble() const { return bDouble; }
248 inline bool HasIntParam() const { return bWithOpt; }
250 sal_uInt16 GetStrIndex( sal_uInt16 nParam ) const;
251 inline bool Is( const OUString& rCompare ) const
252 { return aIntName == rCompare; }
254 inline const ScaStringList& GetCompNameList() const { return aCompList; }
258 class ScaFuncDataList : private ScaList
260 OUString aLastName;
261 sal_uInt32 nLast;
263 public:
264 ScaFuncDataList( ResMgr& rResMgr );
265 virtual ~ScaFuncDataList();
267 using ScaList::Count;
269 inline const ScaFuncData* Get( sal_uInt32 nIndex ) const;
270 const ScaFuncData* Get( const OUString& rProgrammaticName ) const;
271 inline ScaFuncData* First();
272 inline ScaFuncData* Next();
274 using ScaList::Append;
275 inline void Append( ScaFuncData* pNew ) { ScaList::Append( pNew ); }
279 inline const ScaFuncData* ScaFuncDataList::Get( sal_uInt32 nIndex ) const
281 return static_cast< const ScaFuncData* >( ScaList::GetObject( nIndex ) );
284 inline ScaFuncData* ScaFuncDataList::First()
286 return static_cast< ScaFuncData* >( ScaList::First() );
289 inline ScaFuncData* ScaFuncDataList::Next()
291 return static_cast< ScaFuncData* >( ScaList::Next() );
294 } // namespace pricing
295 } // namespace sca
300 css::uno::Reference< css::uno::XInterface > SAL_CALL PricingFunctionAddIn_CreateInstance(
301 const css::uno::Reference< css::lang::XMultiServiceFactory >& );
304 // AddIn class for pricing functions
306 class ScaPricingAddIn : public ::cppu::WeakImplHelper5<
307 css::sheet::XAddIn,
308 css::sheet::XCompatibilityNames,
309 css::sheet::addin::XPricingFunctions,
310 css::lang::XServiceName,
311 css::lang::XServiceInfo >
313 private:
314 css::lang::Locale aFuncLoc;
315 css::lang::Locale* pDefLocales;
316 ResMgr* pResMgr;
317 sca::pricing::ScaFuncDataList* pFuncDataList;
320 void InitDefLocales();
321 const css::lang::Locale& GetLocale( sal_uInt32 nIndex );
322 ResMgr& GetResMgr() throw( css::uno::RuntimeException );
323 void InitData();
325 OUString GetDisplFuncStr( sal_uInt16 nResId ) throw( css::uno::RuntimeException );
326 OUString GetFuncDescrStr( sal_uInt16 nResId, sal_uInt16 nStrIndex ) throw( css::uno::RuntimeException );
328 public:
329 ScaPricingAddIn();
330 virtual ~ScaPricingAddIn();
332 static OUString getImplementationName_Static();
333 static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
335 // XAddIn
336 virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
337 virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
338 virtual OUString SAL_CALL getFunctionDescription( const OUString& aProgrammaticName ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
339 virtual OUString SAL_CALL getDisplayArgumentName( const OUString& aProgrammaticName, sal_Int32 nArgument ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
340 virtual OUString SAL_CALL getArgumentDescription( const OUString& aProgrammaticName, sal_Int32 nArgument ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
341 virtual OUString SAL_CALL getProgrammaticCategoryName( const OUString& aProgrammaticName ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
342 virtual OUString SAL_CALL getDisplayCategoryName( const OUString& aProgrammaticName ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
344 // XCompatibilityNames
345 virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames( const OUString& aProgrammaticName ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
347 // XLocalizable
348 virtual void SAL_CALL setLocale( const css::lang::Locale& eLocale ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
349 virtual css::lang::Locale SAL_CALL getLocale() throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
351 // XServiceName
352 virtual OUString SAL_CALL getServiceName() throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
354 // XServiceInfo
355 virtual OUString SAL_CALL getImplementationName() throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
356 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
357 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
360 // methods from own interfaces start here
363 virtual double SAL_CALL getOptBarrier( double spot, double vol,
364 double r, double rf, double T, double strike,
365 double barrier_low, double barrier_up, double rebate,
366 const OUString& put_call, const OUString& in_out,
367 const OUString& continuous, const css::uno::Any& greek ) throw( css::uno::RuntimeException, css::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
369 virtual double SAL_CALL getOptTouch( double spot, double vol,
370 double r, double rf, double T,
371 double barrier_low, double barrier_up,
372 const OUString& for_dom, const OUString& in_out,
373 const OUString& barriercont, const css::uno::Any& greekstr ) throw( css::uno::RuntimeException, css::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
375 virtual double SAL_CALL getOptProbHit( double spot, double vol,
376 double mu, double T,
377 double barrier_low, double barrier_up ) throw( css::uno::RuntimeException, css::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
379 virtual double SAL_CALL getOptProbInMoney( double spot, double vol,
380 double mu, double T,
381 double barrier_low, double barrier_up,
382 const css::uno::Any& strikeval, const css::uno::Any& put_call ) throw( css::uno::RuntimeException, css::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
387 #endif
389 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */