Mercurial > hg > octave-lyh
changeset 8346:8302788f09db
fix empty matrix handling in switch statement
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 25 Nov 2008 14:04:55 +0100 |
parents | c777f3ce02d8 |
children | fa78cb8d8a5c |
files | src/ChangeLog src/ov.cc src/ov.h src/pt-select.cc |
diffstat | 4 files changed, 32 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2008-11-25 Jaroslav Hajek <highegg@gmail.com> + + * ov.cc (octave_value::is_equal): New member function. + * ov.h: Declare it. + * pt-select.cc (tree_switch_case::label_matches): Call + octave_value::is_equal. + 2008-11-25 Jaroslav Hajek <highegg@gmail.com> * ov-base.h (octave_base_value::type_conv_info): New class.
--- a/src/ov.cc +++ b/src/ov.cc @@ -1223,6 +1223,25 @@ return retval; } +bool +octave_value::is_equal (const octave_value& test) const +{ + bool retval = false; + + // If there is no op_eq for these types, we can't compare values. + + if (rows () == test.rows () && columns () == test.columns ()) + { + octave_value tmp = do_binary_op (octave_value::op_eq, *this, test); + + // Empty array also means a match. + if (! error_state && tmp.is_defined ()) + retval = tmp.is_true () || tmp.is_empty (); + } + + return retval; +} + Cell octave_value::cell_value (void) const {
--- a/src/ov.h +++ b/src/ov.h @@ -574,6 +574,10 @@ bool is_true (void) const { return rep->is_true (); } + // Do two constants match (in a switch statement)? + + bool is_equal (const octave_value&) const; + // Are the dimensions of this constant zero by zero? bool is_zero_by_zero (void) const
--- a/src/pt-select.cc +++ b/src/pt-select.cc @@ -152,27 +152,6 @@ } -// Compare two octave values, returning true if equal, false if not -// FIXME --- should be member or friend of octave_value class. - -static bool -equal (const octave_value& val, const octave_value& test) -{ - bool retval = false; - - // If there is no op_eq for these types, we can't compare values. - - if (val.rows () == test.rows () && val.columns () == test.columns ()) - { - octave_value tmp = do_binary_op (octave_value::op_eq, val, test); - - if (! error_state && tmp.is_defined ()) - retval = tmp.is_true (); - } - - return retval; -} - bool tree_switch_case::label_matches (const octave_value& val) { @@ -188,7 +167,7 @@ { for (octave_idx_type j = 0; j < cell.columns (); j++) { - bool match = equal (val, cell(i,j)); + bool match = val.is_equal (cell(i,j)); if (error_state) return false; @@ -199,7 +178,7 @@ } else { - bool match = equal (val, label_value); + bool match = val.is_equal (label_value); if (error_state) return false;