[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Easy way to interpret octave_value as XXX?
From: |
Rik |
Subject: |
Re: Easy way to interpret octave_value as XXX? |
Date: |
Tue, 18 Dec 2012 08:17:36 -0800 |
On 12/18/2012 07:46 AM, John W. Eaton wrote:
> On 17-Dec-2012, Michael Goffioul wrote:
>
> | On Mon, Dec 17, 2012 at 5:43 PM, Rik <address@hidden> wrote:
> |
> | 12/17/12
> |
> | John,
> |
> | I have an octave_value that is the input to a DEFUN function. I have
> | verified that the object is in fact of class "octave_java". Is there an
> | easy way to interpret the octave_value as being of class octave_java and
> | calling a method from the octave_java class?
> |
> | Or is the real, but longer way, to declare a new function in ov-base.h
> | that
> | performs the interpretation. And then in the DEFUN function I need to
> | declare a new instance of the octave_java class.
> |
> | octave_java oct_jobj = args(0).octave_java_value ();
> | oct_jobj.method_name ();
>
> I would not expose the representation class as a value. If you want
> to go this route, then look at the way the octave_function_value
> method works to return the rep pointer as a pointer to an
> octave_function object.
>
> Which functions from the octave_java class do you want to expose?
>
> | The java.cc code used to do something like (see TO_JAVA macro):
> |
> | dynamic_cast<octave_java*> ((obj).internal_rep ())
> |
> | Not very clean, but it was only used internally anyway. This also returns a
> | pointer, not a plain object. Having a method
> octave_value::octave_java_value()
> | returning a plain octave_java is technically possible: the octave_java class
> | handles copy, by referencing the underlying Java object.
>
> Right, this is a reasonable way to do the job.
12/18/12
John,
I used Michael's solution here
(http://hg.savannah.gnu.org/hgweb/octave/rev/317f4857c1e1). I was
modifying class() to return the true Java class name rather than merely
"octave_java". It was a one-liner call to jobj->java_class_name () as soon
as I actually had it coerced into the correct class.
--Rik