document how to derive octave_value class

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

document how to derive octave_value class

Pantxo
Hi,

I find my self trying to declare a new class in the interpreter, derived from octave_value. I can see no mention of the way to do so in the manual. Am I wrong ?

I have found several examples in octave-forge but it would be useful (at least for me and those whose c++ proficiency is not that good) to have a very bare bones example in the manual.

Preparing this could be a good exercise for me, if you are interested.

Pantxo

Reply | Threaded
Open this post in threaded view
|

Re: document how to derive octave_value class

Andreas Weber-3
Am 13.01.2014 19:26, schrieb Pantxo Diribarne:
> I find my self trying to declare a new class in the interpreter, derived
> from octave_value. I can see no mention of the way to do so in the
> manual. Am I wrong ?

There is examples/make_int.cc which shows the basic concepts.
HTH Andy

Reply | Threaded
Open this post in threaded view
|

Re: document how to derive octave_value class

Pantxo
Le lun. 13 janv. 2014 21:34:32 CET, Andreas Weber a écrit :
> Am 13.01.2014 19:26, schrieb Pantxo Diribarne:
>> I find my self trying to declare a new class in the interpreter, derived
>> from octave_value. I can see no mention of the way to do so in the
>> manual. Am I wrong ?
>
> There is examples/make_int.cc which shows the basic concepts.
> HTH Andy
>

Thanks. It's a bit to exhaustive for my concern, but I am shure I will
find what I want :-)

Pantxo
Reply | Threaded
Open this post in threaded view
|

Re: document how to derive octave_value class

Andreas Weber-3
Hi Pantxo,

Am 13.01.2014 22:16, schrieb Pantxo Diribarne:

> Le lun. 13 janv. 2014 21:34:32 CET, Andreas Weber a écrit :
>> Am 13.01.2014 19:26, schrieb Pantxo Diribarne:
>>> I find my self trying to declare a new class in the interpreter, derived
>>> from octave_value. I can see no mention of the way to do so in the
>>> manual. Am I wrong ?
>>
>> There is examples/make_int.cc which shows the basic concepts.
>> HTH Andy
>
> Thanks. It's a bit to exhaustive for my concern, but I am shure I will
> find what I want :-)

I don't know if there is a better starting point than this. Perhaps
someone else? But I would appreciate if you could write down your
learning process or experiences and document it.

For me, these 2 resources was a big help:
http://www.gnu.org/software/octave/doc/interpreter/Oct_002dFiles.html#Oct_002dFiles
http://octave.sourceforge.net/doxygen/html/index.html

--Andy

Reply | Threaded
Open this post in threaded view
|

Re: document how to derive octave_value class

Pantxo
Le lun. 13 janv. 2014 22:33:03 CET, Andreas Weber a écrit :

> Hi Pantxo,
>
> Am 13.01.2014 22:16, schrieb Pantxo Diribarne:
>> Le lun. 13 janv. 2014 21:34:32 CET, Andreas Weber a écrit :
>>> Am 13.01.2014 19:26, schrieb Pantxo Diribarne:
>>>> I find my self trying to declare a new class in the interpreter, derived
>>>> from octave_value. I can see no mention of the way to do so in the
>>>> manual. Am I wrong ?
>>>
>>> There is examples/make_int.cc which shows the basic concepts.
>>> HTH Andy
>>
>> Thanks. It's a bit to exhaustive for my concern, but I am shure I will
>> find what I want :-)
>
> I don't know if there is a better starting point than this. Perhaps
> someone else? But I would appreciate if you could write down your
> learning process or experiences and document it.
>
> For me, these 2 resources was a big help:
> http://www.gnu.org/software/octave/doc/interpreter/Oct_002dFiles.html#Oct_002dFiles
> http://octave.sourceforge.net/doxygen/html/index.html
>
> --Andy
>

I generally use oct files to interface octave to external libraries,
and I also find that the corresponding documentation is a very big help.
But there is no counterpart in the documentation for defining an octave
class (neither a mention of make_int.cc).

Anyway, I will ask on the help mailing list now that I have a starting
point.
Thanks

Pantxo


Reply | Threaded
Open this post in threaded view
|

Re: document how to derive octave_value class

Andreas Weber-2
In reply to this post by Pantxo
On 13.01.2014 19:26, Pantxo Diribarne wrote:
> I find my self trying to declare a new class in the interpreter, derived
> from octave_value.

