diff src/ov-fcn-handle.cc @ 4654:a9b22513b7a6

[project @ 2003-11-24 18:56:35 by jwe]
author jwe
date Mon, 24 Nov 2003 18:56:35 +0000
parents f7ce581b27fb
children c8829691db47
line wrap: on
line diff
--- a/src/ov-fcn-handle.cc	Mon Nov 24 05:02:46 2003 +0000
+++ b/src/ov-fcn-handle.cc	Mon Nov 24 18:56:35 2003 +0000
@@ -31,18 +31,117 @@
 #include <iostream>
 
 #include "defun.h"
+#include "error.h"
+#include "gripes.h"
 #include "oct-map.h"
 #include "ov-base.h"
+#include "ov-base-mat.h"
+#include "ov-base-mat.cc"
 #include "ov-fcn-handle.h"
 #include "pr-output.h"
 #include "variables.h"
 
+// Instantiate Arrays of fcn_handle_elt values.
+
+#include "Array.h"
+#include "Array.cc"
+
+INSTANTIATE_ARRAY_AND_ASSIGN (fcn_handle_elt);
+
+#include "Array2.h"
+
+template class Array2<fcn_handle_elt>;
+
+#include "ArrayN.h"
+#include "ArrayN.cc"
+
+template class ArrayN<fcn_handle_elt>;
+
+template class octave_base_matrix<fcn_handle_array>;
+
+boolNDArray
+fcn_handle_array::all (int) const
+{
+  error ("all: invalid call for function handle object");
+  return boolNDArray ();
+}
+
+boolNDArray
+fcn_handle_array::any (int) const
+{
+  error ("any: invalid call for function handle object");
+  return boolNDArray ();
+}
+
 DEFINE_OCTAVE_ALLOCATOR (octave_fcn_handle);
 
 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fcn_handle,
 				     "function handle",
 				     "function handle");
 
+octave_function *
+octave_fcn_handle::function_value (bool)
+{
+  octave_function *retval = 0;
+
+  if (numel () > 0)
+    {
+      // XXX FIXME XXX -- is warn_fortran_indexing the right variable here?
+      if (Vwarn_fortran_indexing)
+	gripe_implicit_conversion ("function handle array",
+				   "scalar function handle");
+
+      fcn_handle_elt elt = matrix(0);
+
+      retval = elt.function_value ();
+    }
+  else
+    gripe_invalid_conversion ("function handle array",
+			      "scalar function handle");
+
+  return retval;
+}
+
+std::string
+octave_fcn_handle::name (void) const
+{
+  std::string retval;
+
+  if (numel () > 0)
+    {
+      // XXX FIXME XXX -- is warn_fortran_indexing the right variable here?
+      if (Vwarn_fortran_indexing)
+	gripe_implicit_conversion ("function handle array",
+				   "scalar function handle");
+
+      fcn_handle_elt elt = matrix(0);
+
+      retval = elt.name ();
+    }
+  else
+    gripe_invalid_conversion ("function handle array",
+			      "scalar function handle");
+
+  return retval;
+}
+
+ArrayN<std::string>
+fcn_handle_array::names (void) const
+{
+  ArrayN<std::string> retval (dims ());
+
+  int nel = length ();
+
+  for (int i = 0; i < nel; i++)
+    {
+      fcn_handle_elt elt = elem (i);
+
+      retval(i) = elt.name ();
+    }
+
+  return retval;
+}
+
 void
 octave_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax) const
 {
@@ -53,8 +152,14 @@
 void
 octave_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax) const
 {
+  dim_vector dv = matrix.dims ();
+  os << "<" << dv.str () << " function handle object>";
+
+#if 0
   indent (os);
-  os << name ();
+  octave_print_internal (os, name_array (), pr_as_read_syntax,
+			 current_print_indent_level (), true);
+#endif
 }
 
 octave_value
@@ -65,11 +170,7 @@
   octave_function *f = lookup_function (nm);
 
   if (f)
-    {
-      octave_fcn_handle fh (f, nm);
-
-      retval = octave_value (fh);
-    }
+    return fcn_handle_array (f, nm);
   else
     error ("error creating function handle \"@%s\"", nm.c_str ());