Mercurial > hg > octave-lyh
changeset 7651:443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 26 Mar 2008 22:09:42 -0400 |
parents | eb7bdde776f2 |
children | b5731e43283a |
files | src/ChangeLog src/ov-base-mat.h src/ov-base-scalar.h src/ov-base-sparse.h src/ov-builtin.h src/ov-cell.cc src/ov-cell.h src/ov-class.h src/ov-fcn-handle.h src/ov-list.h src/ov-mex-fcn.h src/ov-range.h src/ov-struct.cc src/ov-struct.h src/ov-usr-fcn.h src/ov.cc |
diffstat | 16 files changed, 107 insertions(+), 88 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,43 @@ 2008-03-26 John W. Eaton <jwe@octave.org> + * ov-range.h (octave_range::subsref (const std::string&, + const std::list<octave_value_list>&, int)): + Forward to simple subsref. + * ov-base-sparse.h (octave_base_sparse<T>::subsref (const std::string&, + const std::list<octave_value_list>&, int)): Likewise. + * ov-base-scalar.h (octave_base_sparse<T>::subsref (const std::string&, + const std::list<octave_value_list>&, int)): Likewise. + * ov-base-matrix.h (octave_base_matrix<T>::subsref (const std::string&, + const std::list<octave_value_list>&, int)): Likewise. + + * ov-struct.cc, ov-cell.h (octave_cell::subsref (const + std::string&, const std::list<octave_value_list>&, int)): + Define nargout version of subsref instead of simple version. + * ov-struct.cc, ov-struct.h (octave_struct::subsref (const + std::string&, const std::list<octave_value_list>&, int)): + Define nargout version of subsref instead of simple version. + + * ov-builtin.h (octave_builtin::subsref (const std::string&, + const std::list<octave_value_list>&): Forward to nargout subsref. + * ov-cell.h (octave_cell::subsref (const std::string&, + const std::list<octave_value_list>&)): + * ov-class.h (octave_class::subsref (const std::string&, + const std::list<octave_value_list>&): Likewise. + * ov-fcn-handle.h (octave_fcn_handle::subsref (const std::string&, + const std::list<octave_value_list>&): Likewise. + * ov-list.h (octave_list::subsref (const std::string&, + const std::list<octave_value_list>&): Likewise. + * ov-mex-fcn.h (octave_mex_function::subsref (const std::string&, + const std::list<octave_value_list>&): Likewise. + * ov-struct.h (octave_struct::subsref (const std::string&, + const std::list<octave_value_list>&)): + * ov-usr-fcn.h (octave_user_function::subsref (const std::string&, + const std::list<octave_value_list>&): Likewise. + + * ov.cc (octave_value::subsref): Use value of nargout instead of + is_constant method to decide which type of subsref method to call. + (octave_value::assign): Always call simple subref method here. + * DLD-FUNCTIONS/chol.cc, DLD-FUNCTIONS/det.cc, DLD-FUNCTIONS/getpwent.cc, DLD-FUNCTIONS/inv.cc, DLD-FUNCTIONS/qr.cc, DLD-FUNCTIONS/symrcm.cc, file-io.cc):
--- a/src/ov-base-mat.h +++ b/src/ov-base-mat.h @@ -75,12 +75,9 @@ octave_value subsref (const std::string& type, const std::list<octave_value_list>& idx); - octave_value_list subsref (const std::string&, - const std::list<octave_value_list>&, int) - { - panic_impossible (); - return octave_value_list (); - } + octave_value_list subsref (const std::string& type, + const std::list<octave_value_list>& idx, int) + { return subsref (type, idx); } octave_value subsasgn (const std::string& type, const std::list<octave_value_list>& idx,
--- a/src/ov-base-scalar.h +++ b/src/ov-base-scalar.h @@ -65,12 +65,9 @@ octave_value subsref (const std::string& type, const std::list<octave_value_list>& idx); - octave_value_list subsref (const std::string&, - const std::list<octave_value_list>&, int) - { - panic_impossible (); - return octave_value_list (); - } + octave_value_list subsref (const std::string& type, + const std::list<octave_value_list>& idx, int) + { return subsref (type, idx); } octave_value subsasgn (const std::string& type, const std::list<octave_value_list>& idx,
--- a/src/ov-base-sparse.h +++ b/src/ov-base-sparse.h @@ -87,12 +87,9 @@ octave_value subsref (const std::string& type, const std::list<octave_value_list>& idx); - octave_value_list subsref (const std::string&, - const std::list<octave_value_list>&, int) - { - panic_impossible (); - return octave_value_list (); - } + octave_value_list subsref (const std::string& type, + const std::list<octave_value_list>& idx, int) + { return subsref (type, idx); } octave_value subsasgn (const std::string& type, const std::list<octave_value_list>& idx,
--- a/src/ov-builtin.h +++ b/src/ov-builtin.h @@ -50,11 +50,11 @@ ~octave_builtin (void) { } - octave_value subsref (const std::string&, - const std::list<octave_value_list>&) + octave_value subsref (const std::string& type, + const std::list<octave_value_list>& idx) { - panic_impossible (); - return octave_value (); + octave_value_list tmp = subsref (type, idx, 1); + return tmp.length () > 0 ? tmp(0) : octave_value (); } octave_value_list subsref (const std::string& type,
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -65,16 +65,17 @@ error ("assignment to cell array failed"); } -octave_value +octave_value_list octave_cell::subsref (const std::string& type, - const std::list<octave_value_list>& idx) + const std::list<octave_value_list>& idx, + int nargout) { - octave_value retval; + octave_value_list retval; switch (type[0]) { case '(': - retval = do_index_op (idx.front ()); + retval(0) = do_index_op (idx.front ()); break; case '{': @@ -86,7 +87,7 @@ Cell tcell = tmp.cell_value (); if (tcell.length () == 1) - retval = tcell(0,0); + retval(0) = tcell(0,0); else { octave_idx_type n = tcell.numel (); @@ -99,7 +100,7 @@ lst(i) = tcell(i); } - retval = octave_value (lst, true); + retval(0) = octave_value (lst, true); } } } @@ -121,7 +122,7 @@ // octave_user_function::subsref. if (idx.size () > 1) - retval = retval.next_subsref (type, idx); + retval = retval(0).next_subsref (nargout, type, idx); return retval; }
--- a/src/ov-cell.h +++ b/src/ov-cell.h @@ -70,15 +70,15 @@ octave_base_value *try_narrowing_conversion (void); #endif - octave_value subsref (const std::string&, - const std::list<octave_value_list>&); + octave_value subsref (const std::string& type, + const std::list<octave_value_list>& idx) + { + octave_value_list tmp = subsref (type, idx, 1); + return tmp.length () > 0 ? tmp(0) : octave_value (); + } - octave_value_list subsref (const std::string&, - const std::list<octave_value_list>&, int) - { - panic_impossible (); - return octave_value_list (); - } + octave_value_list subsref (const std::string& type, + const std::list<octave_value_list>& idx, int); octave_value subsasgn (const std::string& type, const std::list<octave_value_list>& idx,
--- a/src/ov-class.h +++ b/src/ov-class.h @@ -64,11 +64,11 @@ Cell dotref (const octave_value_list& idx); - octave_value subsref (const std::string&, - const std::list<octave_value_list>&) + octave_value subsref (const std::string& type, + const std::list<octave_value_list>& idx) { - panic_impossible (); - return octave_value_list (); + octave_value_list tmp = subsref (type, idx, 1); + return tmp.length () > 0 ? tmp(0) : octave_value (); } octave_value_list subsref (const std::string& type,
--- a/src/ov-fcn-handle.h +++ b/src/ov-fcn-handle.h @@ -57,11 +57,11 @@ octave_base_value *clone (void) const { return new octave_fcn_handle (*this); } octave_base_value *empty_clone (void) const { return new octave_fcn_handle (); } - octave_value subsref (const std::string&, - const std::list<octave_value_list>&) + octave_value subsref (const std::string& type, + const std::list<octave_value_list>& idx) { - panic_impossible (); - return octave_value (); + octave_value_list tmp = subsref (type, idx, 1); + return tmp.length () > 0 ? tmp(0) : octave_value (); } octave_value_list subsref (const std::string& type,
--- a/src/ov-list.h +++ b/src/ov-list.h @@ -63,11 +63,11 @@ octave_base_value *clone (void) const { return new octave_list (*this); } octave_base_value *empty_clone (void) const { return new octave_list (); } - octave_value subsref (const std::string&, - const std::list<octave_value_list>&) + octave_value subsref (const std::string& type, + const std::list<octave_value_list>& idx) { - panic_impossible (); - return octave_value_list (); + octave_value_list tmp = subsref (type, idx, 1); + return tmp.length () > 0 ? tmp(0) : octave_value (); } octave_value_list subsref (const std::string& type,
--- a/src/ov-mex-fcn.h +++ b/src/ov-mex-fcn.h @@ -50,11 +50,11 @@ ~octave_mex_function (void); - octave_value subsref (const std::string&, - const std::list<octave_value_list>&) + octave_value subsref (const std::string& type, + const std::list<octave_value_list>& idx) { - panic_impossible (); - return octave_value (); + octave_value_list tmp = subsref (type, idx, 1); + return tmp.length () > 0 ? tmp(0) : octave_value (); } octave_value_list subsref (const std::string& type,
--- a/src/ov-range.h +++ b/src/ov-range.h @@ -91,12 +91,9 @@ octave_value subsref (const std::string& type, const std::list<octave_value_list>& idx); - octave_value_list subsref (const std::string&, - const std::list<octave_value_list>&, int) - { - panic_impossible (); - return octave_value_list (); - } + octave_value_list subsref (const std::string& type, + const std::list<octave_value_list>& idx, int) + { return subsref (type, idx); } octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false);
--- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -96,11 +96,12 @@ error ("assignment to structure element failed"); } -octave_value +octave_value_list octave_struct::subsref (const std::string& type, - const std::list<octave_value_list>& idx) + const std::list<octave_value_list>& idx, + int nargout) { - octave_value retval; + octave_value_list retval; int skip = 1; @@ -119,7 +120,7 @@ { Cell t = tmp.index (idx.front (), true); - retval = (t.length () == 1) ? t(0) : octave_value (t, true); + retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); // We handled two index elements, so tell // next_subsref to skip both of them. @@ -128,7 +129,7 @@ } } else - retval = map.index (idx.front (), true); + retval(0) = map.index (idx.front (), true); } break; @@ -138,7 +139,7 @@ { Cell t = dotref (idx.front ()); - retval = (t.length () == 1) ? t(0) : octave_value (t, true); + retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); } } break; @@ -156,7 +157,7 @@ // octave_user_function::subsref. if (idx.size () > 1) - retval = retval.next_subsref (type, idx, skip); + retval = retval(0).next_subsref (nargout, type, idx, skip); return retval; }
--- a/src/ov-struct.h +++ b/src/ov-struct.h @@ -65,16 +65,15 @@ Cell dotref (const octave_value_list& idx); - octave_value subsref (const std::string&, - const std::list<octave_value_list>&); + octave_value subsref (const std::string& type, + const std::list<octave_value_list>& idx) + { + octave_value_list tmp = subsref (type, idx, 1); + return tmp.length () > 0 ? tmp(0) : octave_value (); + } octave_value_list subsref (const std::string&, - const std::list<octave_value_list>&, int) - { - panic_impossible (); - return octave_value_list (); - } - + const std::list<octave_value_list>&, int); static octave_value numeric_conv (const Cell& val, const std::string& type);
--- a/src/ov-usr-fcn.h +++ b/src/ov-usr-fcn.h @@ -187,11 +187,11 @@ } } - octave_value subsref (const std::string&, - const std::list<octave_value_list>&) + octave_value subsref (const std::string& type, + const std::list<octave_value_list>& idx) { - panic_impossible (); - return octave_value (); + octave_value_list tmp = subsref (type, idx, 1); + return tmp.length () > 0 ? tmp(0) : octave_value (); } octave_value_list subsref (const std::string& type,
--- a/src/ov.cc +++ b/src/ov.cc @@ -926,7 +926,7 @@ octave_value::subsref (const std::string& type, const std::list<octave_value_list>& idx, int nargout) { - if (is_constant ()) + if (nargout == 1) return rep->subsref (type, idx); else return rep->subsref (type, idx, nargout); @@ -1014,15 +1014,7 @@ // a specific function to call to handle the op= operation for // the types we have. - octave_value t; - if (is_constant ()) - t = subsref (type, idx); - else - { - octave_value_list tl = subsref (type, idx, 1); - if (tl.length () > 0) - t = tl(0); - } + octave_value t = subsref (type, idx); if (! error_state) {