Mercurial > hg > octave-terminal
changeset 9851:1fac51c5f83f
save dims for empty structs
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 23 Nov 2009 08:43:42 +0100 |
parents | 85f6c386f2bb |
children | aabf7a8c2e57 |
files | src/ChangeLog src/ov-struct.cc |
diffstat | 2 files changed, 44 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2009-11-23 Jaroslav Hajek <highegg@gmail.com> + + * ov-struct.cc (octave_struct::save_ascii): Save dimensions for + structs. + (octave_struct::load_ascii): Load dimensions if present, + use 1x1 otherwise. + 2009-11-20 Jaroslav Hajek <highegg@gmail.com> * data.cc (Fmerge): Correct query for logical masks.
--- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -1247,6 +1247,14 @@ octave_idx_type nf = m.nfields (); + const dim_vector dv = dims (); + + os << "# ndims: " << dv.length () << "\n"; + + for (int i = 0; i < dv.length (); i++) + os << " " << dv (i); + os << "\n"; + os << "# length: " << nf << "\n"; // Iterating over the list of keys will preserve the order of the @@ -1272,13 +1280,39 @@ octave_struct::load_ascii (std::istream& is) { octave_idx_type len = 0; + dim_vector dv (1, 1); bool success = true; - if (extract_keyword (is, "length", len) && len >= 0) + // KLUGE: earlier Octave versions did not save extra dimensions with struct, + // and as a result did not preserve dimensions for empty structs. + // The default dimensions were 1x1, which we want to preserve. + string_vector keywords(2); + + keywords[0] = "ndims"; + keywords[1] = "length"; + + std::string kw; + + if (extract_keyword (is, keywords, kw, len, true)) + { + if (kw == keywords[0]) + { + int mdims = std::max (len, 2); + dv.resize (mdims); + for (int i = 0; i < mdims; i++) + is >> dv(i); + + success = extract_keyword (is, keywords[1], len); + } + } + else + success = false; + + if (success && len >= 0) { if (len > 0) { - Octave_map m (map); + Octave_map m (dv); for (octave_idx_type j = 0; j < len; j++) { @@ -1312,7 +1346,7 @@ } } else if (len == 0 ) - map = Octave_map (dim_vector (1, 1)); + map = Octave_map (dv); else panic_impossible (); }