|
From: | jiaguo |
Subject: | Re: Question about subsref in a new data type |
Date: | Fri, 2 Jul 2004 13:23:26 -0500 |
Thanks for your suggestions. I found strange behavior when I test my subsasgn in octave. Basically, if I run 'obj.field=1' in command line or put it into a script file, it can correctly call my subsasgn. However, if I put it into a function file, octave will treat obj as a struct. The way I did is in that function, I first initialize the object, register the data type and operator and then call 'obj.field=1;', but then, obj becomes a struct. Please see test.m for my experiments. I attached my ov-apple class for reference. you can compile them using the Makefile. In my implementation, I set is_map() true. However, when I test the function file test.m, I traced the function calls in 'h.signature=100', and finally I found that in oct-lvalue::assign(), it calls octave_value::assign(), and in octave_value::assign(), it has such statements: if (! error_state) { if (type[0] == '.' && ! is_map ()) { octave_value tmp = Octave_map (); retval = tmp.subsasgn (type, idx, t_rhs); } else retval = subsasgn (type, idx, t_rhs); } and when I test is_map() in gdb, it is false. Can somebody tell me what will be different when we call from a script or from a function? If there is a bug in octave, where could it possibly be? Thanks, Jia ---- Original message ---- >Date: Thu, 1 Jul 2004 00:39:59 -0400 >From: Paul Kienzle <address@hidden> >Subject: Re: Question about subsref in a new data type >To: <address@hidden> > >On Jun 23, 2004, at 9:59 AM, <address@hidden> wrote: > >> Hi all, >> >> I am now adding a new data type into octave. I defined a >> subsasgn function in the new data type so that in the equation >> 'obj.field=1', the value 1 will be assigned to memeber >> 'field' in my class. In order to make it work, I also write >> method: >> bool is_map(void) const {return true;} >> >> By doing it, it works when I directly type 'obj.field=1' in >> the command line. However, if I put it into a .m file and >> call it from the .m file, octave cannot recognize my data type >> and treat obj as a struct. >> >> BTW, I couldn't find the example of subsref in the forge >> directory. > >there's a few, such as getfield/setfield in struct. I don't >know if they are still working though. There's also examples >in extra/mex, but that's kind of ugly code (not least since >structures have changed a couple of times since 2.1.36). > >> Does anybody have this problem before or any suggestions how >> to do subsref? > >I've muddled through, largely by examining code in the octave >source tree. I would recommend looking there (e.g., in src/ov-struct) >rather than octave-forge since octave-forge is full of cruft to support >older octave versions. > >A write-up on the wiki would be nice when you finally figure it out. > >- Paul >
Makefile
Description: Binary data
ov-apple.cc
Description: Binary data
ov-apple.h
Description: Binary data
test.m
Description: Binary data
[Prev in Thread] | Current Thread | [Next in Thread] |