Mercurial > hg > octave-nkf
diff libinterp/octave-value/ov-classdef.cc @ 18450:6e3344111522
Implement subsasgn overloading in classdef
* ov-classdef.cc (octave_classdef::subsasgn): Look for overloaded
method "subsasgn" when not in a class method or a builtin call.
* ov-classdef.h (to_cdef, to_cdef_ref): Turn warning into error when
the casted object is not of type "object".
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Fri, 24 Jan 2014 22:17:29 -0500 |
parents | 9ca314e79956 |
children | 642fc1165f3f |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-classdef.cc +++ b/libinterp/octave-value/ov-classdef.cc @@ -959,9 +959,45 @@ const std::list<octave_value_list>& idx, const octave_value& rhs) { - // FIXME: should check "subsasgn" method first - - return object.subsasgn (type, idx, rhs); + octave_value retval; + + cdef_class cls = object.get_class (); + + if (! in_class_method (cls) && ! called_from_builtin ()) + { + cdef_method meth = cls.find_method ("subsasgn"); + + if (meth.ok ()) + { + octave_value_list args; + + args(1) = make_idx_args (type, idx, "subsasgn"); + + if (! error_state) + { + count++; + args(0) = octave_value (this); + args(2) = rhs; + + octave_value_list retlist; + + retlist = meth.execute (args, 1, true, "subsasgn"); + + if (! error_state) + { + if (retlist.length () > 0) + retval = retlist(0); + else + ::error ("overloaded method `subsasgn' did not return any value"); + } + } + } + } + + if (! error_state && ! retval.is_defined ()) + retval = object.subsasgn (type, idx, rhs); + + return retval; } octave_value