comparison src/ov.cc @ 10315:57a59eae83cc

untabify src C++ source files
author John W. Eaton <jwe@octave.org>
date Thu, 11 Feb 2010 12:41:46 -0500
parents 0efd486813fe
children 8b3cfc1288e2
comparison
equal deleted inserted replaced
10314:07ebe522dac2 10315:57a59eae83cc
578 { 578 {
579 } 579 }
580 580
581 octave_value::octave_value (const Cell& c, bool is_csl) 581 octave_value::octave_value (const Cell& c, bool is_csl)
582 : rep (is_csl 582 : rep (is_csl
583 ? dynamic_cast<octave_base_value *> (new octave_cs_list (c)) 583 ? dynamic_cast<octave_base_value *> (new octave_cs_list (c))
584 : dynamic_cast<octave_base_value *> (new octave_cell (c))) 584 : dynamic_cast<octave_base_value *> (new octave_cell (c)))
585 { 585 {
586 } 586 }
587 587
588 octave_value::octave_value (const Array<octave_value>& a, bool is_csl) 588 octave_value::octave_value (const Array<octave_value>& a, bool is_csl)
589 : rep (is_csl 589 : rep (is_csl
590 ? dynamic_cast<octave_base_value *> (new octave_cs_list (Cell (a))) 590 ? dynamic_cast<octave_base_value *> (new octave_cs_list (Cell (a)))
591 : dynamic_cast<octave_base_value *> (new octave_cell (Cell (a)))) 591 : dynamic_cast<octave_base_value *> (new octave_cell (Cell (a))))
592 { 592 {
593 } 593 }
594 594
595 octave_value::octave_value (const Matrix& m, const MatrixType& t) 595 octave_value::octave_value (const Matrix& m, const MatrixType& t)
596 : rep (new octave_matrix (m, t)) 596 : rep (new octave_matrix (m, t))
777 maybe_mutate (); 777 maybe_mutate ();
778 } 778 }
779 779
780 octave_value::octave_value (char c, char type) 780 octave_value::octave_value (char c, char type)
781 : rep (type == '"' 781 : rep (type == '"'
782 ? new octave_char_matrix_dq_str (c) 782 ? new octave_char_matrix_dq_str (c)
783 : new octave_char_matrix_sq_str (c)) 783 : new octave_char_matrix_sq_str (c))
784 { 784 {
785 maybe_mutate (); 785 maybe_mutate ();
786 } 786 }
787 787
788 octave_value::octave_value (const char *s, char type) 788 octave_value::octave_value (const char *s, char type)
789 : rep (type == '"' 789 : rep (type == '"'
790 ? new octave_char_matrix_dq_str (s) 790 ? new octave_char_matrix_dq_str (s)
791 : new octave_char_matrix_sq_str (s)) 791 : new octave_char_matrix_sq_str (s))
792 { 792 {
793 maybe_mutate (); 793 maybe_mutate ();
794 } 794 }
795 795
796 octave_value::octave_value (const std::string& s, char type) 796 octave_value::octave_value (const std::string& s, char type)
797 : rep (type == '"' 797 : rep (type == '"'
798 ? new octave_char_matrix_dq_str (s) 798 ? new octave_char_matrix_dq_str (s)
799 : new octave_char_matrix_sq_str (s)) 799 : new octave_char_matrix_sq_str (s))
800 { 800 {
801 maybe_mutate (); 801 maybe_mutate ();
802 } 802 }
803 803
804 octave_value::octave_value (const string_vector& s, char type) 804 octave_value::octave_value (const string_vector& s, char type)
805 : rep (type == '"' 805 : rep (type == '"'
806 ? new octave_char_matrix_dq_str (s) 806 ? new octave_char_matrix_dq_str (s)
807 : new octave_char_matrix_sq_str (s)) 807 : new octave_char_matrix_sq_str (s))
808 { 808 {
809 maybe_mutate (); 809 maybe_mutate ();
810 } 810 }
811 811
812 octave_value::octave_value (const charMatrix& chm, char type) 812 octave_value::octave_value (const charMatrix& chm, char type)
813 : rep (type == '"' 813 : rep (type == '"'
814 ? new octave_char_matrix_dq_str (chm) 814 ? new octave_char_matrix_dq_str (chm)
815 : new octave_char_matrix_sq_str (chm)) 815 : new octave_char_matrix_sq_str (chm))
816 { 816 {
817 maybe_mutate (); 817 maybe_mutate ();
818 } 818 }
819 819
820 octave_value::octave_value (const charNDArray& chm, char type) 820 octave_value::octave_value (const charNDArray& chm, char type)
821 : rep (type == '"' 821 : rep (type == '"'
822 ? new octave_char_matrix_dq_str (chm) 822 ? new octave_char_matrix_dq_str (chm)
823 : new octave_char_matrix_sq_str (chm)) 823 : new octave_char_matrix_sq_str (chm))
824 { 824 {
825 maybe_mutate (); 825 maybe_mutate ();
826 } 826 }
827 827
828 octave_value::octave_value (const Array<char>& chm, char type) 828 octave_value::octave_value (const Array<char>& chm, char type)
829 : rep (type == '"' 829 : rep (type == '"'
830 ? new octave_char_matrix_dq_str (chm) 830 ? new octave_char_matrix_dq_str (chm)
831 : new octave_char_matrix_sq_str (chm)) 831 : new octave_char_matrix_sq_str (chm))
832 { 832 {
833 maybe_mutate (); 833 maybe_mutate ();
834 } 834 }
835 835
836 octave_value::octave_value (const charMatrix& chm, bool, char type) 836 octave_value::octave_value (const charMatrix& chm, bool, char type)
837 : rep (type == '"' 837 : rep (type == '"'
838 ? new octave_char_matrix_dq_str (chm) 838 ? new octave_char_matrix_dq_str (chm)
839 : new octave_char_matrix_sq_str (chm)) 839 : new octave_char_matrix_sq_str (chm))
840 { 840 {
841 maybe_mutate (); 841 maybe_mutate ();
842 } 842 }
843 843
844 octave_value::octave_value (const charNDArray& chm, bool, char type) 844 octave_value::octave_value (const charNDArray& chm, bool, char type)
845 : rep (type == '"' 845 : rep (type == '"'
846 ? new octave_char_matrix_dq_str (chm) 846 ? new octave_char_matrix_dq_str (chm)
847 : new octave_char_matrix_sq_str (chm)) 847 : new octave_char_matrix_sq_str (chm))
848 { 848 {
849 maybe_mutate (); 849 maybe_mutate ();
850 } 850 }
851 851
852 octave_value::octave_value (const Array<char>& chm, bool, char type) 852 octave_value::octave_value (const Array<char>& chm, bool, char type)
853 : rep (type == '"' 853 : rep (type == '"'
854 ? new octave_char_matrix_dq_str (chm) 854 ? new octave_char_matrix_dq_str (chm)
855 : new octave_char_matrix_sq_str (chm)) 855 : new octave_char_matrix_sq_str (chm))
856 { 856 {
857 maybe_mutate (); 857 maybe_mutate ();
858 } 858 }
859 859
860 octave_value::octave_value (const SparseMatrix& m, const MatrixType &t) 860 octave_value::octave_value (const SparseMatrix& m, const MatrixType &t)
1145 octave_base_value *tmp = rep->try_narrowing_conversion (); 1145 octave_base_value *tmp = rep->try_narrowing_conversion ();
1146 1146
1147 if (tmp && tmp != rep) 1147 if (tmp && tmp != rep)
1148 { 1148 {
1149 if (--rep->count == 0) 1149 if (--rep->count == 0)
1150 delete rep; 1150 delete rep;
1151 1151
1152 rep = tmp; 1152 rep = tmp;
1153 } 1153 }
1154 } 1154 }
1155 1155
1156 octave_value 1156 octave_value
1157 octave_value::single_subsref (const std::string& type, 1157 octave_value::single_subsref (const std::string& type,
1158 const octave_value_list& idx) 1158 const octave_value_list& idx)
1159 { 1159 {
1160 std::list<octave_value_list> i; 1160 std::list<octave_value_list> i;
1161 1161
1162 i.push_back (idx); 1162 i.push_back (idx);
1163 1163
1164 return rep->subsref (type, i); 1164 return rep->subsref (type, i);
1165 } 1165 }
1166 1166
1167 octave_value_list 1167 octave_value_list
1168 octave_value::subsref (const std::string& type, 1168 octave_value::subsref (const std::string& type,
1169 const std::list<octave_value_list>& idx, int nargout) 1169 const std::list<octave_value_list>& idx, int nargout)
1170 { 1170 {
1171 if (nargout == 1) 1171 if (nargout == 1)
1172 return rep->subsref (type, idx); 1172 return rep->subsref (type, idx);
1173 else 1173 else
1174 return rep->subsref (type, idx, nargout); 1174 return rep->subsref (type, idx, nargout);
1175 } 1175 }
1176 1176
1177 octave_value 1177 octave_value
1178 octave_value::next_subsref (const std::string& type, 1178 octave_value::next_subsref (const std::string& type,
1179 const std::list<octave_value_list>& idx, 1179 const std::list<octave_value_list>& idx,
1180 size_t skip) 1180 size_t skip)
1181 { 1181 {
1182 if (! error_state && idx.size () > skip) 1182 if (! error_state && idx.size () > skip)
1183 { 1183 {
1184 std::list<octave_value_list> new_idx (idx); 1184 std::list<octave_value_list> new_idx (idx);
1185 for (size_t i = 0; i < skip; i++) 1185 for (size_t i = 0; i < skip; i++)
1186 new_idx.erase (new_idx.begin ()); 1186 new_idx.erase (new_idx.begin ());
1187 return subsref (type.substr (skip), new_idx); 1187 return subsref (type.substr (skip), new_idx);
1188 } 1188 }
1189 else 1189 else
1190 return *this; 1190 return *this;
1191 } 1191 }
1192 1192
1193 octave_value_list 1193 octave_value_list
1194 octave_value::next_subsref (int nargout, const std::string& type, 1194 octave_value::next_subsref (int nargout, const std::string& type,
1195 const std::list<octave_value_list>& idx, 1195 const std::list<octave_value_list>& idx,
1196 size_t skip) 1196 size_t skip)
1197 { 1197 {
1198 if (! error_state && idx.size () > skip) 1198 if (! error_state && idx.size () > skip)
1199 { 1199 {
1200 std::list<octave_value_list> new_idx (idx); 1200 std::list<octave_value_list> new_idx (idx);
1201 for (size_t i = 0; i < skip; i++) 1201 for (size_t i = 0; i < skip; i++)
1202 new_idx.erase (new_idx.begin ()); 1202 new_idx.erase (new_idx.begin ());
1203 return subsref (type.substr (skip), new_idx, nargout); 1203 return subsref (type.substr (skip), new_idx, nargout);
1204 } 1204 }
1205 else 1205 else
1206 return *this; 1206 return *this;
1207 } 1207 }
1208 1208
1209 octave_value 1209 octave_value
1210 octave_value::next_subsref (bool auto_add, const std::string& type, 1210 octave_value::next_subsref (bool auto_add, const std::string& type,
1211 const std::list<octave_value_list>& idx, 1211 const std::list<octave_value_list>& idx,
1212 size_t skip) 1212 size_t skip)
1213 { 1213 {
1214 if (! error_state && idx.size () > skip) 1214 if (! error_state && idx.size () > skip)
1215 { 1215 {
1216 std::list<octave_value_list> new_idx (idx); 1216 std::list<octave_value_list> new_idx (idx);
1217 for (size_t i = 0; i < skip; i++) 1217 for (size_t i = 0; i < skip; i++)
1218 new_idx.erase (new_idx.begin ()); 1218 new_idx.erase (new_idx.begin ());
1219 return subsref (type.substr (skip), new_idx, auto_add); 1219 return subsref (type.substr (skip), new_idx, auto_add);
1220 } 1220 }
1221 else 1221 else
1222 return *this; 1222 return *this;
1223 } 1223 }
1229 } 1229 }
1230 1230
1231 #if 0 1231 #if 0
1232 static void 1232 static void
1233 gripe_assign_failed (const std::string& on, const std::string& tn1, 1233 gripe_assign_failed (const std::string& on, const std::string& tn1,
1234 const std::string& tn2) 1234 const std::string& tn2)
1235 { 1235 {
1236 error ("assignment failed for `%s %s %s'", 1236 error ("assignment failed for `%s %s %s'",
1237 tn1.c_str (), on.c_str (), tn2.c_str ()); 1237 tn1.c_str (), on.c_str (), tn2.c_str ());
1238 } 1238 }
1239 #endif 1239 #endif
1240 1240
1241 static void 1241 static void
1242 gripe_assign_failed_or_no_method (const std::string& on, 1242 gripe_assign_failed_or_no_method (const std::string& on,
1243 const std::string& tn1, 1243 const std::string& tn1,
1244 const std::string& tn2) 1244 const std::string& tn2)
1245 { 1245 {
1246 error ("assignment failed, or no method for `%s %s %s'", 1246 error ("assignment failed, or no method for `%s %s %s'",
1247 tn1.c_str (), on.c_str (), tn2.c_str ()); 1247 tn1.c_str (), on.c_str (), tn2.c_str ());
1248 } 1248 }
1249 1249
1250 octave_value 1250 octave_value
1251 octave_value::subsasgn (const std::string& type, 1251 octave_value::subsasgn (const std::string& type,
1252 const std::list<octave_value_list>& idx, 1252 const std::list<octave_value_list>& idx,
1253 const octave_value& rhs) 1253 const octave_value& rhs)
1254 { 1254 {
1255 return rep->subsasgn (type, idx, rhs); 1255 return rep->subsasgn (type, idx, rhs);
1256 } 1256 }
1257 1257
1258 octave_value 1258 octave_value
1259 octave_value::assign (assign_op op, const std::string& type, 1259 octave_value::assign (assign_op op, const std::string& type,
1260 const std::list<octave_value_list>& idx, 1260 const std::list<octave_value_list>& idx,
1261 const octave_value& rhs) 1261 const octave_value& rhs)
1262 { 1262 {
1263 octave_value retval; 1263 octave_value retval;
1264 1264
1265 make_unique (); 1265 make_unique ();
1266 1266
1269 if (op != op_asn_eq) 1269 if (op != op_asn_eq)
1270 { 1270 {
1271 octave_value t = subsref (type, idx); 1271 octave_value t = subsref (type, idx);
1272 1272
1273 if (! error_state) 1273 if (! error_state)
1274 { 1274 {
1275 binary_op binop = op_eq_to_binary_op (op); 1275 binary_op binop = op_eq_to_binary_op (op);
1276 1276
1277 if (! error_state) 1277 if (! error_state)
1278 t_rhs = do_binary_op (binop, t, rhs); 1278 t_rhs = do_binary_op (binop, t, rhs);
1279 } 1279 }
1280 } 1280 }
1281 1281
1282 if (! error_state) 1282 if (! error_state)
1283 { 1283 {
1284 if (type[0] == '.' && ! (is_map () || is_object ())) 1284 if (type[0] == '.' && ! (is_map () || is_object ()))
1285 { 1285 {
1286 octave_value tmp = Octave_map (); 1286 octave_value tmp = Octave_map ();
1287 retval = tmp.subsasgn (type, idx, t_rhs); 1287 retval = tmp.subsasgn (type, idx, t_rhs);
1288 } 1288 }
1289 else 1289 else
1290 retval = subsasgn (type, idx, t_rhs); 1290 retval = subsasgn (type, idx, t_rhs);
1291 1291
1292 if (error_state) 1292 if (error_state)
1293 gripe_assign_failed_or_no_method (assign_op_as_string (op_asn_eq), 1293 gripe_assign_failed_or_no_method (assign_op_as_string (op_asn_eq),
1294 type_name (), rhs.type_name ()); 1294 type_name (), rhs.type_name ());
1295 } 1295 }
1311 if (rep->count == 1) 1311 if (rep->count == 1)
1312 { 1312 {
1313 int tthis = this->type_id (); 1313 int tthis = this->type_id ();
1314 int trhs = rhs.type_id (); 1314 int trhs = rhs.type_id ();
1315 1315
1316 f = octave_value_typeinfo::lookup_assign_op (op, tthis, trhs); 1316 f = octave_value_typeinfo::lookup_assign_op (op, tthis, trhs);
1317 } 1317 }
1318 1318
1319 if (f) 1319 if (f)
1320 { 1320 {
1321 try 1321 try
1322 { 1322 {
1323 f (*rep, octave_value_list (), *rhs.rep); 1323 f (*rep, octave_value_list (), *rhs.rep);
1324 maybe_mutate (); // Usually unnecessary, but may be needed (complex arrays). 1324 maybe_mutate (); // Usually unnecessary, but may be needed (complex arrays).
1325 } 1325 }
1326 catch (octave_execution_exception) 1326 catch (octave_execution_exception)
1327 { 1327 {
1328 gripe_library_execution_error (); 1328 gripe_library_execution_error ();
1329 } 1329 }
1330 } 1330 }
1331 else 1331 else
1332 { 1332 {
1333 1333
1334 binary_op binop = op_eq_to_binary_op (op); 1334 binary_op binop = op_eq_to_binary_op (op);
1335 1335
1354 dim_vector dv = dims (); 1354 dim_vector dv = dims ();
1355 1355
1356 for (int i = 0; i < dv.length (); i++) 1356 for (int i = 0; i < dv.length (); i++)
1357 { 1357 {
1358 if (dv(i) < 0) 1358 if (dv(i) < 0)
1359 { 1359 {
1360 retval = -1; 1360 retval = -1;
1361 break; 1361 break;
1362 } 1362 }
1363 1363
1364 if (dv(i) == 0) 1364 if (dv(i) == 0)
1365 { 1365 {
1366 retval = 0; 1366 retval = 0;
1367 break; 1367 break;
1368 } 1368 }
1369 1369
1370 if (dv(i) > retval) 1370 if (dv(i) > retval)
1371 retval = dv(i); 1371 retval = dv(i);
1372 } 1372 }
1373 1373
1374 return retval; 1374 return retval;
1375 } 1375 }
1376 1376
1385 { 1385 {
1386 octave_value tmp = do_binary_op (octave_value::op_eq, *this, test); 1386 octave_value tmp = do_binary_op (octave_value::op_eq, *this, test);
1387 1387
1388 // Empty array also means a match. 1388 // Empty array also means a match.
1389 if (! error_state && tmp.is_defined ()) 1389 if (! error_state && tmp.is_defined ())
1390 retval = tmp.is_true () || tmp.is_empty (); 1390 retval = tmp.is_true () || tmp.is_empty ();
1391 } 1391 }
1392 1392
1393 return retval; 1393 return retval;
1394 } 1394 }
1395 1395
1513 frc_vec_conv)); 1513 frc_vec_conv));
1514 } 1514 }
1515 1515
1516 Array<double> 1516 Array<double>
1517 octave_value::vector_value (bool force_string_conv, 1517 octave_value::vector_value (bool force_string_conv,
1518 bool force_vector_conversion) const 1518 bool force_vector_conversion) const
1519 { 1519 {
1520 Array<double> retval = array_value (force_string_conv); 1520 Array<double> retval = array_value (force_string_conv);
1521 1521
1522 if (error_state) 1522 if (error_state)
1523 return retval; 1523 return retval;
1546 return retval; 1546 return retval;
1547 } 1547 }
1548 1548
1549 Array<int> 1549 Array<int>
1550 octave_value::int_vector_value (bool force_string_conv, bool require_int, 1550 octave_value::int_vector_value (bool force_string_conv, bool require_int,
1551 bool force_vector_conversion) const 1551 bool force_vector_conversion) const
1552 { 1552 {
1553 Array<int> retval; 1553 Array<int> retval;
1554 1554
1555 if (is_integer_type ()) 1555 if (is_integer_type ())
1556 { 1556 {
1628 } 1628 }
1629 1629
1630 Array<octave_idx_type> 1630 Array<octave_idx_type>
1631 octave_value::octave_idx_type_vector_value (bool require_int, 1631 octave_value::octave_idx_type_vector_value (bool require_int,
1632 bool force_string_conv, 1632 bool force_string_conv,
1633 bool force_vector_conversion) const 1633 bool force_vector_conversion) const
1634 { 1634 {
1635 Array<octave_idx_type> retval; 1635 Array<octave_idx_type> retval;
1636 1636
1637 if (is_integer_type ()) 1637 if (is_integer_type ())
1638 { 1638 {
1790 maybe_economize (); 1790 maybe_economize ();
1791 } 1791 }
1792 1792
1793 int 1793 int
1794 octave_value::write (octave_stream& os, int block_size, 1794 octave_value::write (octave_stream& os, int block_size,
1795 oct_data_conv::data_type output_type, int skip, 1795 oct_data_conv::data_type output_type, int skip,
1796 oct_mach_info::float_format flt_fmt) const 1796 oct_mach_info::float_format flt_fmt) const
1797 { 1797 {
1798 return rep->write (os, block_size, output_type, skip, flt_fmt); 1798 return rep->write (os, block_size, output_type, skip, flt_fmt);
1799 } 1799 }
1800 1800
1801 static void 1801 static void
1802 gripe_binary_op (const std::string& on, const std::string& tn1, 1802 gripe_binary_op (const std::string& on, const std::string& tn1,
1803 const std::string& tn2) 1803 const std::string& tn2)
1804 { 1804 {
1805 error ("binary operator `%s' not implemented for `%s' by `%s' operations", 1805 error ("binary operator `%s' not implemented for `%s' by `%s' operations",
1806 on.c_str (), tn1.c_str (), tn2.c_str ()); 1806 on.c_str (), tn1.c_str (), tn2.c_str ());
1807 } 1807 }
1808 1808
1809 static void 1809 static void
1810 gripe_binary_op_conv (const std::string& on) 1810 gripe_binary_op_conv (const std::string& on)
1811 { 1811 {
1812 error ("type conversion failed for binary operator `%s'", on.c_str ()); 1812 error ("type conversion failed for binary operator `%s'", on.c_str ());
1813 } 1813 }
1814 1814
1815 octave_value 1815 octave_value
1816 do_binary_op (octave_value::binary_op op, 1816 do_binary_op (octave_value::binary_op op,
1817 const octave_value& v1, const octave_value& v2) 1817 const octave_value& v1, const octave_value& v2)
1818 { 1818 {
1819 octave_value retval; 1819 octave_value retval;
1820 1820
1821 int t1 = v1.type_id (); 1821 int t1 = v1.type_id ();
1822 int t2 = v2.type_id (); 1822 int t2 = v2.type_id ();
1823 1823
1824 if (t1 == octave_class::static_type_id () 1824 if (t1 == octave_class::static_type_id ()
1825 || t2 == octave_class::static_type_id ()) 1825 || t2 == octave_class::static_type_id ())
1826 { 1826 {
1827 octave_value_typeinfo::binary_class_op_fcn f 1827 octave_value_typeinfo::binary_class_op_fcn f
1828 = octave_value_typeinfo::lookup_binary_class_op (op); 1828 = octave_value_typeinfo::lookup_binary_class_op (op);
1829 1829
1830 if (f) 1830 if (f)
1831 { 1831 {
1832 try 1832 try
1833 { 1833 {
1834 retval = f (v1, v2); 1834 retval = f (v1, v2);
1835 } 1835 }
1836 catch (octave_execution_exception) 1836 catch (octave_execution_exception)
1837 { 1837 {
1838 gripe_library_execution_error (); 1838 gripe_library_execution_error ();
1839 } 1839 }
1840 } 1840 }
1841 else 1841 else
1842 gripe_binary_op (octave_value::binary_op_as_string (op), 1842 gripe_binary_op (octave_value::binary_op_as_string (op),
1843 v1.class_name (), v2.class_name ()); 1843 v1.class_name (), v2.class_name ());
1844 } 1844 }
1845 else 1845 else
1846 { 1846 {
1847 // FIXME -- we need to handle overloading operators for built-in 1847 // FIXME -- we need to handle overloading operators for built-in
1848 // classes (double, char, int8, etc.) 1848 // classes (double, char, int8, etc.)
1849 1849
1850 octave_value_typeinfo::binary_op_fcn f 1850 octave_value_typeinfo::binary_op_fcn f
1851 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); 1851 = octave_value_typeinfo::lookup_binary_op (op, t1, t2);
1852 1852
1853 if (f) 1853 if (f)
1854 { 1854 {
1855 try 1855 try
1856 { 1856 {
1857 retval = f (*v1.rep, *v2.rep); 1857 retval = f (*v1.rep, *v2.rep);
1858 } 1858 }
1859 catch (octave_execution_exception) 1859 catch (octave_execution_exception)
1860 { 1860 {
1861 gripe_library_execution_error (); 1861 gripe_library_execution_error ();
1862 } 1862 }
1863 } 1863 }
1864 else 1864 else
1865 { 1865 {
1866 octave_value tv1; 1866 octave_value tv1;
1867 octave_base_value::type_conv_info cf1 = v1.numeric_conversion_function (); 1867 octave_base_value::type_conv_info cf1 = v1.numeric_conversion_function ();
1868 1868
1869 octave_value tv2; 1869 octave_value tv2;
1870 octave_base_value::type_conv_info cf2 = v2.numeric_conversion_function (); 1870 octave_base_value::type_conv_info cf2 = v2.numeric_conversion_function ();
1871 1871
1872 // Try biased (one-sided) conversions first. 1872 // Try biased (one-sided) conversions first.
1873 if (cf2.type_id () >= 0 && 1873 if (cf2.type_id () >= 0 &&
1874 octave_value_typeinfo::lookup_binary_op (op, t1, cf2.type_id ())) 1874 octave_value_typeinfo::lookup_binary_op (op, t1, cf2.type_id ()))
1875 cf1 = 0; 1875 cf1 = 0;
1876 else if (cf1.type_id () >= 0 && 1876 else if (cf1.type_id () >= 0 &&
1877 octave_value_typeinfo::lookup_binary_op (op, cf1.type_id (), t2)) 1877 octave_value_typeinfo::lookup_binary_op (op, cf1.type_id (), t2))
1878 cf2 = 0; 1878 cf2 = 0;
1879 1879
1880 if (cf1) 1880 if (cf1)
1881 { 1881 {
1882 octave_base_value *tmp = cf1 (*v1.rep); 1882 octave_base_value *tmp = cf1 (*v1.rep);
1883 1883
1884 if (tmp) 1884 if (tmp)
1885 { 1885 {
1886 tv1 = octave_value (tmp); 1886 tv1 = octave_value (tmp);
1887 t1 = tv1.type_id (); 1887 t1 = tv1.type_id ();
1888 } 1888 }
1889 else 1889 else
1890 { 1890 {
1891 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); 1891 gripe_binary_op_conv (octave_value::binary_op_as_string (op));
1892 return retval; 1892 return retval;
1893 } 1893 }
1894 } 1894 }
1895 else 1895 else
1896 tv1 = v1; 1896 tv1 = v1;
1897 1897
1898 if (cf2) 1898 if (cf2)
1899 { 1899 {
1900 octave_base_value *tmp = cf2 (*v2.rep); 1900 octave_base_value *tmp = cf2 (*v2.rep);
1901 1901
1902 if (tmp) 1902 if (tmp)
1903 { 1903 {
1904 tv2 = octave_value (tmp); 1904 tv2 = octave_value (tmp);
1905 t2 = tv2.type_id (); 1905 t2 = tv2.type_id ();
1906 } 1906 }
1907 else 1907 else
1908 { 1908 {
1909 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); 1909 gripe_binary_op_conv (octave_value::binary_op_as_string (op));
1910 return retval; 1910 return retval;
1911 } 1911 }
1912 } 1912 }
1913 else 1913 else
1914 tv2 = v2; 1914 tv2 = v2;
1915 1915
1916 if (cf1 || cf2) 1916 if (cf1 || cf2)
1917 { 1917 {
1918 retval = do_binary_op (op, tv1, tv2); 1918 retval = do_binary_op (op, tv1, tv2);
1919 } 1919 }
1920 else 1920 else
1921 { 1921 {
1922 //demote double -> single and try again 1922 //demote double -> single and try again
1923 cf1 = tv1.numeric_demotion_function (); 1923 cf1 = tv1.numeric_demotion_function ();
1924 1924
1925 cf2 = tv2.numeric_demotion_function (); 1925 cf2 = tv2.numeric_demotion_function ();
1926 1926
1927 // Try biased (one-sided) conversions first. 1927 // Try biased (one-sided) conversions first.
1928 if (cf2.type_id () >= 0 1928 if (cf2.type_id () >= 0
1929 && octave_value_typeinfo::lookup_binary_op (op, t1, cf2.type_id ())) 1929 && octave_value_typeinfo::lookup_binary_op (op, t1, cf2.type_id ()))
1930 cf1 = 0; 1930 cf1 = 0;
1931 else if (cf1.type_id () >= 0 1931 else if (cf1.type_id () >= 0
1932 && octave_value_typeinfo::lookup_binary_op (op, cf1.type_id (), t2)) 1932 && octave_value_typeinfo::lookup_binary_op (op, cf1.type_id (), t2))
1933 cf2 = 0; 1933 cf2 = 0;
1934 1934
1935 if (cf1) 1935 if (cf1)
1936 { 1936 {
1937 octave_base_value *tmp = cf1 (*tv1.rep); 1937 octave_base_value *tmp = cf1 (*tv1.rep);
1938 1938
1939 if (tmp) 1939 if (tmp)
1940 { 1940 {
1941 tv1 = octave_value (tmp); 1941 tv1 = octave_value (tmp);
1942 t1 = tv1.type_id (); 1942 t1 = tv1.type_id ();
1943 } 1943 }
1944 else 1944 else
1945 { 1945 {
1946 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); 1946 gripe_binary_op_conv (octave_value::binary_op_as_string (op));
1947 return retval; 1947 return retval;
1948 } 1948 }
1949 } 1949 }
1950 1950
1951 if (cf2) 1951 if (cf2)
1952 { 1952 {
1953 octave_base_value *tmp = cf2 (*tv2.rep); 1953 octave_base_value *tmp = cf2 (*tv2.rep);
1954 1954
1955 if (tmp) 1955 if (tmp)
1956 { 1956 {
1957 tv2 = octave_value (tmp); 1957 tv2 = octave_value (tmp);
1958 t2 = tv2.type_id (); 1958 t2 = tv2.type_id ();
1959 } 1959 }
1960 else 1960 else
1961 { 1961 {
1962 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); 1962 gripe_binary_op_conv (octave_value::binary_op_as_string (op));
1963 return retval; 1963 return retval;
1964 } 1964 }
1965 } 1965 }
1966 1966
1967 if (cf1 || cf2) 1967 if (cf1 || cf2)
1968 { 1968 {
1969 f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); 1969 f = octave_value_typeinfo::lookup_binary_op (op, t1, t2);
1970 1970
1971 if (f) 1971 if (f)
1972 { 1972 {
1973 try 1973 try
1974 { 1974 {
1975 retval = f (*tv1.rep, *tv2.rep); 1975 retval = f (*tv1.rep, *tv2.rep);
1976 } 1976 }
1977 catch (octave_execution_exception) 1977 catch (octave_execution_exception)
1978 { 1978 {
1979 gripe_library_execution_error (); 1979 gripe_library_execution_error ();
1980 } 1980 }
1981 } 1981 }
1982 else 1982 else
1983 gripe_binary_op (octave_value::binary_op_as_string (op), 1983 gripe_binary_op (octave_value::binary_op_as_string (op),
1984 v1.type_name (), v2.type_name ()); 1984 v1.type_name (), v2.type_name ());
1985 } 1985 }
1986 else 1986 else
1987 gripe_binary_op (octave_value::binary_op_as_string (op), 1987 gripe_binary_op (octave_value::binary_op_as_string (op),
1988 v1.type_name (), v2.type_name ()); 1988 v1.type_name (), v2.type_name ());
1989 } 1989 }
1990 } 1990 }
1991 } 1991 }
1992 1992
1993 return retval; 1993 return retval;
1994 } 1994 }
1995 1995
2070 2070
2071 if (t1 == octave_class::static_type_id () 2071 if (t1 == octave_class::static_type_id ()
2072 || t2 == octave_class::static_type_id ()) 2072 || t2 == octave_class::static_type_id ())
2073 { 2073 {
2074 octave_value_typeinfo::binary_class_op_fcn f 2074 octave_value_typeinfo::binary_class_op_fcn f
2075 = octave_value_typeinfo::lookup_binary_class_op (op); 2075 = octave_value_typeinfo::lookup_binary_class_op (op);
2076 2076
2077 if (f) 2077 if (f)
2078 { 2078 {
2079 try 2079 try
2080 { 2080 {
2081 retval = f (v1, v2); 2081 retval = f (v1, v2);
2082 } 2082 }
2083 catch (octave_execution_exception) 2083 catch (octave_execution_exception)
2084 { 2084 {
2085 gripe_library_execution_error (); 2085 gripe_library_execution_error ();
2086 } 2086 }
2087 } 2087 }
2088 else 2088 else
2089 retval = decompose_binary_op (op, v1, v2); 2089 retval = decompose_binary_op (op, v1, v2);
2090 } 2090 }
2091 else 2091 else
2092 { 2092 {
2093 octave_value_typeinfo::binary_op_fcn f 2093 octave_value_typeinfo::binary_op_fcn f
2094 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); 2094 = octave_value_typeinfo::lookup_binary_op (op, t1, t2);
2095 2095
2096 if (f) 2096 if (f)
2097 { 2097 {
2098 try 2098 try
2099 { 2099 {
2100 retval = f (*v1.rep, *v2.rep); 2100 retval = f (*v1.rep, *v2.rep);
2101 } 2101 }
2102 catch (octave_execution_exception) 2102 catch (octave_execution_exception)
2103 { 2103 {
2104 gripe_library_execution_error (); 2104 gripe_library_execution_error ();
2105 } 2105 }
2106 } 2106 }
2107 else 2107 else
2108 retval = decompose_binary_op (op, v1, v2); 2108 retval = decompose_binary_op (op, v1, v2);
2109 } 2109 }
2110 2110
2111 return retval; 2111 return retval;
2113 2113
2114 static void 2114 static void
2115 gripe_cat_op (const std::string& tn1, const std::string& tn2) 2115 gripe_cat_op (const std::string& tn1, const std::string& tn2)
2116 { 2116 {
2117 error ("concatenation operator not implemented for `%s' by `%s' operations", 2117 error ("concatenation operator not implemented for `%s' by `%s' operations",
2118 tn1.c_str (), tn2.c_str ()); 2118 tn1.c_str (), tn2.c_str ());
2119 } 2119 }
2120 2120
2121 static void 2121 static void
2122 gripe_cat_op_conv (void) 2122 gripe_cat_op_conv (void)
2123 { 2123 {
2124 error ("type conversion failed for concatenation operator"); 2124 error ("type conversion failed for concatenation operator");
2125 } 2125 }
2126 2126
2127 octave_value 2127 octave_value
2128 do_cat_op (const octave_value& v1, const octave_value& v2, 2128 do_cat_op (const octave_value& v1, const octave_value& v2,
2129 const Array<octave_idx_type>& ra_idx) 2129 const Array<octave_idx_type>& ra_idx)
2130 { 2130 {
2131 octave_value retval; 2131 octave_value retval;
2132 2132
2133 // Can't rapid return for concatenation with an empty object here as 2133 // Can't rapid return for concatenation with an empty object here as
2134 // something like cat(1,[],single([]) must return the correct type. 2134 // something like cat(1,[],single([]) must return the correct type.
2140 = octave_value_typeinfo::lookup_cat_op (t1, t2); 2140 = octave_value_typeinfo::lookup_cat_op (t1, t2);
2141 2141
2142 if (f) 2142 if (f)
2143 { 2143 {
2144 try 2144 try
2145 { 2145 {
2146 retval = f (*v1.rep, *v2.rep, ra_idx); 2146 retval = f (*v1.rep, *v2.rep, ra_idx);
2147 } 2147 }
2148 catch (octave_execution_exception) 2148 catch (octave_execution_exception)
2149 { 2149 {
2150 gripe_library_execution_error (); 2150 gripe_library_execution_error ();
2151 } 2151 }
2152 } 2152 }
2153 else 2153 else
2154 { 2154 {
2155 octave_value tv1; 2155 octave_value tv1;
2156 octave_base_value::type_conv_info cf1 = v1.numeric_conversion_function (); 2156 octave_base_value::type_conv_info cf1 = v1.numeric_conversion_function ();
2165 else if (cf1.type_id () >= 0 2165 else if (cf1.type_id () >= 0
2166 && octave_value_typeinfo::lookup_cat_op (cf1.type_id (), t2)) 2166 && octave_value_typeinfo::lookup_cat_op (cf1.type_id (), t2))
2167 cf2 = 0; 2167 cf2 = 0;
2168 2168
2169 if (cf1) 2169 if (cf1)
2170 { 2170 {
2171 octave_base_value *tmp = cf1 (*v1.rep); 2171 octave_base_value *tmp = cf1 (*v1.rep);
2172 2172
2173 if (tmp) 2173 if (tmp)
2174 { 2174 {
2175 tv1 = octave_value (tmp); 2175 tv1 = octave_value (tmp);
2176 t1 = tv1.type_id (); 2176 t1 = tv1.type_id ();
2177 } 2177 }
2178 else 2178 else
2179 { 2179 {
2180 gripe_cat_op_conv (); 2180 gripe_cat_op_conv ();
2181 return retval; 2181 return retval;
2182 } 2182 }
2183 } 2183 }
2184 else 2184 else
2185 tv1 = v1; 2185 tv1 = v1;
2186 2186
2187 if (cf2) 2187 if (cf2)
2188 { 2188 {
2189 octave_base_value *tmp = cf2 (*v2.rep); 2189 octave_base_value *tmp = cf2 (*v2.rep);
2190 2190
2191 if (tmp) 2191 if (tmp)
2192 { 2192 {
2193 tv2 = octave_value (tmp); 2193 tv2 = octave_value (tmp);
2194 t2 = tv2.type_id (); 2194 t2 = tv2.type_id ();
2195 } 2195 }
2196 else 2196 else
2197 { 2197 {
2198 gripe_cat_op_conv (); 2198 gripe_cat_op_conv ();
2199 return retval; 2199 return retval;
2200 } 2200 }
2201 } 2201 }
2202 else 2202 else
2203 tv2 = v2; 2203 tv2 = v2;
2204 2204
2205 if (cf1 || cf2) 2205 if (cf1 || cf2)
2206 { 2206 {
2207 retval = do_cat_op (tv1, tv2, ra_idx); 2207 retval = do_cat_op (tv1, tv2, ra_idx);
2208 } 2208 }
2209 else 2209 else
2210 gripe_cat_op (v1.type_name (), v2.type_name ()); 2210 gripe_cat_op (v1.type_name (), v2.type_name ());
2211 } 2211 }
2212 2212
2213 return retval; 2213 return retval;
2214 } 2214 }
2215 2215
2225 2225
2226 static void 2226 static void
2227 gripe_unary_op (const std::string& on, const std::string& tn) 2227 gripe_unary_op (const std::string& on, const std::string& tn)
2228 { 2228 {
2229 error ("unary operator `%s' not implemented for `%s' operands", 2229 error ("unary operator `%s' not implemented for `%s' operands",
2230 on.c_str (), tn.c_str ()); 2230 on.c_str (), tn.c_str ());
2231 } 2231 }
2232 2232
2233 static void 2233 static void
2234 gripe_unary_op_conv (const std::string& on) 2234 gripe_unary_op_conv (const std::string& on)
2235 { 2235 {
2244 int t = v.type_id (); 2244 int t = v.type_id ();
2245 2245
2246 if (t == octave_class::static_type_id ()) 2246 if (t == octave_class::static_type_id ())
2247 { 2247 {
2248 octave_value_typeinfo::unary_class_op_fcn f 2248 octave_value_typeinfo::unary_class_op_fcn f
2249 = octave_value_typeinfo::lookup_unary_class_op (op); 2249 = octave_value_typeinfo::lookup_unary_class_op (op);
2250 2250
2251 if (f) 2251 if (f)
2252 { 2252 {
2253 try 2253 try
2254 { 2254 {
2255 retval = f (v); 2255 retval = f (v);
2256 } 2256 }
2257 catch (octave_execution_exception) 2257 catch (octave_execution_exception)
2258 { 2258 {
2259 gripe_library_execution_error (); 2259 gripe_library_execution_error ();
2260 } 2260 }
2261 } 2261 }
2262 else 2262 else
2263 gripe_unary_op (octave_value::unary_op_as_string (op), 2263 gripe_unary_op (octave_value::unary_op_as_string (op),
2264 v.class_name ()); 2264 v.class_name ());
2265 } 2265 }
2266 else 2266 else
2267 { 2267 {
2268 // FIXME -- we need to handle overloading operators for built-in 2268 // FIXME -- we need to handle overloading operators for built-in
2269 // classes (double, char, int8, etc.) 2269 // classes (double, char, int8, etc.)
2270 2270
2271 octave_value_typeinfo::unary_op_fcn f 2271 octave_value_typeinfo::unary_op_fcn f
2272 = octave_value_typeinfo::lookup_unary_op (op, t); 2272 = octave_value_typeinfo::lookup_unary_op (op, t);
2273 2273
2274 if (f) 2274 if (f)
2275 { 2275 {
2276 try 2276 try
2277 { 2277 {
2278 retval = f (*v.rep); 2278 retval = f (*v.rep);
2279 } 2279 }
2280 catch (octave_execution_exception) 2280 catch (octave_execution_exception)
2281 { 2281 {
2282 gripe_library_execution_error (); 2282 gripe_library_execution_error ();
2283 } 2283 }
2284 } 2284 }
2285 else 2285 else
2286 { 2286 {
2287 octave_value tv; 2287 octave_value tv;
2288 octave_base_value::type_conv_fcn cf 2288 octave_base_value::type_conv_fcn cf
2289 = v.numeric_conversion_function (); 2289 = v.numeric_conversion_function ();
2290 2290
2291 if (cf) 2291 if (cf)
2292 { 2292 {
2293 octave_base_value *tmp = cf (*v.rep); 2293 octave_base_value *tmp = cf (*v.rep);
2294 2294
2295 if (tmp) 2295 if (tmp)
2296 { 2296 {
2297 tv = octave_value (tmp); 2297 tv = octave_value (tmp);
2298 retval = do_unary_op (op, tv); 2298 retval = do_unary_op (op, tv);
2299 } 2299 }
2300 else 2300 else
2301 gripe_unary_op_conv (octave_value::unary_op_as_string (op)); 2301 gripe_unary_op_conv (octave_value::unary_op_as_string (op));
2302 } 2302 }
2303 else 2303 else
2304 gripe_unary_op (octave_value::unary_op_as_string (op), 2304 gripe_unary_op (octave_value::unary_op_as_string (op),
2305 v.type_name ()); 2305 v.type_name ());
2306 } 2306 }
2307 } 2307 }
2308 2308
2309 return retval; 2309 return retval;
2310 } 2310 }
2311 2311
2312 static void 2312 static void
2313 gripe_unary_op_conversion_failed (const std::string& op, 2313 gripe_unary_op_conversion_failed (const std::string& op,
2314 const std::string& tn) 2314 const std::string& tn)
2315 { 2315 {
2316 error ("operator %s: type conversion for `%s' failed", 2316 error ("operator %s: type conversion for `%s' failed",
2317 op.c_str (), tn.c_str ()); 2317 op.c_str (), tn.c_str ());
2318 } 2318 }
2319 2319
2320 const octave_value& 2320 const octave_value&
2321 octave_value::do_non_const_unary_op (unary_op op) 2321 octave_value::do_non_const_unary_op (unary_op op)
2322 { 2322 {
2424 } 2424 }
2425 2425
2426 #if 0 2426 #if 0
2427 static void 2427 static void
2428 gripe_unary_op_failed_or_no_method (const std::string& on, 2428 gripe_unary_op_failed_or_no_method (const std::string& on,
2429 const std::string& tn) 2429 const std::string& tn)
2430 { 2430 {
2431 error ("operator %s: no method, or unable to evaluate for %s operand", 2431 error ("operator %s: no method, or unable to evaluate for %s operand",
2432 on.c_str (), tn.c_str ()); 2432 on.c_str (), tn.c_str ());
2433 } 2433 }
2434 #endif 2434 #endif
2435 2435
2436 void 2436 void
2437 octave_value::do_non_const_unary_op (unary_op, const octave_value_list&) 2437 octave_value::do_non_const_unary_op (unary_op, const octave_value_list&)
2439 abort (); 2439 abort ();
2440 } 2440 }
2441 2441
2442 octave_value 2442 octave_value
2443 octave_value::do_non_const_unary_op (unary_op op, const std::string& type, 2443 octave_value::do_non_const_unary_op (unary_op op, const std::string& type,
2444 const std::list<octave_value_list>& idx) 2444 const std::list<octave_value_list>& idx)
2445 { 2445 {
2446 octave_value retval; 2446 octave_value retval;
2447 2447
2448 if (idx.empty ()) 2448 if (idx.empty ())
2449 { 2449 {
2480 binop = op_sub_eq; 2480 binop = op_sub_eq;
2481 break; 2481 break;
2482 2482
2483 default: 2483 default:
2484 { 2484 {
2485 std::string on = unary_op_as_string (op); 2485 std::string on = unary_op_as_string (op);
2486 error ("operator %s: no assign operator found", on.c_str ()); 2486 error ("operator %s: no assign operator found", on.c_str ());
2487 } 2487 }
2488 } 2488 }
2489 2489
2490 return binop; 2490 return binop;
2491 } 2491 }
2553 binop = op_el_or; 2553 binop = op_el_or;
2554 break; 2554 break;
2555 2555
2556 default: 2556 default:
2557 { 2557 {
2558 std::string on = assign_op_as_string (op); 2558 std::string on = assign_op_as_string (op);
2559 error ("operator %s: no binary operator found", on.c_str ()); 2559 error ("operator %s: no binary operator found", on.c_str ());
2560 } 2560 }
2561 } 2561 }
2562 2562
2563 return binop; 2563 return binop;
2564 } 2564 }
2569 octave_value retval; 2569 octave_value retval;
2570 2570
2571 if (type.length () > 0) 2571 if (type.length () > 0)
2572 { 2572 {
2573 switch (type[0]) 2573 switch (type[0])
2574 { 2574 {
2575 case '(': 2575 case '(':
2576 { 2576 {
2577 if (type.length () > 1 && type[1] == '.') 2577 if (type.length () > 1 && type[1] == '.')
2578 retval = Octave_map (); 2578 retval = Octave_map ();
2579 else 2579 else
2580 retval = octave_value (rhs.empty_clone ()); 2580 retval = octave_value (rhs.empty_clone ());
2581 } 2581 }
2582 break; 2582 break;
2583 2583
2584 case '{': 2584 case '{':
2585 retval = Cell (); 2585 retval = Cell ();
2586 break; 2586 break;
2587 2587
2588 case '.': 2588 case '.':
2589 retval = Octave_map (); 2589 retval = Octave_map ();
2590 break; 2590 break;
2591 2591
2592 default: 2592 default:
2593 panic_impossible (); 2593 panic_impossible ();
2594 } 2594 }
2595 } 2595 }
2596 else 2596 else
2597 retval = octave_value (rhs.empty_clone ()); 2597 retval = octave_value (rhs.empty_clone ());
2598 2598
2599 return retval; 2599 return retval;
2789 octave_value arg0 = args(0); 2789 octave_value arg0 = args(0);
2790 2790
2791 arg0.make_unique (); 2791 arg0.make_unique ();
2792 2792
2793 if (! error_state) 2793 if (! error_state)
2794 retval = arg0.subsasgn (type, idx, args(2)); 2794 retval = arg0.subsasgn (type, idx, args(2));
2795 } 2795 }
2796 else 2796 else
2797 print_usage (); 2797 print_usage ();
2798 2798
2799 return retval; 2799 return retval;