Mercurial > octave-nkf
diff libinterp/octave-value/ov.cc @ 20592:56fee8f84fe7
eliminate more simple uses of error_state
* cellfun.cc, syscalls.cc, urlwrite.cc, ov.cc, pt-eval.cc:
Eliminate uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 05 Oct 2015 22:47:42 -0400 |
parents | b70cc4bd8109 |
children | 729a85dafba8 |
line wrap: on
line diff
--- a/libinterp/octave-value/ov.cc Mon Oct 05 21:37:03 2015 -0400 +++ b/libinterp/octave-value/ov.cc Mon Oct 05 22:47:42 2015 -0400 @@ -1318,7 +1318,7 @@ const std::list<octave_value_list>& idx, size_t skip) { - if (! error_state && idx.size () > skip) + if (idx.size () > skip) { std::list<octave_value_list> new_idx (idx); for (size_t i = 0; i < skip; i++) @@ -1334,7 +1334,7 @@ const std::list<octave_value_list>& idx, size_t skip) { - if (! error_state && idx.size () > skip) + if (idx.size () > skip) { std::list<octave_value_list> new_idx (idx); for (size_t i = 0; i < skip; i++) @@ -1351,7 +1351,7 @@ const std::list<octave_lvalue> *lvalue_list, size_t skip) { - if (! error_state && idx.size () > skip) + if (idx.size () > skip) { std::list<octave_value_list> new_idx (idx); for (size_t i = 0; i < skip; i++) @@ -1367,7 +1367,7 @@ const std::list<octave_value_list>& idx, size_t skip) { - if (! error_state && idx.size () > skip) + if (idx.size () > skip) { std::list<octave_value_list> new_idx (idx); for (size_t i = 0; i < skip; i++) @@ -1443,28 +1443,21 @@ { octave_value t = subsref (type, idx); - if (! error_state) - { - binary_op binop = op_eq_to_binary_op (op); - - if (! error_state) - t_rhs = do_binary_op (binop, t, rhs); - } + binary_op binop = op_eq_to_binary_op (op); + + t_rhs = do_binary_op (binop, t, rhs); } else error ("in computed assignment A(index) OP= X, A must be defined first"); } - if (! error_state) - { - octave_value tmp = subsasgn (type, idx, t_rhs); - - if (error_state) - gripe_assign_failed_or_no_method (assign_op_as_string (op_asn_eq), - type_name (), rhs.type_name ()); - else - *this = tmp; - } + octave_value tmp = subsasgn (type, idx, t_rhs); + + if (error_state) + gripe_assign_failed_or_no_method (assign_op_as_string (op_asn_eq), + type_name (), rhs.type_name ()); + else + *this = tmp; return *this; } @@ -1499,13 +1492,9 @@ binary_op binop = op_eq_to_binary_op (op); - if (! error_state) - { - octave_value t = do_binary_op (binop, *this, rhs); - - if (! error_state) - operator = (t); - } + octave_value t = do_binary_op (binop, *this, rhs); + + operator = (t); } } else @@ -1548,7 +1537,7 @@ octave_value tmp = do_binary_op (octave_value::op_eq, *this, test); // Empty array also means a match. - if (! error_state && tmp.is_defined ()) + if (tmp.is_defined ()) retval = tmp.is_true () || tmp.is_empty (); } @@ -1685,12 +1674,9 @@ { Array<double> retval = array_value (force_string_conv); - if (error_state) - return retval; - else - return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "real vector")); + return retval.reshape (make_vector_dims (retval.dims (), + force_vector_conversion, + type_name (), "real vector")); } template <class T> @@ -1736,36 +1722,30 @@ else { const NDArray a = array_value (force_string_conv); - if (! error_state) + + if (require_int) { - if (require_int) + retval.resize (a.dims ()); + for (octave_idx_type i = 0; i < a.numel (); i++) { - retval.resize (a.dims ()); - for (octave_idx_type i = 0; i < a.numel (); i++) + double ai = a.elem (i); + int v = static_cast<int> (ai); + if (ai == v) + retval.xelem (i) = v; + else { - double ai = a.elem (i); - int v = static_cast<int> (ai); - if (ai == v) - retval.xelem (i) = v; - else - { - error_with_cfn ("conversion to integer value failed"); - break; - } + error_with_cfn ("conversion to integer value failed"); + break; } } - else - retval = Array<int> (a); } + else + retval = Array<int> (a); } - - if (error_state) - return retval; - else - return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "integer vector")); + return retval.reshape (make_vector_dims (retval.dims (), + force_vector_conversion, + type_name (), "integer vector")); } template <class T> @@ -1812,36 +1792,30 @@ else { const NDArray a = array_value (force_string_conv); - if (! error_state) + + if (require_int) { - if (require_int) + retval.resize (a.dims ()); + for (octave_idx_type i = 0; i < a.numel (); i++) { - retval.resize (a.dims ()); - for (octave_idx_type i = 0; i < a.numel (); i++) + double ai = a.elem (i); + octave_idx_type v = static_cast<octave_idx_type> (ai); + if (ai == v) + retval.xelem (i) = v; + else { - double ai = a.elem (i); - octave_idx_type v = static_cast<octave_idx_type> (ai); - if (ai == v) - retval.xelem (i) = v; - else - { - error_with_cfn ("conversion to integer value failed"); - break; - } + error_with_cfn ("conversion to integer value failed"); + break; } } - else - retval = Array<octave_idx_type> (a); } + else + retval = Array<octave_idx_type> (a); } - - if (error_state) - return retval; - else - return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "integer vector")); + return retval.reshape (make_vector_dims (retval.dims (), + force_vector_conversion, + type_name (), "integer vector")); } Array<Complex> @@ -1850,12 +1824,9 @@ { Array<Complex> retval = complex_array_value (force_string_conv); - if (error_state) - return retval; - else - return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "complex vector")); + return retval.reshape (make_vector_dims (retval.dims (), + force_vector_conversion, + type_name (), "complex vector")); } FloatColumnVector @@ -1897,12 +1868,9 @@ { Array<float> retval = float_array_value (force_string_conv); - if (error_state) - return retval; - else - return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "real vector")); + return retval.reshape (make_vector_dims (retval.dims (), + force_vector_conversion, + type_name (), "real vector")); } Array<FloatComplex> @@ -1911,12 +1879,9 @@ { Array<FloatComplex> retval = float_complex_array_value (force_string_conv); - if (error_state) - return retval; - else - return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "complex vector")); + return retval.reshape (make_vector_dims (retval.dims (), + force_vector_conversion, + type_name (), "complex vector")); } octave_value @@ -2966,15 +2931,12 @@ decode_subscripts ("subsref", args(1), type, idx); - if (! error_state) - { - octave_value arg0 = args(0); - - if (type.empty ()) - retval = arg0; - else - retval = arg0.subsref (type, idx, nargout); - } + octave_value arg0 = args(0); + + if (type.empty ()) + retval = arg0; + else + retval = arg0.subsref (type, idx, nargout); } else print_usage (); @@ -3024,23 +2986,19 @@ decode_subscripts ("subsasgn", args(1), type, idx); - if (! error_state) + if (type.empty ()) { - if (type.empty ()) - { - // Regularize a null matrix if stored into a variable. - - retval = args(2).storable_value (); - } - else - { - octave_value arg0 = args(0); - - arg0.make_unique (); - - if (! error_state) - retval= arg0.subsasgn (type, idx, args(2)); - } + // Regularize a null matrix if stored into a variable. + + retval = args(2).storable_value (); + } + else + { + octave_value arg0 = args(0); + + arg0.make_unique (); + + retval= arg0.subsasgn (type, idx, args(2)); } } else