comparison libinterp/octave-value/ov-class.cc @ 20593:c41595061186

eliminate more simple uses of error_state * betainc.cc, file-io.cc, ov-class.cc, ov-struct.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Mon, 05 Oct 2015 23:09:54 -0400
parents b70cc4bd8109
children 729a85dafba8
comparison
equal deleted inserted replaced
20592:56fee8f84fe7 20593:c41595061186
201 } 201 }
202 } 202 }
203 } 203 }
204 } 204 }
205 205
206 if (! error_state) 206 symbol_table::add_to_parent_map (id, parent_list);
207 symbol_table::add_to_parent_map (id, parent_list);
208 } 207 }
209 208
210 octave_base_value * 209 octave_base_value *
211 octave_class::unique_clone (void) 210 octave_class::unique_clone (void)
212 { 211 {
400 std::list<octave_value_list>::const_iterator p = idx.begin (); 399 std::list<octave_value_list>::const_iterator p = idx.begin ();
401 octave_value_list key_idx = *++p; 400 octave_value_list key_idx = *++p;
402 401
403 Cell tmp = dotref (key_idx); 402 Cell tmp = dotref (key_idx);
404 403
405 if (! error_state) 404 Cell t = tmp.index (idx.front ());
406 { 405
407 Cell t = tmp.index (idx.front ()); 406 retval(0) = (t.numel () == 1) ? t(0)
408 407 : octave_value (t, true);
409 retval(0) = (t.numel () == 1) ? t(0) 408
410 : octave_value (t, true); 409 // We handled two index elements, so tell
411 410 // next_subsref to skip both of them.
412 // We handled two index elements, so tell 411
413 // next_subsref to skip both of them. 412 skip++;
414
415 skip++;
416 }
417 } 413 }
418 else 414 else
419 retval(0) = octave_value (map.index (idx.front ()), 415 retval(0) = octave_value (map.index (idx.front ()),
420 c_name, parent_list); 416 c_name, parent_list);
421 } 417 }
454 if (meth.is_defined ()) 450 if (meth.is_defined ())
455 { 451 {
456 octave_value_list args; 452 octave_value_list args;
457 453
458 args(1) = make_idx_args (type, idx, "subsref"); 454 args(1) = make_idx_args (type, idx, "subsref");
459
460 if (error_state)
461 return octave_value_list ();
462 455
463 count++; 456 count++;
464 args(0) = octave_value (this); 457 args(0) = octave_value (this);
465 458
466 // FIXME: for Matlab compatibility, let us attempt to set up a proper 459 // FIXME: for Matlab compatibility, let us attempt to set up a proper
567 } 560 }
568 else 561 else
569 args(2) = rhs; 562 args(2) = rhs;
570 563
571 args(1) = make_idx_args (type, idx, "subsasgn"); 564 args(1) = make_idx_args (type, idx, "subsasgn");
572
573 if (error_state)
574 return octave_value_list ();
575
576 args(0) = obj; 565 args(0) = obj;
577 566
578 // Now comes the magic. Count copies with me: 567 // Now comes the magic. Count copies with me:
579 // 1. myself (obsolete) 568 // 1. myself (obsolete)
580 // 2. the copy inside args (obsolete) 569 // 2. the copy inside args (obsolete)
626 { 615 {
627 616
628 if (obvp) 617 if (obvp)
629 { 618 {
630 obvp->subsasgn (type, idx, rhs); 619 obvp->subsasgn (type, idx, rhs);
620
631 if (! error_state) 621 if (! error_state)
632 { 622 {
633 count++; 623 count++;
634 retval = octave_value (this); 624 retval = octave_value (this);
635 } 625 }
680 Cell map_elt = map_val.index (idx.front (), true); 670 Cell map_elt = map_val.index (idx.front (), true);
681 671
682 u = numeric_conv (map_elt, type.substr (2)); 672 u = numeric_conv (map_elt, type.substr (2));
683 } 673 }
684 674
685 if (! error_state) 675 std::list<octave_value_list> next_idx (idx);
686 { 676
687 std::list<octave_value_list> next_idx (idx); 677 // We handled two index elements, so subsasgn to
688 678 // needs to skip both of them.
689 // We handled two index elements, so subsasgn to 679
690 // needs to skip both of them. 680 next_idx.erase (next_idx.begin ());
691 681 next_idx.erase (next_idx.begin ());
692 next_idx.erase (next_idx.begin ()); 682
693 next_idx.erase (next_idx.begin ()); 683 u.make_unique ();
694 684
695 u.make_unique (); 685 t_rhs = u.subsasgn (type.substr (2), next_idx, rhs);
696
697 t_rhs = u.subsasgn (type.substr (2), next_idx, rhs);
698 }
699 } 686 }
700 else 687 else
701 gripe_invalid_index_for_assignment (); 688 gripe_invalid_index_for_assignment ();
702 } 689 }
703 else 690 else
726 map.contents (pkey).make_unique (); 713 map.contents (pkey).make_unique ();
727 tmpc = map.contents (pkey); 714 tmpc = map.contents (pkey);
728 } 715 }
729 716
730 // FIXME: better code reuse? 717 // FIXME: better code reuse?
731 if (! error_state) 718 if (tmpc.numel () == 1)
732 { 719 {
733 if (tmpc.numel () == 1) 720 octave_value& tmp = tmpc(0);
721
722 if (! tmp.is_defined () || tmp.is_zero_by_zero ())
734 { 723 {
735 octave_value& tmp = tmpc(0); 724 tmp = octave_value::empty_conv (next_type, rhs);
736 725 tmp.make_unique (); // probably a no-op.
737 if (! tmp.is_defined () || tmp.is_zero_by_zero ())
738 {
739 tmp = octave_value::empty_conv (next_type, rhs);
740 tmp.make_unique (); // probably a no-op.
741 }
742 else
743 // optimization: ignore copy still stored inside our map.
744 tmp.make_unique (1);
745
746 if (! error_state)
747 t_rhs = tmp.subsasgn (next_type, next_idx, rhs);
748 } 726 }
749 else 727 else
750 gripe_indexed_cs_list (); 728 // optimization: ignore copy still stored inside our map.
729 tmp.make_unique (1);
730
731 t_rhs = tmp.subsasgn (next_type, next_idx, rhs);
751 } 732 }
733 else
734 gripe_indexed_cs_list ();
752 } 735 }
753 break; 736 break;
754 737
755 case '{': 738 case '{':
756 gripe_invalid_index_type (type_name (), type[0]); 739 gripe_invalid_index_type (type_name (), type[0]);
897 octave_value_list args; 880 octave_value_list args;
898 args(0) = octave_value (new octave_class (map, c_name, parent_list)); 881 args(0) = octave_value (new octave_class (map, c_name, parent_list));
899 882
900 octave_value_list tmp = feval (meth.function_value (), args, 1); 883 octave_value_list tmp = feval (meth.function_value (), args, 1);
901 884
902 if (!error_state && tmp.length () >= 1) 885 if (tmp(0).is_object ())
903 { 886 error ("subsindex function must return a valid index vector");
904 if (tmp(0).is_object ()) 887 else
905 error ("subsindex function must return a valid index vector"); 888 // Index vector returned by subsindex is zero based
906 else 889 // (why this inconsistency Mathworks?), and so we must
907 // Index vector returned by subsindex is zero based 890 // add one to the value returned as the index_vector method
908 // (why this inconsistency Mathworks?), and so we must 891 // expects it to be one based.
909 // add one to the value returned as the index_vector method 892 retval = do_binary_op (octave_value::op_add, tmp (0),
910 // expects it to be one based. 893 octave_value (1.0)).index_vector (require_integers);
911 retval = do_binary_op (octave_value::op_add, tmp (0),
912 octave_value (1.0)).index_vector (require_integers);
913 }
914 } 894 }
915 else 895 else
916 error ("no subsindex method defined for class %s", 896 error ("no subsindex method defined for class %s",
917 class_name ().c_str ()); 897 class_name ().c_str ());
918 898
1056 octave_value_list args; 1036 octave_value_list args;
1057 args(0) = octave_value (new octave_class (map, c_name, parent_list)); 1037 args(0) = octave_value (new octave_class (map, c_name, parent_list));
1058 1038
1059 octave_value_list tmp = feval (meth.function_value (), args, 1); 1039 octave_value_list tmp = feval (meth.function_value (), args, 1);
1060 1040
1061 if (!error_state && tmp.length () >= 1) 1041 if (tmp.length () >= 1)
1062 { 1042 {
1063 if (tmp(0).is_string ()) 1043 if (tmp(0).is_string ())
1064 retval = tmp(0).all_strings (pad); 1044 retval = tmp(0).all_strings (pad);
1065 else 1045 else
1066 error ("cname/char method did not return a string"); 1046 error ("cname/char method did not return a string");
1268 octave_map m; 1248 octave_map m;
1269 if (load_path::find_method (class_name (), "saveobj") != std::string ()) 1249 if (load_path::find_method (class_name (), "saveobj") != std::string ())
1270 { 1250 {
1271 octave_value in = new octave_class (*this); 1251 octave_value in = new octave_class (*this);
1272 octave_value_list tmp = feval ("saveobj", in, 1); 1252 octave_value_list tmp = feval ("saveobj", in, 1);
1273 if (! error_state) 1253
1274 m = tmp(0).map_value (); 1254 m = tmp(0).map_value ();
1275 else
1276 return false;
1277 } 1255 }
1278 else 1256 else
1279 m = map_value (); 1257 m = map_value ();
1280 1258
1281 os << "# length: " << m.nfields () << "\n"; 1259 os << "# length: " << m.nfields () << "\n";
1348 != std::string ()) 1326 != std::string ())
1349 { 1327 {
1350 octave_value in = new octave_class (*this); 1328 octave_value in = new octave_class (*this);
1351 octave_value_list tmp = feval ("loadobj", in, 1); 1329 octave_value_list tmp = feval ("loadobj", in, 1);
1352 1330
1353 if (! error_state) 1331 map = tmp(0).map_value ();
1354 map = tmp(0).map_value ();
1355 else
1356 success = false;
1357 } 1332 }
1358 } 1333 }
1359 else 1334 else
1360 { 1335 {
1361 error ("load: failed to load class"); 1336 error ("load: failed to load class");
1396 octave_map m; 1371 octave_map m;
1397 if (load_path::find_method (class_name (), "saveobj") != std::string ()) 1372 if (load_path::find_method (class_name (), "saveobj") != std::string ())
1398 { 1373 {
1399 octave_value in = new octave_class (*this); 1374 octave_value in = new octave_class (*this);
1400 octave_value_list tmp = feval ("saveobj", in, 1); 1375 octave_value_list tmp = feval ("saveobj", in, 1);
1401 if (! error_state) 1376
1402 m = tmp(0).map_value (); 1377 m = tmp(0).map_value ();
1403 else
1404 return false;
1405 } 1378 }
1406 else 1379 else
1407 m = map_value (); 1380 m = map_value ();
1408 1381
1409 int32_t len = m.nfields (); 1382 int32_t len = m.nfields ();
1492 if (load_path::find_method (c_name, "loadobj") != std::string ()) 1465 if (load_path::find_method (c_name, "loadobj") != std::string ())
1493 { 1466 {
1494 octave_value in = new octave_class (*this); 1467 octave_value in = new octave_class (*this);
1495 octave_value_list tmp = feval ("loadobj", in, 1); 1468 octave_value_list tmp = feval ("loadobj", in, 1);
1496 1469
1497 if (! error_state) 1470 map = tmp(0).map_value ();
1498 map = tmp(0).map_value ();
1499 else
1500 success = false;
1501 } 1471 }
1502 } 1472 }
1503 else 1473 else
1504 { 1474 {
1505 warning ("load: failed to load class"); 1475 warning ("load: failed to load class");
1567 1537
1568 if (load_path::find_method (class_name (), "saveobj") != std::string ()) 1538 if (load_path::find_method (class_name (), "saveobj") != std::string ())
1569 { 1539 {
1570 octave_value in = new octave_class (*this); 1540 octave_value in = new octave_class (*this);
1571 octave_value_list tmp = feval ("saveobj", in, 1); 1541 octave_value_list tmp = feval ("saveobj", in, 1);
1572 if (! error_state) 1542
1573 m = tmp(0).map_value (); 1543 m = tmp(0).map_value ();
1574 else
1575 goto error_cleanup;
1576 } 1544 }
1577 else 1545 else
1578 m = map_value (); 1546 m = map_value ();
1579 1547
1580 // recursively add each element of the class to this group 1548 // recursively add each element of the class to this group
1738 if (load_path::find_method (c_name, "loadobj") != std::string ()) 1706 if (load_path::find_method (c_name, "loadobj") != std::string ())
1739 { 1707 {
1740 octave_value in = new octave_class (*this); 1708 octave_value in = new octave_class (*this);
1741 octave_value_list tmp = feval ("loadobj", in, 1); 1709 octave_value_list tmp = feval ("loadobj", in, 1);
1742 1710
1743 if (! error_state) 1711 map = tmp(0).map_value ();
1744 { 1712 retval = true;
1745 map = tmp(0).map_value ();
1746 retval = true;
1747 }
1748 else
1749 retval = false;
1750 } 1713 }
1751 } 1714 }
1752 1715
1753 error_cleanup: 1716 error_cleanup:
1754 if (data_hid > 0) 1717 if (data_hid > 0)
1915 1878
1916 retval 1879 retval
1917 = octave_value (new octave_class (m, id, parents)); 1880 = octave_value (new octave_class (m, id, parents));
1918 } 1881 }
1919 1882
1920 if (! error_state) 1883 octave_class::exemplar_const_iterator it
1921 { 1884 = octave_class::exemplar_map.find (id);
1922 octave_class::exemplar_const_iterator it 1885
1923 = octave_class::exemplar_map.find (id); 1886 if (it == octave_class::exemplar_map.end ())
1924 1887 octave_class::exemplar_map[id]
1925 if (it == octave_class::exemplar_map.end ()) 1888 = octave_class::exemplar_info (retval);
1926 octave_class::exemplar_map[id] 1889 else if (! it->second.compare (retval))
1927 = octave_class::exemplar_info (retval); 1890 error ("class: object of class '%s' does not match previously constructed objects",
1928 else if (! it->second.compare (retval)) 1891 id.c_str ());
1929 error ("class: object of class '%s' does not match previously constructed objects",
1930 id.c_str ());
1931 }
1932 } 1892 }
1933 else 1893 else
1934 error ("class: expecting structure S as first argument"); 1894 error ("class: expecting structure S as first argument");
1935 } 1895 }
1936 else 1896 else
2135 else if (arg.is_string ()) 2095 else if (arg.is_string ())
2136 class_name = arg.string_value (); 2096 class_name = arg.string_value ();
2137 else 2097 else
2138 error ("ismethod: expecting object or class name as first argument"); 2098 error ("ismethod: expecting object or class name as first argument");
2139 2099
2140 if (! error_state) 2100 std::string method = args(1).string_value ();
2141 { 2101
2142 std::string method = args(1).string_value (); 2102 if (load_path::find_method (class_name, method) != std::string ())
2143 2103 retval = true;
2144 if (! error_state) 2104 else
2145 { 2105 retval = false;
2146 if (load_path::find_method (class_name, method) != std::string ())
2147 retval = true;
2148 else
2149 retval = false;
2150 }
2151 }
2152 } 2106 }
2153 else 2107 else
2154 print_usage (); 2108 print_usage ();
2155 2109
2156 return retval; 2110 return retval;
2176 if (arg.is_object ()) 2130 if (arg.is_object ())
2177 class_name = arg.class_name (); 2131 class_name = arg.class_name ();
2178 else if (arg.is_string ()) 2132 else if (arg.is_string ())
2179 class_name = arg.string_value (); 2133 class_name = arg.string_value ();
2180 2134
2181 if (! error_state) 2135 string_vector sv = load_path::methods (class_name);
2182 { 2136 retval = Cell (sv);
2183 string_vector sv = load_path::methods (class_name);
2184 retval = Cell (sv);
2185 }
2186 2137
2187 return retval; 2138 return retval;
2188 } 2139 }
2189 2140
2190 static bool 2141 static bool