Mercurial > hg > octave-terminal
changeset 9857:43a7adf62534
save dims for empty structs (binary fmt)
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 24 Nov 2009 07:35:47 +0100 |
parents | 870a69bac55c |
children | 47c5af1868df |
files | src/ChangeLog src/ov-struct.cc |
diffstat | 2 files changed, 49 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2009-11-24 Jaroslav Hajek <highegg@gmail.com> + + * ov-struct.cc (octave_struct::save_binary): Save dimensions for + structs. + (octave_struct::load_binary): Load dimensions if present, + use 1x1 otherwise. + 2009-11-23 Jaroslav Hajek <highegg@gmail.com> * data.cc (Fmerge): Add missing parentheses.
--- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -1365,6 +1365,19 @@ octave_idx_type nf = m.nfields (); + dim_vector d = dims (); + if (d.length () < 1) + return false; + + // Use negative value for ndims + int32_t di = - d.length(); + os.write (reinterpret_cast<char *> (&di), 4); + for (int i = 0; i < d.length (); i++) + { + di = d(i); + os.write (reinterpret_cast<char *> (&di), 4); + } + int32_t len = nf; os.write (reinterpret_cast<char *> (&len), 4); @@ -1398,9 +1411,34 @@ if (swap) swap_bytes<4> (&len); + dim_vector dv (1, 1); + + if (len < 0) + { + // We have explicit dimensions. + int mdims = -len; + + int32_t di; + dv.resize (mdims); + + for (int i = 0; i < mdims; i++) + { + if (! is.read (reinterpret_cast<char *> (&di), 4)) + return false; + if (swap) + swap_bytes<4> (&di); + dv(i) = di; + } + + if (! is.read (reinterpret_cast<char *> (&len), 4)) + return false; + if (swap) + swap_bytes<4> (&len); + } + if (len > 0) { - Octave_map m (map); + Octave_map m (dv); for (octave_idx_type j = 0; j < len; j++) { @@ -1434,10 +1472,10 @@ success = false; } } - else if (len == 0 ) - map = Octave_map (dim_vector (1, 1)); + else if (len == 0) + map = Octave_map (dv); else - panic_impossible (); + success = false; return success; }