changeset 9458:0c7d84a65386

allow taking handles of methods with no base overload
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 24 Jul 2009 08:13:20 +0200
parents f9fb8c1a8e45
children cb0b21f34abc
files src/ChangeLog src/load-path.cc src/load-path.h src/ov-fcn-handle.cc
diffstat 4 files changed, 69 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Jul 23 18:04:49 2009 -0400
+++ b/src/ChangeLog	Fri Jul 24 08:13:20 2009 +0200
@@ -1,3 +1,13 @@
+2009-07-24  Jaroslav Hajek  <highegg@gmail.com>
+
+	* load-path.cc (load_path::do_any_class_method): New method.
+	* load-path.h (load_path::do_any_class_method): New method decl.
+	(load_path::any_class_method): New method.
+	* ov-fcn-handle.cc (octave_fcn_handle::do_multi_index_op): Support
+	calls without non-overloaded base function.
+	(make_fcn_handle): Support creation without non-overloaded base
+	function.
+
 2009-07-23  Shai Ayal  <shaiay@users.sourceforge.net>
 
 	* DLD-FUNCTIONS/fltk_backend.cc (plot_window::pixel2axes_or_ca):
--- a/src/load-path.cc	Thu Jul 23 18:04:49 2009 -0400
+++ b/src/load-path.cc	Fri Jul 24 08:13:20 2009 +0200
@@ -1091,6 +1091,28 @@
   return retval;
 }
 
+bool
+load_path::do_any_class_method (const std::string& meth) const
+{
+  bool retval = false;
+
+  //  update ();
+
+  for (const_method_map_iterator q = method_map.begin ();
+       q != method_map.end (); q++)
+    {
+      const fcn_map_type& m = q->second;
+
+      if (m.find (meth) != m.end ())
+        {
+          retval = true;
+          break;
+        }
+    }
+
+  return retval;
+}
+
 std::string
 load_path::do_find_file (const std::string& file) const
 {
--- a/src/load-path.h	Thu Jul 23 18:04:49 2009 -0400
+++ b/src/load-path.h	Fri Jul 24 08:13:20 2009 +0200
@@ -108,6 +108,12 @@
       ? instance->do_methods (class_name) : std::list<std::string> ();
   }
 
+  static bool any_class_method (const std::string& meth)
+  {
+    return instance_ok ()
+      ? instance->do_any_class_method (meth) : false;
+  }
+
   static std::string find_fcn (const std::string& fcn, std::string& dir_name)
   {
     return instance_ok ()
@@ -479,6 +485,8 @@
 
   std::list<std::string> do_methods (const std::string& class_name) const;
 
+  bool do_any_class_method (const std::string& meth) const;
+
   std::string do_find_file (const std::string& file) const;
 
   std::string do_find_dir (const std::string& dir) const;
--- a/src/ov-fcn-handle.cc	Thu Jul 23 18:04:49 2009 -0400
+++ b/src/ov-fcn-handle.cc	Fri Jul 24 08:13:20 2009 +0200
@@ -122,7 +122,8 @@
 {
   octave_value_list retval;
 
-  out_of_date_check (fcn);
+  if (fcn.is_defined ())
+    out_of_date_check (fcn);
 
   if (disp.get () && ! args.empty ())
     {
@@ -155,6 +156,13 @@
 
       if (ovfcn.is_defined ())
         retval = ovfcn.do_multi_index_op (nargout, args);
+      else if (fcn.is_undefined ())
+        {
+          if (ddt.empty ())
+            ddt = args(0).class_name ();
+
+          error ("no %s method to handle class %s", nm.c_str (), ddt.c_str ());
+        }
       else
         error ("invalid function handle");
     }
@@ -1429,15 +1437,32 @@
 	}
     }
 
+  bool handle_ok = false;
   octave_value f = symbol_table::find_function (tnm);
+
+  if (f.is_undefined ())
+    {
+      if (load_path::any_class_method (tnm))
+        handle_ok = true;
+      else
+        {
+          load_path::update ();
+          if (load_path::any_class_method (tnm))
+            handle_ok = true;
+        }
+    }
+  else
+    handle_ok = true;
+
   octave_function *fptr = f.is_defined () ? f.function_value () : 0;
 
-  if (fptr)
+
+  if (handle_ok)
     {
       // If it's a subfunction, private function, or class constructor,
       // we want no dispatch.
-      if (fptr->is_nested_function () || fptr->is_private_function ()
-          || fptr->is_class_constructor ())
+      if (fptr && (fptr->is_nested_function () || fptr->is_private_function ()
+          || fptr->is_class_constructor ()))
         retval = octave_value (new octave_fcn_handle (f, tnm));
       else
         {