Page 1 of 1
[Solved] How to return a matrix from Cpp add-in
Posted: Fri Jul 06, 2012 1:41 am
by saleem145
Hello,
I have made a lot of progress with the complete cpp add-in. I would now like to add a routine that returns a two dimensional matrix. To compound the problem the columns will be of different datatypes -- some strings, some numbers, etc....
Any points would be appreciated!!
Saleem
BTW: I will also need to make the corresponding change to the idl file.
Re: How to return a matrix from Cpp add-in
Posted: Fri Jul 06, 2012 3:34 am
by Charlie Young
saleem145 wrote:Hello,
I have made a lot of progress with the complete cpp add-in. I would now like to add a routine that returns a two dimensional matrix. To compound the problem the columns will be of different datatypes -- some strings, some numbers, etc....
Any points would be appreciated!!
Saleem
BTW: I will also need to make the corresponding change to the idl file.
There is no big problem with the mixed data, you want to use Sequence<Sequence<Any>> as the return type, and in the idl that just means use sequence< sequence< any > >.
The nested sequences work as as both returns and arguments. Sometimes in the documentation and the .rdb this shows up as [][]Any or [][]any or any[][].
There are tricks for allocating the sequences in the c++ program, but they aren't hard.
Re: How to return a matrix from Cpp add-in
Posted: Fri Jul 06, 2012 6:05 pm
by saleem145
Hello,
I am trying the following code.
My idl looks like
#include <com/sun/star/uno/XInterface.idl>
#include <com/sun/star/lang/IllegalArgumentException.idl>
Code: Select all
module my_module
{
interface XSomething
{
string methodOne( [in] string val );
double methodTwo();
sequence< double > methodThree();
void initialize_dataset( [in] long start_date, [in] long end_date);
};
service MyService1 : XSomething;
};
Following code was inserted into service1_impl.cxx
Code: Select all
virtual Sequence< double > SAL_CALL methodThree( )
throw (RuntimeException);
Code: Select all
Sequence< double > MyService1Impl::methodThree( )
throw (RuntimeException)
{
Sequence< double > result(2);
result[0] = 1;
result[1] = 3;
return result;
}
Appropriate entry was added to xcu file. I am getting #VALUE errors.
I added the following code to TestComponent.cxx
Code: Select all
Sequence< double > res = xSomething->methodThree();
fprintf(stdout,"\nCreate new instance of MyService1\nCall of XSomething.methThree at MyService1 = %f %f", res[0], res[1]);
Upon running it I get the following message
caught UNO exception: Binary URP bridge disposed during call
Any insights would be appreciated as always!! Thanks in advance for your help!
Saleem
Re: How to return a matrix from Cpp add-in
Posted: Fri Jul 06, 2012 9:42 pm
by Charlie Young
Although you don't need to implement
XAddin, I should have pointed out the the documentation there mentions the allowed argument and return types. You may not return double[], but you may return double[][], so the solution for your methodthree in the .idl is to do
Code: Select all
sequence< sequence< double > > methodThree();
and then code it as
Code: Select all
Sequence<Sequence< double >> MyService1Impl::methodThree( )
throw (RuntimeException)
{
Sequence <Sequence< double >> result(2);
result[0] = Sequence< double >(1);
result[1] = Sequence< double >(1);
result[0][0] = 1;
result[1][0] = 3;
return result;
}
But don't forget that it needs to be entered as an array formula! This shouldn't affect the CalcAddin.xcu though.
I haven't explored your fprintf problem yet, but I suspect there just isn't a stdout to print to from this program. When debugging these things, I have resorted to having the program print stuff to a text file, then look at the file afterwards, but I can't find the code I used for that at the moment. Stay tuned...
Re: How to return a matrix from Cpp add-in
Posted: Fri Jul 06, 2012 11:05 pm
by saleem145
Have it working!! Thanks again!
Saleem