Mercurial > hg > octave-nkf
changeset 12127:b83162e8f402
fix nested indexed assignemnt in superclasses
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 22 Jan 2011 13:48:11 +0100 |
parents | 85f9a5b211fd |
children | e916491cbb99 |
files | src/ChangeLog src/ov-class.cc |
diffstat | 2 files changed, 58 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2011-01-22 Jaroslav Hajek <highegg@gmail.com> + + * ov-class.cc (octave_class::subsasgn): Find appropriate unique base + before trying any indexed assignment. + 2011-01-22 Konstantinos Poulios <logari81@googlemail.com> * graphics.h.in, graphics.cc (xmtick, ymtick, zmtick):
--- a/src/ov-class.cc +++ b/src/ov-class.cc @@ -573,6 +573,32 @@ } } + // Find the class in which this method resides before + // attempting to do the indexed assignment. + + std::string method_class = get_current_method_class (); + + octave_base_value *obvp = unique_parent_class (method_class); + if (obvp != this) + { + + if (obvp) + { + obvp->subsasgn (type, idx, rhs); + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + } + else + error ("malformed class"); + + return retval; + } + // FIXME -- this block of code is the same as the body of // octave_struct::subsasgn. Maybe it could be shared instead of // duplicated. @@ -766,38 +792,39 @@ case '.': { - // Find the class in which this method resides before - // attempting to access the requested field. - - std::string method_class = get_current_method_class (); - - octave_base_value *obvp = unique_parent_class (method_class); + octave_value_list key_idx = idx.front (); - if (obvp) - { - octave_value_list key_idx = idx.front (); + assert (key_idx.length () == 1); - assert (key_idx.length () == 1); - - std::string key = key_idx(0).string_value (); + std::string key = key_idx(0).string_value (); - if (! error_state) - { - obvp->assign (key, t_rhs); + if (t_rhs.is_cs_list ()) + { + Cell tmp_cell = Cell (t_rhs.list_value ()); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else - gripe_failed_assignment (); + // The shape of the RHS is irrelevant, we just want + // the number of elements to agree and to preserve the + // shape of the left hand side of the assignment. + + if (numel () == tmp_cell.numel ()) + tmp_cell = tmp_cell.reshape (dims ()); + + map.setfield (key, tmp_cell); } else - error ("malformed class"); + { + Cell tmp_cell(1, 1); + tmp_cell(0) = t_rhs.storable_value (); + map.setfield (key, tmp_cell); + } + + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); } break;