Mercurial > octave
changeset 21725:78e0b187904b
Call @class/logical method for objects in conditional expressions (bug #43097)
* ov-class.{cc,h} (octave_class::is_true): New method, dispatch call to
@class/logical if defined.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Wed, 18 May 2016 11:00:58 -0700 |
parents | aba2e6293dd8 |
children | f05a00e611ff |
files | libinterp/octave-value/ov-class.cc libinterp/octave-value/ov-class.h |
diffstat | 2 files changed, 20 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-class.cc Tue May 17 12:09:30 2016 -0400 +++ b/libinterp/octave-value/ov-class.cc Wed May 18 11:00:58 2016 -0700 @@ -836,6 +836,24 @@ return retval; } +bool +octave_class::is_true (void) const +{ + bool retval = false; + + octave_value meth = symbol_table::find_method ("logical", class_name ()); + + if (meth.is_defined ()) + { + octave_value in = new octave_class (*this); + + octave_value_list tmp = feval (meth.function_value (), in, 1); + retval = tmp(0).is_true (); + } + + return retval; +} + string_vector octave_class::map_keys (void) const {
--- a/libinterp/octave-value/ov-class.h Tue May 17 12:09:30 2016 -0400 +++ b/libinterp/octave-value/ov-class.h Wed May 18 11:00:58 2016 -0700 @@ -154,6 +154,8 @@ bool is_object (void) const { return true; } + bool is_true (void) const; + octave_map map_value (void) const { return map; } string_vector map_keys (void) const;