Mercurial > octave-nkf
diff libinterp/octave-value/ov-class.cc @ 19137:56bc1464ec59
Implement "isa" for classdef objects.
* ov.h (octave_value::is_instance_of): New method.
* ov-base.h (octave_base_value::is_instance_of): Likewise.
* ov-class.h (octave_class::is_instance_of): New method declaration.
* ov-class.cc (octave_class::is_instance_of): Implement it with
find_parent_class.
* ov-classdef.h (octave_classdef::is_instance_of): New method
declaration.
* ov-classdef.cc (octave_classdef::is_instance_of): Implement it
with lookup_class and is_superclass.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Sat, 20 Sep 2014 12:43:25 -0400 |
parents | 4cdab2973171 |
children | 03067dab10ca |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-class.cc Sat Sep 20 06:31:27 2014 -0700 +++ b/libinterp/octave-value/ov-class.cc Sat Sep 20 12:43:25 2014 -0400 @@ -1015,6 +1015,35 @@ return retval; } +bool +octave_class::is_instance_of (const std::string& cls_name) const +{ + bool retval = false; + + if (cls_name == class_name ()) + retval = true; + else + { + for (std::list<std::string>::const_iterator pit = parent_list.begin (); + pit != parent_list.end (); + pit++) + { + octave_map::const_iterator smap = map.seek (*pit); + + const Cell& tmp = map.contents (smap); + + const octave_value& vtmp = tmp(0); + + retval = vtmp.is_instance_of (cls_name); + + if (retval) + break; + } + } + + return retval; +} + string_vector octave_class::all_strings (bool pad) const { @@ -1962,7 +1991,7 @@ if ((cl == "float" && obj.is_float_type ()) || (cl == "integer" && obj.is_integer_type ()) || (cl == "numeric" && obj.is_numeric_type ()) || - obj.class_name () == cl || obj.find_parent_class (cl)) + obj.class_name () == cl || obj.is_instance_of (cl)) matches(idx) = true; } return octave_value (matches);