[Solved] How to return a matrix from Cpp add-in

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
saleem145
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

[Solved] How to return a matrix from Cpp add-in

Post 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.
Last edited by Hagar Delest on Sat Jul 07, 2012 10:35 am, edited 1 time in total.
Reason: tagged solved.
OpenOffice 3.4.0
Mac OS X 10.5.8
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: How to return a matrix from Cpp add-in

Post 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.
Apache OpenOffice 4.1.1
Windows XP
saleem145
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Re: How to return a matrix from Cpp add-in

Post 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
OpenOffice 3.4.0
Mac OS X 10.5.8
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: How to return a matrix from Cpp add-in

Post 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...
Apache OpenOffice 4.1.1
Windows XP
saleem145
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Re: How to return a matrix from Cpp add-in

Post by saleem145 »

Have it working!! Thanks again!

Saleem
OpenOffice 3.4.0
Mac OS X 10.5.8
Post Reply