SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
Posted: Thu Feb 02, 2006 10:10 am Post subject: Interfacing GSL with an add-in (C++) |
|
|
This thread is related to Add-In in C++ [url]http://www.oooforum.org/forum/viewtopic.phtml?t=29552[/url]
Our goal is to interface a dynamic library GSL (GNU Scientific Library) with OOoCalc and OOoBasic. This way is typical for Linux. (I think there is an other way under Windows at least with OOoBasic because you can call directly a dll file)
Here is the IDL file :
| Code: |
// IDL
module my_module
{
interface XSomething : com::sun::star::uno::XInterface
{
string methodOne( [in] string val );
string methodTwo( [in] string val );
long methodThree( [in] sequence< sequence< long > > aValList );
sequence< sequence< long > > methodFour( [in] sequence< sequence< long > > aValList );
sequence< sequence< double > > poly_complex_solve(
[in] sequence< sequence< double > > aValList );
};
service MyService2
{
interface XSomething;
interface com::sun::star::lang::XInitialization;
interface com::sun::star::lang::XServiceName;
interface com::sun::star::sheet::XAddIn;
};
}; |
The new method is "poly_complex_solve" which call in fact gsl_poly_complex_solve. The corresponding C++ code is :
| Code: |
// C++
...
#include <gsl/gsl_poly.h>
...
Sequence< Sequence< double > > MyService2Impl::poly_complex_solve(
const Sequence< Sequence< double > > &aValList )throw (RuntimeException)
{
sal_Int32 nE1 = aValList.getLength();
sal_Int32 nE2;
Sequence< double > rList = aValList[ 0 ];
nE2 = rList.getLength();
double table[nE1][nE2];
for( sal_Int32 n1 = 0 ; n1 < nE1; n1++ )
{
for (sal_Int32 n2=0;n2<nE2;n2++)
table[n1][n2]=aValList[n1][n2];
}
// I have a 2D nE1xnE2 table here
if (nE1==1){ // coefs à l'horizontal
double z[(nE2-1)*2];
gsl_poly_complex_workspace * w = gsl_poly_complex_workspace_alloc(nE2);
gsl_poly_complex_solve(table[0],nE2,w,z);
gsl_poly_complex_workspace_free(w);
Sequence< double > solList1D(2);
Sequence< Sequence< double > > solList2D(nE2-1);
for( int j=0;j<((nE2-1)<<1);j+=2){
for( int i=0; i<2 ; i++){
solList1D[i]=z[i+j];
}
solList2D[j>>1]=solList1D;
}
return solList2D;
} else
if (nE2==1){ // vertical : doesn't work at the moment
Sequence< Sequence< double > > temp = aValList;//Error: return the entry
return temp;
} else {
//Error: return the entry
Sequence< Sequence< double > > temp = aValList; // retour à l'envoyeur
return temp;
}
} |
which only works if polynom coefficients are put horizontally.
Of course you have to modify
| Code: |
// C++
OUString SAL_CALL MyService2Impl::getDisplayFunctionName( const OUString& aProgrammaticName ) throw( uno::RuntimeException )
{
OUString aProgName, aRet;
aProgName = aProgrammaticName;
if (aProgName.equalsAscii("methodOne")) aRet = OUString::createFromAscii("method1");
if (aProgName.equalsAscii("methodTwo")) aRet = OUString::createFromAscii("method2");
if (aProgName.equalsAscii("methodThree")) aRet = OUString::createFromAscii("method3");
if (aProgName.equalsAscii("methodFour")) aRet = OUString::createFromAscii("method4");
if (aProgName.equalsAscii("poly_complex_solve")) aRet =
OUString::createFromAscii("poly_complex_solve");
return aRet;
}
....
|
and also the makefile creating the add-in (linker part) :
| Code: |
....
ifeq "$(OS)" "WIN"
$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) $(OUT_COMP_GEN)/%.def
-$(MKDIR) $(subst /,$(PS),$(@D))
$(LINK) $(LIBRARY_LINK_FLAGS) /OUT:$@ /MAP:$(OUT_COMP_GEN)/$(subst $(SHAREDLIB_EXT),map,$(@F)) \
/DEF:$(OUT_COMP_GEN)/$(subst $(SHAREDLIB_EXT),def,$(@F)) $(SLOFILES) \
$(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) msvcrt.lib kernel32.lib
else
$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES)
-$(MKDIR) $(subst /,$(PS),$(@D))
$(LINK) $(LIBRARY_LINK_FLAGS) $(LINK_LIBS) -o $@ $^\
$(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) $(STC++LIB) -lgsl -lgslcblas -lm
# $(CPPUHELPERLIB)
endif
.... |
where you can see the new libraries added (-lgsl -lgslcblas -lm)
More in my document (chapter 14) OOo version
An other example of interfacing with shared library is given by Eric Elhers :
The project is QuantLibAddin - [url]http://quantlib.org/quantlibaddin/ [/url]
It's an integration of QuantLib, an open source analytics library, to
various platforms including Calc.
Notes on how to build and install QuantLibAddin for Calc are at this link http://quantlib.org/quantlibaddin/calc.html
On the QuantLib downloads page [url]
http://sourceforge.net/project/showfiles.php?group_id=12740 [/url]
You can download QuantLibAddin and see the source code of the Calc addin.
To run QuantLibAddin you need to build
QuantLib - [url]http://quantlib.org [/url]
log4cxx - [url]http://logging.apache.org/log4cxx/ [/url]
ObjectHandler - [url]http://quantlib.org/objecthandler [/url]
QuantLibAddin - [url]http://quantlib.org/quantlibaddin/ [/url] _________________ Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide |
|