Mercurial > octave-nkf
comparison libinterp/octave-value/ov-classdef.cc @ 18382: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 |
comparison
equal
deleted
inserted
replaced
18380:b48391da83fc | 18382:6e3344111522 |
---|---|
957 octave_value | 957 octave_value |
958 octave_classdef::subsasgn (const std::string& type, | 958 octave_classdef::subsasgn (const std::string& type, |
959 const std::list<octave_value_list>& idx, | 959 const std::list<octave_value_list>& idx, |
960 const octave_value& rhs) | 960 const octave_value& rhs) |
961 { | 961 { |
962 // FIXME: should check "subsasgn" method first | 962 octave_value retval; |
963 | 963 |
964 return object.subsasgn (type, idx, rhs); | 964 cdef_class cls = object.get_class (); |
965 | |
966 if (! in_class_method (cls) && ! called_from_builtin ()) | |
967 { | |
968 cdef_method meth = cls.find_method ("subsasgn"); | |
969 | |
970 if (meth.ok ()) | |
971 { | |
972 octave_value_list args; | |
973 | |
974 args(1) = make_idx_args (type, idx, "subsasgn"); | |
975 | |
976 if (! error_state) | |
977 { | |
978 count++; | |
979 args(0) = octave_value (this); | |
980 args(2) = rhs; | |
981 | |
982 octave_value_list retlist; | |
983 | |
984 retlist = meth.execute (args, 1, true, "subsasgn"); | |
985 | |
986 if (! error_state) | |
987 { | |
988 if (retlist.length () > 0) | |
989 retval = retlist(0); | |
990 else | |
991 ::error ("overloaded method `subsasgn' did not return any value"); | |
992 } | |
993 } | |
994 } | |
995 } | |
996 | |
997 if (! error_state && ! retval.is_defined ()) | |
998 retval = object.subsasgn (type, idx, rhs); | |
999 | |
1000 return retval; | |
965 } | 1001 } |
966 | 1002 |
967 octave_value | 1003 octave_value |
968 octave_classdef::undef_subsasgn (const std::string& type, | 1004 octave_classdef::undef_subsasgn (const std::string& type, |
969 const std::list<octave_value_list>& idx, | 1005 const std::list<octave_value_list>& idx, |