Mercurial > hg > octave-lyh
changeset 7760:f5268d7045d7
struct2cell: handle structure arrays properly
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 May 2008 03:23:12 -0400 |
parents | 84a7f00586aa |
children | 5adeea5de26c |
files | src/ChangeLog src/ov-cell.cc |
diffstat | 2 files changed, 14 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2008-05-06 John W. Eaton <jwe@octave.org> + + * ov-cell.cc (Fstruct2cell): Handle structure arrays properly. + 2008-05-05 David Bateman <dbateman@free.fr> * sysdep.cc (Fputenv): Allow single arg. Alias to setenv.
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -1115,7 +1115,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)] @@ -1123,44 +1123,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<octave_idx_type> 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;