# HG changeset patch # User John W. Eaton # Date 1210058592 14400 # Node ID 1a7ef7a48be10ffa84fbc0c0b8681d7b31c16a05 # Parent 20aba78035b3e0bbf3486664f783f9639b663240 struct2cell: handle structure arrays properly diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2008-05-06 John W. Eaton + + * ov-cell.cc (Fstruct2cell): Handle structure arrays properly. + 2008-05-05 David Bateman * sysdep.cc (Fputenv): Allow single arg. Alias to setenv. diff --git a/src/ov-cell.cc b/src/ov-cell.cc --- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -1114,7 +1114,7 @@ string_vector keys = m.keys (); - octave_idx_type fields_numel = keys.length (); + octave_idx_type num_fields = keys.length (); // The resulting dim_vector should have dimensions: // [numel(fields) size(struct)] @@ -1122,44 +1122,26 @@ dim_vector result_dv; result_dv.resize (m_dv.length () + 1); // Add 1 for the fields. - result_dv(0) = fields_numel; + result_dv(0) = num_fields; for (int i = 1; i < result_dv.length (); i++) result_dv(i) = m_dv(i-1); - // Squeeze to be sure that a (3,1) vector doesn't get turned - // into a (3,3,1) vector. - - result_dv = result_dv.squeeze (); - Cell c (result_dv); - // Use ra_idx both for counting and for assignments, so - // ra_idx(0) will both contain fields_numel for each call to - // increment_index and j for each assignment. + octave_idx_type n_elts = m.numel (); - Array ra_idx (result_dv.length (), 0); - ra_idx(0) = fields_numel; - - for (octave_idx_type i = 0; i < m_dv.numel (); i++) + for (octave_idx_type j = 0; j < num_fields; j++) { - for (octave_idx_type j = 0; j < fields_numel; j++) - { - ra_idx(0) = j; + octave_idx_type k = j; - Cell c_tmp = m.contents (keys(j)); + const Cell vals = m.contents (keys(j)); - if (c_tmp.length () > 1) // Is a cell. - c(ra_idx) = c_tmp; - else if (c_tmp.length () == 1) // Get octave_value. - c(ra_idx) = c_tmp(0); - else - c(ra_idx) = Cell (); - - ra_idx(0) = fields_numel; + for (octave_idx_type i = 0; i < n_elts; i++) + { + c(k) = vals(i); + k += num_fields; } - - increment_index (ra_idx, result_dv); } retval = c;