Mercurial > octave
diff libinterp/octave-value/ov-struct.cc @ 20979:0963ed389012
maint: invert if/else/error instances.
* ov-bool-mat.cc, ov-cell.cc, ov-class.cc, ov-classdef.cc,
ov-cx-mat.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-perm.cc,
ov-re-mat.cc, ov-str-mat.cc, ov-struct.cc, ov-usr-fcn.cc:
Invert if/else/error instances.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 24 Dec 2015 12:50:28 -0500 |
parents | 1edf15793cac |
children | 93748bcaec17 |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-struct.cc Thu Dec 24 12:06:27 2015 -0500 +++ b/libinterp/octave-value/ov-struct.cc Thu Dec 24 12:50:28 2015 -0500 @@ -727,41 +727,39 @@ else success = false; - if (success && len >= 0) + if (! success || len < 0) + error ("load: failed to extract number of elements in structure"); + + if (len > 0) { - if (len > 0) + octave_map m (dv); + + for (octave_idx_type j = 0; j < len; j++) { - octave_map m (dv); - - for (octave_idx_type j = 0; j < len; j++) - { - octave_value t2; - bool dummy; - - // recurse to read cell elements - std::string nm - = read_text_data (is, std::string (), dummy, t2, j); - - if (! is) - break; - - Cell tcell = t2.is_cell () ? t2.xcell_value ("load: internal error loading struct elements") : Cell (t2); - - m.setfield (nm, tcell); - } - - if (is) - map = m; - else - error ("load: failed to load structure"); + octave_value t2; + bool dummy; + + // recurse to read cell elements + std::string nm + = read_text_data (is, std::string (), dummy, t2, j); + + if (! is) + break; + + Cell tcell = t2.is_cell () ? t2.xcell_value ("load: internal error loading struct elements") : Cell (t2); + + m.setfield (nm, tcell); } - else if (len == 0) - map = octave_map (dv); - else - panic_impossible (); + + if (! is) + error ("load: failed to load structure"); + + map = m; } + else if (len == 0) + map = octave_map (dv); else - error ("load: failed to extract number of elements in structure"); + panic_impossible (); return success; } @@ -866,10 +864,10 @@ m.setfield (nm, tcell); } - if (is) - map = m; - else + if (! is) error ("load: failed to load structure"); + + map = m; } else if (len == 0) map = octave_map (dv); @@ -1368,39 +1366,37 @@ bool success = true; octave_idx_type len = 0; - if (extract_keyword (is, "length", len) && len >= 0) + if (! extract_keyword (is, "length", len) || len < 0) + error ("load: failed to extract number of elements in structure"); + + if (len > 0) { - if (len > 0) + octave_scalar_map m; + + for (octave_idx_type j = 0; j < len; j++) { - octave_scalar_map m; - - for (octave_idx_type j = 0; j < len; j++) - { - octave_value t2; - bool dummy; - - // recurse to read cell elements - std::string nm - = read_text_data (is, std::string (), dummy, t2, j); - - if (! is) - break; - - m.setfield (nm, t2); - } - - if (is) - map = m; - else - error ("load: failed to load structure"); + octave_value t2; + bool dummy; + + // recurse to read cell elements + std::string nm + = read_text_data (is, std::string (), dummy, t2, j); + + if (! is) + break; + + m.setfield (nm, t2); } - else if (len == 0) - map = octave_scalar_map (); - else - panic_impossible (); + + if (! is) + error ("load: failed to load structure"); + + map = m; } + else if (len == 0) + map = octave_scalar_map (); else - error ("load: failed to extract number of elements in structure"); + panic_impossible (); return success; } @@ -1467,10 +1463,10 @@ m.setfield (nm, t2); } - if (is) - map = m; - else + if (! is) error ("load: failed to load structure"); + + map = m; } else if (len == 0) map = octave_scalar_map (); @@ -2073,10 +2069,10 @@ { std::string key = fcell(i).string_value (); - if (m.isfield (key)) - m.rmfield (key); - else + if (! m.isfield (key)) error ("rmfield: structure does not contain field %s", key.c_str ()); + + m.rmfield (key); } return ovl (m);