help-octave
[Top][All Lists]
Advanced

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

structures, lvalues and handle graphics


From: Nimrod Mesika
Subject: structures, lvalues and handle graphics
Date: Sat, 02 Sep 2000 22:57:36 +0200
User-agent: Mutt/1.2i

I'm trying to implement the following functionality (following jwe's
suggestion):

h = line(...) % or whatever constructor you choose
s = get(h);   % s is now some form of struct

s.Color='red';

The code I'm using looks like this:

octave_value Line::asStruct()
{
    Octave_map m;
    m["Type"] = octave_value("line");
    m["Color"] = octave_value(color);
    octave_value v(new octave_struct(m));
    return v;
}

The real problem, of course, is that I need to check the values
entered - make sure their type is correct, values are within range,
etc. Once the value has been changed the figure must be updated
accordingly.

Initially, I thought I'd subclass octave_value and create a few new
types: handle_string, handle_vector, handle_scalar. The new types
would carry a handle to the handle graphics object and their values
would be validated when modified.

The problem with this approach is that, usually, structure fields
are not modified but rather recreated with a new value. So unless
the user writes "s.Color(1:3)='red'" no validation checks would be
done and the object would not be updated.

Next, I tried creating a new handle_struct type. It is similar to
octave_struct, except lvalues are initialized with a chg_fcn. This
function is indeed called when one of the values is being modified
(and yes, even when they are replaced with a new octave_value
object).

BUT, the chg_fcn is called without any arguments. How do I get the
value of the object being modified? Subclassing octave_lvalue to
change the calls to chg_fcn is no good because no functions are
declared virtual.

A third idea (which I haven't tried yet) is to create a new type
which will work as a 'proxy' for the real value. This is similar to
the way octave_value holds an octave_value representation and it may
be possible to subclass octave_value to do just that.

Obviously, I'm not familiar enough with Octave so maybe I'm missing
something obvious.

Any ideas? jwe? others?

-- 
Nimrod.
http://www.geocities.com/rodd_27



-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.che.wisc.edu/octave/octave.html
How to fund new projects:  http://www.che.wisc.edu/octave/funding.html
Subscription information:  http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------



reply via email to

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