Mercurial > hg > octave-lojdl
changeset 6767:a6c8000f113e
[project @ 2007-06-28 19:42:42 by jwe]
author | jwe |
---|---|
date | Thu, 28 Jun 2007 19:42:42 +0000 |
parents | 6373d320a957 |
children | 40e1255eda0e |
files | src/ChangeLog src/oct-stream.cc src/ov-cell.cc |
diffstat | 3 files changed, 53 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2007-06-28 John W. Eaton <jwe@octave.org> + * ov-cell.cc (octave_cell::subsasgn): Given x = {}, convert to + struct for assignments like x(1).f = val; + + * oct-stream.cc (octave_scan_1): New function + (octave_scan): Use it. Handle fmt.width. + * graphics.h (axes::axes_properties::visible): New data member. * graphics.cc (axes::axes_properties::axes_properties, axes::axes_properties::set, axes::axes_properties::get,
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -1047,12 +1047,9 @@ #define OCTAVE_SCAN(is, fmt, arg) octave_scan (is, fmt, arg) -// FIXME -- this needs to be fixed to handle formats which -// specify a maximum width. - template <class T> std::istream& -octave_scan (std::istream& is, const scanf_format_elt& fmt, T* valptr) +octave_scan_1 (std::istream& is, const scanf_format_elt& fmt, T* valptr) { T& ref = *valptr; @@ -1108,6 +1105,30 @@ return is; } +template <class T> +std::istream& +octave_scan (std::istream& is, const scanf_format_elt& fmt, T* valptr) +{ + if (fmt.width) + { + // Limit input to fmt.width characters by reading into a + // temporary stringstream buffer. + + std::string tmp; + + is.width (fmt.width); + is >> tmp; + + std::istringstream ss (tmp); + + octave_scan_1 (ss, fmt, valptr); + } + else + octave_scan_1 (is, fmt, valptr); + + return is; +} + // Note that this specialization is only used for reading characters, not // character strings. See BEGIN_S_CONVERSION for details.
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -137,20 +137,34 @@ { case '(': { - octave_value tmp = do_index_op (idx.front (), true); + if (is_empty () && type[1] == '.') + { + // Allow conversion of empty cell array to some other + // type in cases like + // + // x = []; x(i).f = rhs - if (! tmp.is_defined ()) - tmp = octave_value::empty_conv (type.substr (1), rhs); + octave_value tmp = octave_value::empty_conv (type, rhs); - if (! error_state) + return tmp.subsasgn (type, idx, rhs); + } + else { - std::list<octave_value_list> next_idx (idx); + octave_value tmp = do_index_op (idx.front (), true); - next_idx.erase (next_idx.begin ()); + if (! tmp.is_defined ()) + tmp = octave_value::empty_conv (type.substr (1), rhs); - tmp.make_unique (); + if (! error_state) + { + std::list<octave_value_list> next_idx (idx); - t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs); + next_idx.erase (next_idx.begin ()); + + tmp.make_unique (); + + t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs); + } } } break;