Hi Pantxo,
I think another small example to have a look at is octave-forge
octave-sockets/sockets.cc. -- Andy
Reply | Threaded
Open this post in threaded view
|

Re: document how to derive octave_value class

c.-2

On 15 Jan 2014, at 08:56, Andreas Weber <[hidden email]> wrote:

> On 13.01.2014 19:26, Pantxo Diribarne wrote:
>> I find my self trying to declare a new class in the interpreter, derived
>> from octave_value.
>
> Hi Pantxo,
> I think another small example to have a look at is octave-forge
> octave-sockets/sockets.cc. -- Andy

other examples are the class in the mpi package representing a communicator
and the classes wrapping FEnics objects in fem-fenics.
c.
Reply | Threaded
Open this post in threaded view
|

Re: document how to derive octave_value class

John Swensen-3
In reply to this post by Andreas Weber-2
On Wed, Jan 15, 2014 at 2:56 AM, Andreas Weber <[hidden email]> wrote:
On 13.01.2014 19:26, Pantxo Diribarne wrote:
> I find my self trying to declare a new class in the interpreter, derived
> from octave_value.

Hi Pantxo,
I think another small example to have a look at is octave-forge
octave-sockets/sockets.cc. -- Andy

Someone had talked about patching the sockets class to get rid of the socket being represented by a custom class. When I originally wrote that, I was trying to learn Oct files and the use of a custom class probably really isn't necessary (could have just used an integer). 

So, if you look at the socket package sources and it doesn't look like there is a new class in there anymore, then someone must have made and applied the patch I speak of.

John Swensen
Reply | Threaded
Open this post in threaded view
|

Re: document how to derive octave_value class

Pantxo
Le 15/01/2014 15:21, John Swensen a écrit :
On Wed, Jan 15, 2014 at 2:56 AM, Andreas Weber <[hidden email]> wrote:
On 13.01.2014 19:26, Pantxo Diribarne wrote:
> I find my self trying to declare a new class in the interpreter, derived
> from octave_value.

Hi Pantxo,
I think another small example to have a look at is octave-forge
octave-sockets/sockets.cc. -- Andy

Someone had talked about patching the sockets class to get rid of the socket being represented by a custom class. When I originally wrote that, I was trying to learn Oct files and the use of a custom class probably really isn't necessary (could have just used an integer). 

So, if you look at the socket package sources and it doesn't look like there is a new class in there anymore, then someone must have made and applied the patch I speak of.

John Swensen
Thank you all for those suggestions.
I have tried to make the bare bones example (no operator declaration  macro, only the minimum) that I was hoping to find. There is only constructor, destructor for the class and the DEFUN interface (see attached). Unfortunately It doesn't work, the object is destroyed right before being returned to the interpreter.

I compiled it using "mkoctfile hello_obj.cc", then in octave I see :

octave:1> aa = hello_obj ();
Hello!
octave_hello installed at type-id = 54
Hello!
good bye!
error: value on right hand side of assignment is undefined

Should I now continue on the help list ?

Pantxo

hello_obj.cc (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: document how to derive octave_value class

Andreas Weber-3
Am 15.01.2014 19:17, schrieb Pantxo Diribarne:

> Thank you all for those suggestions.
> I have tried to make the bare bones example (no operator declaration
> macro, only the minimum) that I was hoping to find. There is only
> constructor, destructor for the class and the DEFUN interface (see
> attached). Unfortunately It doesn't work, the object is destroyed right
> before being returned to the interpreter.

I think you have to also add to your class:
  bool is_constant (void) const
  {
    return true;
  }
  bool is_defined (void) const
  {
    return true;
  }
-- Andy
Reply | Threaded
Open this post in threaded view
|

Re: document how to derive octave_value class

Pantxo
Thanks Andy, it now works.

Pantxo


2014/1/16 Andreas Weber <[hidden email]>
Am 15.01.2014 19:17, schrieb Pantxo Diribarne:

> Thank you all for those suggestions.
> I have tried to make the bare bones example (no operator declaration
> macro, only the minimum) that I was hoping to find. There is only
> constructor, destructor for the class and the DEFUN interface (see
> attached). Unfortunately It doesn't work, the object is destroyed right
> before being returned to the interpreter.

I think you have to also add to your class:
  bool is_constant (void) const
  {
    return true;
  }
  bool is_defined (void) const
  {
    return true;
  }
-- Andy