help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Oct version of Mex Object Handle


From: Andy Buckle
Subject: Re: Oct version of Mex Object Handle
Date: Mon, 1 Oct 2012 16:49:51 +0100

On 1 October 2012 16:46, Jose <address@hidden> wrote:
> On 10/01/2012 04:41 PM, Jordi GutiƩrrez Hermoso wrote:
>> oct-files are in C++, the mex interface is in C. This is why the mex
>> interface requires a special way to handle C++ objects. For oct-files,
>> just pass around your C++ types like you would do so in normal C++.
>
> I am not sure I understand this correctly. Can you give me an example of how 
> can I pass around C++ types from/to octave command line?
>
> mex-handle basically stores pointers to C++ classes in octave matrixes, which 
> you can the pass from the command line to C++ through mex files. 
> "Translating" straight from the mex-handle into oct-files, if we wanted to do 
> the same I guess it could be something like this:
>
> ------
> MyClass foo;
> Matrix mPointer(1,1);
> *reinterpret_cast<MyClass**>(mPointer.fortran_vec())= &foo;
> --->mPointer passed to octave command line as an output value
> ...
> --->from octave command line, mPointer passed as an argument
> MyClass* foo = *reinterpret_cast<MyClass**>(mPointer.fortran_vec());
> ------
>
> This compiles, though I have not tested it. Is this correct? Is there a 
> better way?

Passing pointers obtained via fortan_vec is fast. There are other
ways, which are safer. Which is better depends on your priorities.

-- 
/* andy buckle */


reply via email to

[Prev in Thread] Current Thread [Next in Thread]