Mercurial > hg > octave-lyh
changeset 4362:0c69a845ef1a
[project @ 2003-03-03 20:11:08 by jwe]
author | jwe |
---|---|
date | Mon, 03 Mar 2003 20:11:08 +0000 |
parents | 34014c0fb2ce |
children | 28a1be797aae |
files | src/ChangeLog src/load-save.cc src/ov-cell.cc |
diffstat | 3 files changed, 66 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,13 @@ +2003-03-03 John W. Eaton <jwe@bevo.che.wisc.edu> + + * load-save.cc (read_mat5_binary_element): Handle structure arrays. + (save_mat5_binary_element): Likewise. + 2003-03-01 John W. Eaton <jwe@bevo.che.wisc.edu> + * ov-cell.cc (octave_cell::subsasgn): Use make_unique in + appropriate places to preserve copy on write semantics. + * oct-conf.h.in: Substitute OCTAVE_CONF_KPATHSEA_INCFLAGS. * oct-stdstrm.h (octave_stdiostream::output_stream): Return stream
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -2746,17 +2746,39 @@ goto data_read_error; } + int n_fields = len/field_name_length; + + len = PAD (len); + OCTAVE_LOCAL_BUFFER (char, elname, len); if (! is.read (elname, len)) goto data_read_error; - // fields subelements - for (i = 0; i < len/field_name_length; i++) + int n; + if (nr == 1) + n = nc; + else if (nc == 1) + n = nr; + else { - octave_value fieldtc; - read_mat5_binary_element (is, filename, swap, global, fieldtc); - m[elname + i*field_name_length] = fieldtc; + error ("load: can only handle one-dimensional structure arrays"); + goto data_read_error; + } + + octave_value_list field_elts (n, Matrix ()); + + // fields subelements + for (i = 0; i < n_fields; i++) + { + for (int j = 0; j < n; j++) + { + octave_value fieldtc; + read_mat5_binary_element (is, filename, swap, global, fieldtc); + field_elts(j) = fieldtc; + } + + m.assign (elname + i*field_name_length, field_elts); } tc = m; @@ -2838,6 +2860,9 @@ is.seekg (pos + static_cast<std::streamoff> (element_length)); + if (is.eof ()) + is.clear (); + return retval; data_read_error: @@ -4238,15 +4263,8 @@ os.write ((char *)&junk, 4); // dimensions array subelement - if (tc.is_map ()) - { - nr = nc = 1; - } - else - { - nr = tc.rows (); - nc = tc.columns (); - } + nr = tc.rows (); + nc = tc.columns (); write_mat5_tag (os, miINT32, 8); os.write ((char *)&nr, 4); @@ -4344,17 +4362,21 @@ os.write (buf, 32); } + int len = m.array_length (); + for (Octave_map::iterator i = m.begin (); i != m.end (); i++) { // write the data of each element - // XXX FIXME XXX -- if the length of the structure array is - // 1, should we really create a list object? - bool retval2 - = save_mat5_binary_element (os, octave_value (m.contents (i)), - "", mark_as_global, save_as_floats); - - if (! retval2) - goto error_cleanup; + octave_value_list elts = m.contents (i); + + for (int j = 0; j < len; j++) + { + bool retval2 = save_mat5_binary_element (os, elts(j), "", + mark_as_global, + save_as_floats); + if (! retval2) + goto error_cleanup; + } } } }
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -130,6 +130,8 @@ next_idx.erase (next_idx.begin ()); + tmp.make_unique (); + t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs); } } @@ -142,17 +144,22 @@ if (! tmp.is_defined ()) tmp = octave_value::empty_conv (type.substr (1), rhs); - Cell tcell = tmp.cell_value (); + if (! error_state) + { + Cell tcell = tmp.cell_value (); - if (! error_state && tcell.length () == 1) - { - tmp = tcell(0,0); + if (! error_state && tcell.length () == 1) + { + tmp = tcell(0,0); - std::list<octave_value_list> next_idx (idx); + std::list<octave_value_list> next_idx (idx); + + next_idx.erase (next_idx.begin ()); - next_idx.erase (next_idx.begin ()); + tmp.make_unique (); - t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs); + t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs); + } } } break;