comparison libinterp/octave-value/ov.cc @ 20767: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
comparison
equal deleted inserted replaced
20766:0650b8431037 20767:56fee8f84fe7
1316 octave_value 1316 octave_value
1317 octave_value::next_subsref (const std::string& type, 1317 octave_value::next_subsref (const std::string& type,
1318 const std::list<octave_value_list>& idx, 1318 const std::list<octave_value_list>& idx,
1319 size_t skip) 1319 size_t skip)
1320 { 1320 {
1321 if (! error_state && idx.size () > skip) 1321 if (idx.size () > skip)
1322 { 1322 {
1323 std::list<octave_value_list> new_idx (idx); 1323 std::list<octave_value_list> new_idx (idx);
1324 for (size_t i = 0; i < skip; i++) 1324 for (size_t i = 0; i < skip; i++)
1325 new_idx.erase (new_idx.begin ()); 1325 new_idx.erase (new_idx.begin ());
1326 return subsref (type.substr (skip), new_idx); 1326 return subsref (type.substr (skip), new_idx);
1332 octave_value_list 1332 octave_value_list
1333 octave_value::next_subsref (int nargout, const std::string& type, 1333 octave_value::next_subsref (int nargout, const std::string& type,
1334 const std::list<octave_value_list>& idx, 1334 const std::list<octave_value_list>& idx,
1335 size_t skip) 1335 size_t skip)
1336 { 1336 {
1337 if (! error_state && idx.size () > skip) 1337 if (idx.size () > skip)
1338 { 1338 {
1339 std::list<octave_value_list> new_idx (idx); 1339 std::list<octave_value_list> new_idx (idx);
1340 for (size_t i = 0; i < skip; i++) 1340 for (size_t i = 0; i < skip; i++)
1341 new_idx.erase (new_idx.begin ()); 1341 new_idx.erase (new_idx.begin ());
1342 return subsref (type.substr (skip), new_idx, nargout); 1342 return subsref (type.substr (skip), new_idx, nargout);
1349 octave_value::next_subsref (int nargout, const std::string& type, 1349 octave_value::next_subsref (int nargout, const std::string& type,
1350 const std::list<octave_value_list>& idx, 1350 const std::list<octave_value_list>& idx,
1351 const std::list<octave_lvalue> *lvalue_list, 1351 const std::list<octave_lvalue> *lvalue_list,
1352 size_t skip) 1352 size_t skip)
1353 { 1353 {
1354 if (! error_state && idx.size () > skip) 1354 if (idx.size () > skip)
1355 { 1355 {
1356 std::list<octave_value_list> new_idx (idx); 1356 std::list<octave_value_list> new_idx (idx);
1357 for (size_t i = 0; i < skip; i++) 1357 for (size_t i = 0; i < skip; i++)
1358 new_idx.erase (new_idx.begin ()); 1358 new_idx.erase (new_idx.begin ());
1359 return subsref (type.substr (skip), new_idx, nargout, lvalue_list); 1359 return subsref (type.substr (skip), new_idx, nargout, lvalue_list);
1365 octave_value 1365 octave_value
1366 octave_value::next_subsref (bool auto_add, const std::string& type, 1366 octave_value::next_subsref (bool auto_add, const std::string& type,
1367 const std::list<octave_value_list>& idx, 1367 const std::list<octave_value_list>& idx,
1368 size_t skip) 1368 size_t skip)
1369 { 1369 {
1370 if (! error_state && idx.size () > skip) 1370 if (idx.size () > skip)
1371 { 1371 {
1372 std::list<octave_value_list> new_idx (idx); 1372 std::list<octave_value_list> new_idx (idx);
1373 for (size_t i = 0; i < skip; i++) 1373 for (size_t i = 0; i < skip; i++)
1374 new_idx.erase (new_idx.begin ()); 1374 new_idx.erase (new_idx.begin ());
1375 return subsref (type.substr (skip), new_idx, auto_add); 1375 return subsref (type.substr (skip), new_idx, auto_add);
1441 { 1441 {
1442 if (is_defined ()) 1442 if (is_defined ())
1443 { 1443 {
1444 octave_value t = subsref (type, idx); 1444 octave_value t = subsref (type, idx);
1445 1445
1446 if (! error_state) 1446 binary_op binop = op_eq_to_binary_op (op);
1447 { 1447
1448 binary_op binop = op_eq_to_binary_op (op); 1448 t_rhs = do_binary_op (binop, t, rhs);
1449
1450 if (! error_state)
1451 t_rhs = do_binary_op (binop, t, rhs);
1452 }
1453 } 1449 }
1454 else 1450 else
1455 error ("in computed assignment A(index) OP= X, A must be defined first"); 1451 error ("in computed assignment A(index) OP= X, A must be defined first");
1456 } 1452 }
1457 1453
1458 if (! error_state) 1454 octave_value tmp = subsasgn (type, idx, t_rhs);
1459 { 1455
1460 octave_value tmp = subsasgn (type, idx, t_rhs); 1456 if (error_state)
1461 1457 gripe_assign_failed_or_no_method (assign_op_as_string (op_asn_eq),
1462 if (error_state) 1458 type_name (), rhs.type_name ());
1463 gripe_assign_failed_or_no_method (assign_op_as_string (op_asn_eq), 1459 else
1464 type_name (), rhs.type_name ()); 1460 *this = tmp;
1465 else
1466 *this = tmp;
1467 }
1468 1461
1469 return *this; 1462 return *this;
1470 } 1463 }
1471 1464
1472 octave_value& 1465 octave_value&
1497 else 1490 else
1498 { 1491 {
1499 1492
1500 binary_op binop = op_eq_to_binary_op (op); 1493 binary_op binop = op_eq_to_binary_op (op);
1501 1494
1502 if (! error_state) 1495 octave_value t = do_binary_op (binop, *this, rhs);
1503 { 1496
1504 octave_value t = do_binary_op (binop, *this, rhs); 1497 operator = (t);
1505
1506 if (! error_state)
1507 operator = (t);
1508 }
1509 } 1498 }
1510 } 1499 }
1511 else 1500 else
1512 error ("in computed assignment A OP= X, A must be defined first"); 1501 error ("in computed assignment A OP= X, A must be defined first");
1513 1502
1546 if (rows () == test.rows () && columns () == test.columns ()) 1535 if (rows () == test.rows () && columns () == test.columns ())
1547 { 1536 {
1548 octave_value tmp = do_binary_op (octave_value::op_eq, *this, test); 1537 octave_value tmp = do_binary_op (octave_value::op_eq, *this, test);
1549 1538
1550 // Empty array also means a match. 1539 // Empty array also means a match.
1551 if (! error_state && tmp.is_defined ()) 1540 if (tmp.is_defined ())
1552 retval = tmp.is_true () || tmp.is_empty (); 1541 retval = tmp.is_true () || tmp.is_empty ();
1553 } 1542 }
1554 1543
1555 return retval; 1544 return retval;
1556 } 1545 }
1683 octave_value::vector_value (bool force_string_conv, 1672 octave_value::vector_value (bool force_string_conv,
1684 bool force_vector_conversion) const 1673 bool force_vector_conversion) const
1685 { 1674 {
1686 Array<double> retval = array_value (force_string_conv); 1675 Array<double> retval = array_value (force_string_conv);
1687 1676
1688 if (error_state) 1677 return retval.reshape (make_vector_dims (retval.dims (),
1689 return retval; 1678 force_vector_conversion,
1690 else 1679 type_name (), "real vector"));
1691 return retval.reshape (make_vector_dims (retval.dims (),
1692 force_vector_conversion,
1693 type_name (), "real vector"));
1694 } 1680 }
1695 1681
1696 template <class T> 1682 template <class T>
1697 static Array<int> 1683 static Array<int>
1698 convert_to_int_array (const Array<octave_int<T> >& A) 1684 convert_to_int_array (const Array<octave_int<T> >& A)
1734 retval = array_value (force_string_conv); 1720 retval = array_value (force_string_conv);
1735 } 1721 }
1736 else 1722 else
1737 { 1723 {
1738 const NDArray a = array_value (force_string_conv); 1724 const NDArray a = array_value (force_string_conv);
1739 if (! error_state) 1725
1726 if (require_int)
1740 { 1727 {
1741 if (require_int) 1728 retval.resize (a.dims ());
1729 for (octave_idx_type i = 0; i < a.numel (); i++)
1742 { 1730 {
1743 retval.resize (a.dims ()); 1731 double ai = a.elem (i);
1744 for (octave_idx_type i = 0; i < a.numel (); i++) 1732 int v = static_cast<int> (ai);
1733 if (ai == v)
1734 retval.xelem (i) = v;
1735 else
1745 { 1736 {
1746 double ai = a.elem (i); 1737 error_with_cfn ("conversion to integer value failed");
1747 int v = static_cast<int> (ai); 1738 break;
1748 if (ai == v)
1749 retval.xelem (i) = v;
1750 else
1751 {
1752 error_with_cfn ("conversion to integer value failed");
1753 break;
1754 }
1755 } 1739 }
1756 } 1740 }
1757 else
1758 retval = Array<int> (a);
1759 } 1741 }
1760 } 1742 else
1761 1743 retval = Array<int> (a);
1762 1744 }
1763 if (error_state) 1745
1764 return retval; 1746 return retval.reshape (make_vector_dims (retval.dims (),
1765 else 1747 force_vector_conversion,
1766 return retval.reshape (make_vector_dims (retval.dims (), 1748 type_name (), "integer vector"));
1767 force_vector_conversion,
1768 type_name (), "integer vector"));
1769 } 1749 }
1770 1750
1771 template <class T> 1751 template <class T>
1772 static Array<octave_idx_type> 1752 static Array<octave_idx_type>
1773 convert_to_octave_idx_type_array (const Array<octave_int<T> >& A) 1753 convert_to_octave_idx_type_array (const Array<octave_int<T> >& A)
1810 retval = array_value (force_string_conv); 1790 retval = array_value (force_string_conv);
1811 } 1791 }
1812 else 1792 else
1813 { 1793 {
1814 const NDArray a = array_value (force_string_conv); 1794 const NDArray a = array_value (force_string_conv);
1815 if (! error_state) 1795
1796 if (require_int)
1816 { 1797 {
1817 if (require_int) 1798 retval.resize (a.dims ());
1799 for (octave_idx_type i = 0; i < a.numel (); i++)
1818 { 1800 {
1819 retval.resize (a.dims ()); 1801 double ai = a.elem (i);
1820 for (octave_idx_type i = 0; i < a.numel (); i++) 1802 octave_idx_type v = static_cast<octave_idx_type> (ai);
1803 if (ai == v)
1804 retval.xelem (i) = v;
1805 else
1821 { 1806 {
1822 double ai = a.elem (i); 1807 error_with_cfn ("conversion to integer value failed");
1823 octave_idx_type v = static_cast<octave_idx_type> (ai); 1808 break;
1824 if (ai == v)
1825 retval.xelem (i) = v;
1826 else
1827 {
1828 error_with_cfn ("conversion to integer value failed");
1829 break;
1830 }
1831 } 1809 }
1832 } 1810 }
1833 else
1834 retval = Array<octave_idx_type> (a);
1835 } 1811 }
1836 } 1812 else
1837 1813 retval = Array<octave_idx_type> (a);
1838 1814 }
1839 if (error_state) 1815
1840 return retval; 1816 return retval.reshape (make_vector_dims (retval.dims (),
1841 else 1817 force_vector_conversion,
1842 return retval.reshape (make_vector_dims (retval.dims (), 1818 type_name (), "integer vector"));
1843 force_vector_conversion,
1844 type_name (), "integer vector"));
1845 } 1819 }
1846 1820
1847 Array<Complex> 1821 Array<Complex>
1848 octave_value::complex_vector_value (bool force_string_conv, 1822 octave_value::complex_vector_value (bool force_string_conv,
1849 bool force_vector_conversion) const 1823 bool force_vector_conversion) const
1850 { 1824 {
1851 Array<Complex> retval = complex_array_value (force_string_conv); 1825 Array<Complex> retval = complex_array_value (force_string_conv);
1852 1826
1853 if (error_state) 1827 return retval.reshape (make_vector_dims (retval.dims (),
1854 return retval; 1828 force_vector_conversion,
1855 else 1829 type_name (), "complex vector"));
1856 return retval.reshape (make_vector_dims (retval.dims (),
1857 force_vector_conversion,
1858 type_name (), "complex vector"));
1859 } 1830 }
1860 1831
1861 FloatColumnVector 1832 FloatColumnVector
1862 octave_value::float_column_vector_value (bool force_string_conv, 1833 octave_value::float_column_vector_value (bool force_string_conv,
1863 bool frc_vec_conv) const 1834 bool frc_vec_conv) const
1895 octave_value::float_vector_value (bool force_string_conv, 1866 octave_value::float_vector_value (bool force_string_conv,
1896 bool force_vector_conversion) const 1867 bool force_vector_conversion) const
1897 { 1868 {
1898 Array<float> retval = float_array_value (force_string_conv); 1869 Array<float> retval = float_array_value (force_string_conv);
1899 1870
1900 if (error_state) 1871 return retval.reshape (make_vector_dims (retval.dims (),
1901 return retval; 1872 force_vector_conversion,
1902 else 1873 type_name (), "real vector"));
1903 return retval.reshape (make_vector_dims (retval.dims (),
1904 force_vector_conversion,
1905 type_name (), "real vector"));
1906 } 1874 }
1907 1875
1908 Array<FloatComplex> 1876 Array<FloatComplex>
1909 octave_value::float_complex_vector_value (bool force_string_conv, 1877 octave_value::float_complex_vector_value (bool force_string_conv,
1910 bool force_vector_conversion) const 1878 bool force_vector_conversion) const
1911 { 1879 {
1912 Array<FloatComplex> retval = float_complex_array_value (force_string_conv); 1880 Array<FloatComplex> retval = float_complex_array_value (force_string_conv);
1913 1881
1914 if (error_state) 1882 return retval.reshape (make_vector_dims (retval.dims (),
1915 return retval; 1883 force_vector_conversion,
1916 else 1884 type_name (), "complex vector"));
1917 return retval.reshape (make_vector_dims (retval.dims (),
1918 force_vector_conversion,
1919 type_name (), "complex vector"));
1920 } 1885 }
1921 1886
1922 octave_value 1887 octave_value
1923 octave_value::storable_value (void) const 1888 octave_value::storable_value (void) const
1924 { 1889 {
2964 std::string type; 2929 std::string type;
2965 std::list<octave_value_list> idx; 2930 std::list<octave_value_list> idx;
2966 2931
2967 decode_subscripts ("subsref", args(1), type, idx); 2932 decode_subscripts ("subsref", args(1), type, idx);
2968 2933
2969 if (! error_state) 2934 octave_value arg0 = args(0);
2970 { 2935
2971 octave_value arg0 = args(0); 2936 if (type.empty ())
2972 2937 retval = arg0;
2973 if (type.empty ()) 2938 else
2974 retval = arg0; 2939 retval = arg0.subsref (type, idx, nargout);
2975 else
2976 retval = arg0.subsref (type, idx, nargout);
2977 }
2978 } 2940 }
2979 else 2941 else
2980 print_usage (); 2942 print_usage ();
2981 2943
2982 return retval; 2944 return retval;
3022 std::string type; 2984 std::string type;
3023 std::list<octave_value_list> idx; 2985 std::list<octave_value_list> idx;
3024 2986
3025 decode_subscripts ("subsasgn", args(1), type, idx); 2987 decode_subscripts ("subsasgn", args(1), type, idx);
3026 2988
3027 if (! error_state) 2989 if (type.empty ())
3028 { 2990 {
3029 if (type.empty ()) 2991 // Regularize a null matrix if stored into a variable.
3030 { 2992
3031 // Regularize a null matrix if stored into a variable. 2993 retval = args(2).storable_value ();
3032 2994 }
3033 retval = args(2).storable_value (); 2995 else
3034 } 2996 {
3035 else 2997 octave_value arg0 = args(0);
3036 { 2998
3037 octave_value arg0 = args(0); 2999 arg0.make_unique ();
3038 3000
3039 arg0.make_unique (); 3001 retval= arg0.subsasgn (type, idx, args(2));
3040
3041 if (! error_state)
3042 retval= arg0.subsasgn (type, idx, args(2));
3043 }
3044 } 3002 }
3045 } 3003 }
3046 else 3004 else
3047 print_usage (); 3005 print_usage ();
3048 3006