Mercurial > hg > octave-terminal
changeset 10749:df1a3e0ebbff
important fixes for struct rewrite(1)
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 24 Jun 2010 12:43:35 +0200 |
parents | d699a6c63263 |
children | f75e827649a5 |
files | src/oct-map.cc src/oct-map.h src/ov-struct.cc |
diffstat | 3 files changed, 42 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -839,7 +839,7 @@ octave_map rhs1 = rhs.orderfields (*this, perm); if (! error_state) { - assert (rhs1.xkeys.is_same (rhs.xkeys)); + assert (rhs1.xkeys.is_same (xkeys)); assign (i, rhs1); } else @@ -876,7 +876,7 @@ octave_map rhs1 = rhs.orderfields (*this, perm); if (! error_state) { - assert (rhs1.xkeys.is_same (rhs.xkeys)); + assert (rhs1.xkeys.is_same (xkeys)); assign (i, j, rhs1); } else @@ -913,7 +913,7 @@ octave_map rhs1 = rhs.orderfields (*this, perm); if (! error_state) { - assert (rhs1.xkeys.is_same (rhs.xkeys)); + assert (rhs1.xkeys.is_same (xkeys)); assign (ia, rhs1); } else @@ -970,6 +970,37 @@ } void +octave_map::assign (const octave_value_list& idx, const std::string& k, + const Cell& rhs) +{ + Cell tmp; + iterator p = seek (k); + Cell& ref = p != end () ? contents (p) : tmp; + + if (&ref == &tmp) + ref.clear (dimensions); + + ref.assign (idx, rhs); + + if (! error_state && ref.dims () != dimensions) + { + dimensions = ref.dims (); + + octave_idx_type nf = nfields (); + for (octave_idx_type k = 0; k < nf; k++) + { + if (&xvals[k] != &ref) + xvals[k].resize (dimensions, Cell::resize_fill_value ()); + } + + optimize_dimensions (); + } + + if (! error_state && &ref == &tmp) + setfield (k, tmp); +} + +void octave_map::delete_elements (const idx_vector& i) { octave_idx_type nf = nfields ();
--- a/src/oct-map.h +++ b/src/oct-map.h @@ -398,6 +398,9 @@ void assign (const octave_value_list&, const octave_map& rhs); + void assign (const octave_value_list& idx, const std::string& k, + const Cell& rhs); + void delete_elements (const idx_vector& i); void delete_elements (int dim, const idx_vector& i);
--- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -431,7 +431,7 @@ tmp_cell = tmp_cell.reshape (didx); - map.contents (key).assign (idxf, tmp_cell); + map.assign (idxf, key, tmp_cell); if (! error_state) { @@ -448,7 +448,7 @@ if (idxf.all_scalars () || cmap.contents (key).index (idxf, true).numel () == 1) { - map.contents (key).assign (idxf, Cell (t_rhs.storable_value ())); + map.assign (idxf, key, Cell (t_rhs.storable_value ())); if (! error_state) { count++; @@ -1239,6 +1239,9 @@ map.setfield (key, t_rhs.storable_value ()); else gripe_failed_assignment (); + + count++; + retval = this; } else {