comparison libinterp/octave-value/ov-class.cc @ 20530:bf6c4433ed5f

Clean up isa() function. * ov-class.cc (Fisa): Remove not strictly necessary const modifiers on variables. Use more meaningful variable names. Put direct test for class name first in if tree since this is the most likely test to succeed.
author Rik <rik@octave.org>
date Tue, 22 Sep 2015 01:38:40 -0700
parents c6224b4e7774
children b70cc4bd8109
comparison
equal deleted inserted replaced
20529:fbbdd14aa7ce 20530:bf6c4433ed5f
1983 { 1983 {
1984 print_usage (); 1984 print_usage ();
1985 return retval; 1985 return retval;
1986 } 1986 }
1987 1987
1988 octave_value obj = args(0); // not const because of find_parent_class () 1988 octave_value obj = args(0); // not const because of find_parent_class ()
1989 const Array<std::string> cls = args(1).cellstr_value (); 1989 std::string obj_cls = obj.class_name ();
1990 Array<std::string> clsnames = args(1).cellstr_value ();
1990 if (error_state) 1991 if (error_state)
1991 { 1992 {
1992 error ("isa: CLASSNAME must be a string or cell array of strings"); 1993 error ("isa: CLASSNAME must be a string or cell array of strings");
1993 return retval; 1994 return retval;
1994 } 1995 }
1995 1996
1996 boolNDArray matches (cls.dims (), false); 1997 boolNDArray matches (clsnames.dims (), false);
1997 const octave_idx_type n = cls.numel (); 1998 for (octave_idx_type idx = 0; idx < clsnames.numel (); idx++)
1998 for (octave_idx_type idx = 0; idx < n; idx++) 1999 {
1999 { 2000 std::string cls = clsnames(idx);
2000 const std::string cl = cls(idx); 2001 if (obj_cls == cls
2001 if ((cl == "float" && obj.is_float_type ()) 2002 || (cls == "float" && obj.is_float_type ())
2002 || (cl == "integer" && obj.is_integer_type ()) 2003 || (cls == "integer" && obj.is_integer_type ())
2003 || (cl == "numeric" && obj.is_numeric_type ()) 2004 || (cls == "numeric" && obj.is_numeric_type ())
2004 || obj.class_name () == cl || obj.is_instance_of (cl)) 2005 || obj.is_instance_of (cls))
2005 matches(idx) = true; 2006 matches(idx) = true;
2006 } 2007 }
2007 return octave_value (matches); 2008 return octave_value (matches);
2008 } 2009 }
2009 2010