comparison src/ov.cc @ 8150:283989f2da9b

make null assignment matlab compatible
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 26 Sep 2008 11:52:01 -0400
parents cd90e2842080
children c777f3ce02d8
comparison
equal deleted inserted replaced
8149:a8fb37ae61b8 8150:283989f2da9b
67 #include "ov-dld-fcn.h" 67 #include "ov-dld-fcn.h"
68 #include "ov-usr-fcn.h" 68 #include "ov-usr-fcn.h"
69 #include "ov-fcn-handle.h" 69 #include "ov-fcn-handle.h"
70 #include "ov-fcn-inline.h" 70 #include "ov-fcn-inline.h"
71 #include "ov-typeinfo.h" 71 #include "ov-typeinfo.h"
72 #include "ov-null-mat.h"
72 73
73 #include "defun.h" 74 #include "defun.h"
74 #include "error.h" 75 #include "error.h"
75 #include "gripes.h" 76 #include "gripes.h"
76 #include "pager.h" 77 #include "pager.h"
1151 1152
1152 const octave_value& 1153 const octave_value&
1153 octave_value::assign (assign_op op, const octave_value& rhs) 1154 octave_value::assign (assign_op op, const octave_value& rhs)
1154 { 1155 {
1155 if (op == op_asn_eq) 1156 if (op == op_asn_eq)
1156 operator = (rhs); 1157 // Regularize a null matrix if stored into a variable.
1158 operator = (rhs.non_null_value ());
1157 else 1159 else
1158 { 1160 {
1159 // FIXME -- only do the following stuff if we can't find 1161 // FIXME -- only do the following stuff if we can't find
1160 // a specific function to call to handle the op= operation for 1162 // a specific function to call to handle the op= operation for
1161 // the types we have. 1163 // the types we have.
1512 return retval; 1514 return retval;
1513 else 1515 else
1514 return retval.reshape (make_vector_dims (retval.dims (), 1516 return retval.reshape (make_vector_dims (retval.dims (),
1515 force_vector_conversion, 1517 force_vector_conversion,
1516 type_name (), "complex vector")); 1518 type_name (), "complex vector"));
1519 }
1520
1521
1522 octave_value
1523 octave_value::non_null_value (void) const
1524 {
1525 if (is_null_value ())
1526 return octave_value (rep->empty_clone ());
1527 else
1528 return *this;
1529 }
1530
1531 void
1532 octave_value::make_non_null_value (void)
1533 {
1534 if (is_null_value ())
1535 {
1536 octave_base_value *rc = rep->empty_clone ();
1537 if (--rep->count == 0)
1538 delete rep;
1539 rep = rc;
1540 }
1517 } 1541 }
1518 1542
1519 int 1543 int
1520 octave_value::write (octave_stream& os, int block_size, 1544 octave_value::write (octave_stream& os, int block_size,
1521 oct_data_conv::data_type output_type, int skip, 1545 oct_data_conv::data_type output_type, int skip,
2395 octave_fcn_inline::register_type (); 2419 octave_fcn_inline::register_type ();
2396 octave_float_scalar::register_type (); 2420 octave_float_scalar::register_type ();
2397 octave_float_complex::register_type (); 2421 octave_float_complex::register_type ();
2398 octave_float_matrix::register_type (); 2422 octave_float_matrix::register_type ();
2399 octave_float_complex_matrix::register_type (); 2423 octave_float_complex_matrix::register_type ();
2424 octave_null_matrix::register_type ();
2425 octave_null_str::register_type ();
2426 octave_null_sq_str::register_type ();
2400 } 2427 }
2401 2428
2402 #if 0 2429 #if 0
2403 DEFUN (cast, args, , 2430 DEFUN (cast, args, ,
2404 "-*- texinfo -*-\n\ 2431 "-*- texinfo -*-\n\