changeset 10322:21551cc88061

improve function handles comparison
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 15 Feb 2010 07:13:12 +0100
parents 97b4bd6f0925
children ee93dbfba45b
files src/ChangeLog src/OPERATORS/op-fcn.cc src/ov-fcn-handle.cc src/ov-fcn-handle.h
diffstat 4 files changed, 35 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sat Feb 13 08:17:21 2010 +0100
+++ b/src/ChangeLog	Mon Feb 15 07:13:12 2010 +0100
@@ -1,3 +1,9 @@
+2010-02-15  Jaroslav Hajek  <highegg@gmail.com>
+
+	* ov-fcn-handle.cc (octave_fcn_handle::is_equal_to): New method.
+	* ov-fcn-handle.h: Declare it.
+	* OPERATORS/op-fcn.cc (eq, ne): Call it here. Register new handler.
+
 2010-02-13  Jaroslav Hajek  <highegg@gmail.com>
 
 	* load-path.cc (load_path::do_any_class_method): Rename to
--- a/src/OPERATORS/op-fcn.cc	Sat Feb 13 08:17:21 2010 +0100
+++ b/src/OPERATORS/op-fcn.cc	Mon Feb 15 07:13:12 2010 +0100
@@ -36,19 +36,19 @@
 {
   CAST_BINOP_ARGS (const octave_fcn_handle&, const octave_fcn_handle&);
 
-  // FIXME: this may not be entirely correct in case the handles were created
-  // in different directories. Needs checking what recent Matlab does, and also
-  // discussion whether we want to copy its behavior. Or to what extent.
-  // Meanwhile, this catches all the "normal" usages, i.e.
-  //   h == @sin
-  // should yield true only if h is a handle to the global "sin", not a local one.
+  return v1.is_equal_to (v2);
+}
 
-  return (v1.fcn_name () == v2.fcn_name () 
-          && v1.fcn_val ().is_copy_of (v2.fcn_val ()));
+DEFBINOP (ne, fcn_handle, fcn_handle)
+{
+  CAST_BINOP_ARGS (const octave_fcn_handle&, const octave_fcn_handle&);
+
+  return ! v1.is_equal_to (v2);
 }
 
 void
 install_fcn_ops (void)
 {
   INSTALL_BINOP (op_eq, octave_fcn_handle, octave_fcn_handle, eq);
+  INSTALL_BINOP (op_ne, octave_fcn_handle, octave_fcn_handle, ne);
 }
--- a/src/ov-fcn-handle.cc	Sat Feb 13 08:17:21 2010 +0100
+++ b/src/ov-fcn-handle.cc	Mon Feb 15 07:13:12 2010 +0100
@@ -171,6 +171,25 @@
   return retval;
 }
 
+bool 
+octave_fcn_handle::is_equal_to (const octave_fcn_handle& h) const
+{
+  bool retval = fcn.is_copy_of (h.fcn) && (has_overloads == h.has_overloads);
+  retval = retval && (overloads.size () == h.overloads.size ());
+
+  if (retval && has_overloads)
+    {
+      for (int i = 0; i < btyp_num_types && retval; i++)
+        retval = builtin_overloads[i].is_copy_of (h.builtin_overloads[i]);
+
+      str_ov_map::const_iterator iter = overloads.begin (), hiter = h.overloads.begin ();
+      for (; iter != overloads.end () && retval; iter++, hiter++)
+        retval = (iter->first == hiter->first) && (iter->second.is_copy_of (hiter->second));
+    }
+
+  return retval;
+}
+
 bool
 octave_fcn_handle::set_fcn (const std::string &octaveroot, 
                             const std::string& fpath)
@@ -1453,7 +1472,6 @@
         }
     }
 
-  bool handle_ok = false;
   octave_value f = symbol_table::find_function (tnm, octave_value_list (),
                                                 local_funcs);
   octave_function *fptr = f.function_value (true);
--- a/src/ov-fcn-handle.h	Sat Feb 13 08:17:21 2010 +0100
+++ b/src/ov-fcn-handle.h	Mon Feb 15 07:13:12 2010 +0100
@@ -123,6 +123,8 @@
       overloads[dispatch_type] = ov_fcn;
     }
 
+  bool is_equal_to (const octave_fcn_handle&) const;
+
   bool save_ascii (std::ostream& os);
 
   bool load_ascii (std::istream& is);