[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Oct version of Mex Object Handle
From: |
Jose |
Subject: |
Re: Oct version of Mex Object Handle |
Date: |
Mon, 1 Oct 2012 18:46:37 +0300 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 |
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?
BR
Jose