Mercurial > hg > octave-nkf
changeset 4994:48d0defe9445
[project @ 2004-09-15 20:31:31 by jwe]
author | jwe |
---|---|
date | Wed, 15 Sep 2004 20:31:31 +0000 |
parents | 761b8d760785 |
children | fd4d0aab09d7 |
files | src/ChangeLog src/ov-builtin.cc src/ov-cell.cc src/ov-cell.h src/ov-fcn-handle.cc src/ov-list.cc src/ov-list.h src/ov-mapper.cc src/ov-struct.cc src/ov-struct.h src/ov-usr-fcn.cc src/ov.cc src/ov.h |
diffstat | 13 files changed, 118 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,29 @@ +2004-09-15 John W. Eaton <jwe@octave.org> + + * ov-cell.cc (octave_cell::subsref): Pass nargout to next_subsref. + * ov-builtin.cc (octave_builtin::subsref): Likewise. + * ov-fcn-handle.cc (octave_fcn_handle::subsref): Likewise. + * ov-list.cc (octave_list::subsref): Likewise. + * ov-mapper.cc (octave_mapper::subsref): Likewise. + * ov-struct.cc (octave_struct::subsref): Likewise. + * ov-usr-fcn.cc (octave_user_function::subsref): Likewise. + + * ov-struct.cc, ov-struct.h (octave_struct::subsref (const + std::string&, const std::list<octave_value_list>&, int)): + Define this version. + (octave_struct::subsref (const std::string&, const + std::list<octave_value_list>&)): Panic in this version. + * ov-list.cc, ov-list.h: Likewise. + * ov-cell.cc, ov-cell.h: Likewise. + + * ov.cc (octave_value::subsref (int, const std::string&, const + std::list<octave_value_list>&, size_t)): New function. + * ov.h: Provide decl. + + * ov-cell.h (octave_cell::is_constant): Return false. + * ov-struct.h (octave_struct::is_constant): Delete. + * ov-list.h (octave_list::is_constant): Delete. + 2004-09-14 David Bateman <dbateman@free.fr> * DLD-FUNCTIONS/sort.cc (mx_sort (charNDArray&, bool, int)):
--- a/src/ov-builtin.cc +++ b/src/ov-builtin.cc @@ -91,7 +91,7 @@ // for exmaple? if (idx.size () > 1) - retval = retval(0).next_subsref (type, idx); + retval = retval(0).next_subsref (nargout, type, idx); return retval; }
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -58,16 +58,16 @@ DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cell, "cell", "cell"); -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 '{': @@ -79,7 +79,7 @@ Cell tcell = tmp.cell_value (); if (tcell.length () == 1) - retval = tcell(0,0); + retval(0) = tcell(0,0); else { int n = tcell.numel (); @@ -92,7 +92,7 @@ lst(i) = tcell(i); } - retval = octave_value (lst, true); + retval(0) = octave_value (lst, true); } } } @@ -109,7 +109,14 @@ panic_impossible (); } - return retval.next_subsref (type, idx); + // XXX FIXME XXX -- perhaps there should be an + // octave_value_list::next_subsref member function? See also + // octave_user_function::subsref. + + if (idx.size () > 1) + retval = retval(0).next_subsref (nargout, type, idx); + + return retval; } octave_value
--- a/src/ov-cell.h +++ b/src/ov-cell.h @@ -73,16 +73,17 @@ octave_value *try_narrowing_conversion (void); #endif - 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) + octave_value subsref (const std::string&, + const std::list<octave_value_list>&) { panic_impossible (); return octave_value_list (); } + octave_value_list subsref (const std::string& type, + const std::list<octave_value_list>& idx, + int nargout); + octave_value subsasgn (const std::string& type, const std::list<octave_value_list>& idx, const octave_value& rhs); @@ -95,6 +96,8 @@ bool is_defined (void) const { return true; } + bool is_constant (void) const { return false; } + bool is_cell (void) const { return true; } Cell cell_value (void) const { return matrix; }
--- a/src/ov-fcn-handle.cc +++ b/src/ov-fcn-handle.cc @@ -92,7 +92,7 @@ // octave_builtin::subsref. if (idx.size () > 1) - retval = retval(0).next_subsref (type, idx); + retval = retval(0).next_subsref (nargout, type, idx); return retval; }
--- a/src/ov-list.cc +++ b/src/ov-list.cc @@ -36,6 +36,7 @@ #include "Cell.h" #include "defun.h" #include "error.h" +#include "ov.h" #include "ov-list.h" #include "unwind-prot.h" @@ -60,11 +61,11 @@ data(i) = c(i); } -octave_value +octave_value_list octave_list::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]) { @@ -78,7 +79,7 @@ Cell tmp = data.index (i); - retval = octave_value (new octave_list (tmp)); + retval(0) = octave_value (new octave_list (tmp)); } else error ("only one index allowed for lists"); @@ -96,9 +97,9 @@ Cell tmp = data.index (i); if (tmp.length () == 1) - retval = tmp(0); + retval(0) = tmp(0); else - retval = octave_value (tmp, true); + retval(0) = octave_value (tmp, true); } else error ("only one index allowed for lists"); @@ -116,7 +117,14 @@ panic_impossible (); } - return retval.next_subsref (type, idx); + // XXX FIXME XXX -- perhaps there should be an + // octave_value_list::next_subsref member function? See also + // octave_user_function::subsref. + + if (idx.size () > 1) + retval = retval(0).next_subsref (nargout, type, idx); + + return retval; } octave_value
--- a/src/ov-list.h +++ b/src/ov-list.h @@ -66,16 +66,17 @@ octave_value *clone (void) const { return new octave_list (*this); } octave_value *empty_clone (void) const { return new octave_list (); } - 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) + octave_value subsref (const std::string&, + const std::list<octave_value_list>&) { panic_impossible (); return octave_value_list (); } + octave_value_list subsref (const std::string& type, + const std::list<octave_value_list>& idx, + int nargout); + octave_value do_index_op (const octave_value_list& idx, int resize_ok); octave_value subsasgn (const std::string& type, @@ -90,8 +91,6 @@ bool is_defined (void) const { return true; } - bool is_constant (void) const { return true; } - bool is_list (void) const { return true; } octave_value_list list_value (void) const;
--- a/src/ov-mapper.cc +++ b/src/ov-mapper.cc @@ -265,8 +265,12 @@ return retval; - // XXX FIXME XXX - // return retval.next_subsref (type, idx); + // XXX FIXME XXX -- perhaps there should be an + // octave_value_list::next_subsref member function? See also + // and octave_builtin::subsref. + + if (idx.size () > 1) + retval = retval(0).next_subsref (nargout, type, idx); } octave_value_list
--- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -97,11 +97,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; @@ -120,7 +121,7 @@ { Cell t = tmp.index (idx.front ()); - 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. @@ -129,7 +130,7 @@ } } else - retval = map.index (idx.front ()); + retval(0) = map.index (idx.front ()); } break; @@ -137,7 +138,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; @@ -149,8 +150,12 @@ panic_impossible (); } - if (! error_state) - retval = retval.next_subsref (type, idx, skip); + // XXX FIXME XXX -- perhaps there should be an + // octave_value_list::next_subsref member function? See also + // octave_user_function::subsref. + + if (idx.size () > 1) + retval = retval(0).next_subsref (nargout, type, idx); return retval; }
--- a/src/ov-struct.h +++ b/src/ov-struct.h @@ -69,16 +69,17 @@ Cell dotref (const octave_value_list& idx); - 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) + octave_value subsref (const std::string&, + const std::list<octave_value_list>&) { panic_impossible (); return octave_value_list (); } + octave_value_list subsref (const std::string& type, + const std::list<octave_value_list>& idx, + int nargout); + static octave_value numeric_conv (const Cell& val, const std::string& type); @@ -98,8 +99,6 @@ bool is_defined (void) const { return true; } - bool is_constant (void) const { return true; } - bool is_map (void) const { return true; } Octave_map map_value (void) const { return map; }
--- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -318,7 +318,7 @@ // octave_builtin::subsref. if (idx.size () > 1) - retval = retval(0).next_subsref (type, idx); + retval = retval(0).next_subsref (nargout, type, idx); return retval; }
--- a/src/ov.cc +++ b/src/ov.cc @@ -844,6 +844,22 @@ } octave_value_list +octave_value::next_subsref (int nargout, const std::string& type, + const std::list<octave_value_list>& idx, + size_t skip) +{ + if (! error_state && idx.size () > skip) + { + std::list<octave_value_list> new_idx (idx); + for (size_t i = 0; i < skip; i++) + new_idx.erase (new_idx.begin ()); + return subsref (type.substr (skip), new_idx, nargout); + } + else + return *this; +} + +octave_value_list octave_value::do_multi_index_op (int nargout, const octave_value_list& idx) { return rep->do_multi_index_op (nargout, idx);
--- a/src/ov.h +++ b/src/ov.h @@ -318,6 +318,11 @@ std::list<octave_value_list>& idx, size_t skip = 1); + octave_value_list next_subsref (int nargout, + const std::string& type, const + std::list<octave_value_list>& idx, + size_t skip = 1); + virtual octave_value do_index_op (const octave_value_list& idx, int resize_ok) { return rep->do_index_op (idx, resize_ok); }