Mercurial > hg > octave-lyh
diff 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 |
line wrap: on
line diff
--- a/src/ov.cc +++ b/src/ov.cc @@ -69,6 +69,7 @@ #include "ov-fcn-handle.h" #include "ov-fcn-inline.h" #include "ov-typeinfo.h" +#include "ov-null-mat.h" #include "defun.h" #include "error.h" @@ -1153,7 +1154,8 @@ octave_value::assign (assign_op op, const octave_value& rhs) { if (op == op_asn_eq) - operator = (rhs); + // Regularize a null matrix if stored into a variable. + operator = (rhs.non_null_value ()); else { // FIXME -- only do the following stuff if we can't find @@ -1516,6 +1518,28 @@ type_name (), "complex vector")); } + +octave_value +octave_value::non_null_value (void) const +{ + if (is_null_value ()) + return octave_value (rep->empty_clone ()); + else + return *this; +} + +void +octave_value::make_non_null_value (void) +{ + if (is_null_value ()) + { + octave_base_value *rc = rep->empty_clone (); + if (--rep->count == 0) + delete rep; + rep = rc; + } +} + int octave_value::write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip, @@ -2397,6 +2421,9 @@ octave_float_complex::register_type (); octave_float_matrix::register_type (); octave_float_complex_matrix::register_type (); + octave_null_matrix::register_type (); + octave_null_str::register_type (); + octave_null_sq_str::register_type (); } #if 0