changeset 4925:90f51232d751

[project @ 2004-08-02 22:09:47 by jwe]
author jwe
date Mon, 02 Aug 2004 22:09:47 +0000
parents 9a3a32f5a27d
children e80587ad9503
files src/ChangeLog src/Makefile.in src/OPERATORS/op-fcn-handle.cc src/ov-fcn-handle.cc src/ov-fcn-handle.h src/ov.cc src/ov.h src/pr-output.cc src/pr-output.h
diffstat 9 files changed, 44 insertions(+), 284 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon Aug 02 19:04:20 2004 +0000
+++ b/src/ChangeLog	Mon Aug 02 22:09:47 2004 +0000
@@ -1,6 +1,14 @@
 2004-08-02  John W. Eaton  <jwe@octave.org>
 
+	* OPERATORS/op-fcn-handle.cc: Delete.
+	* Makefile.in (OP_XSRC): Delete it from the list.
+	* pr-output.cc (octave_print_internal (std::ostream&, const
+	std::string&, bool, int): New function.
 	* ov-fcn-handle.cc (octave_value::subsref): New function.
+	* ov-fcn-handle.h (class fcn_handle_elt, class fcn_handle_array):
+	Delete.
+	(class octave_fcn_handle): Derive from octave_base_value, not
+	octave_base_matrix<fcn_handle_array>.
 
 	* ov-cx-mat.cc (try_narrowing_conversion): Also allow complex to
 	real conversion for N-d arrays.
--- a/src/Makefile.in	Mon Aug 02 19:04:20 2004 +0000
+++ b/src/Makefile.in	Mon Aug 02 22:09:47 2004 +0000
@@ -112,7 +112,7 @@
 	op-fil-rec.cc op-fil-str.cc op-list.cc op-m-cm.cc \
 	op-m-cs.cc op-m-m.cc op-m-s.cc op-range.cc op-s-cm.cc \
 	op-s-cs.cc op-s-m.cc op-s-s.cc op-str-m.cc \
-	op-str-s.cc op-str-str.cc op-streamoff.cc op-fcn-handle.cc \
+	op-str-s.cc op-str-str.cc op-streamoff.cc \
 	$(INTTYPE_OP_XSRC)
 
 OP_SRC := $(addprefix OPERATORS/, $(OP_XSRC))
--- a/src/OPERATORS/op-fcn-handle.cc	Mon Aug 02 19:04:20 2004 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/*
-
-Copyright (C) 2003 John W. Eaton
-
-This file is part of Octave.
-
-Octave is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
-later version.
-
-Octave is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "gripes.h"
-#include "ov.h"
-#include "ov-fcn-handle.h"
-#include "ov-typeinfo.h"
-#include "ops.h"
-
-// fcn_handle unary ops.
-
-DEFUNOP (transpose, fcn_handle)
-{
-  CAST_UNOP_ARG (const octave_fcn_handle&);
-
-  return octave_value (fcn_handle_array (v.fcn_handle_array_value().transpose ()));
-}
-
-DEFASSIGNOP (assign, fcn_handle, fcn_handle)
-{
-  CAST_BINOP_ARGS (octave_fcn_handle&, const octave_fcn_handle&);
-
-  v1.assign (idx, v2.fcn_handle_array_value ());
-  return octave_value ();
-}
-
-void
-install_fcn_handle_ops (void)
-{
-  INSTALL_UNOP (op_transpose, octave_fcn_handle, transpose);
-  INSTALL_UNOP (op_hermitian, octave_fcn_handle, transpose);
-
-  INSTALL_ASSIGNOP (op_asn_eq, octave_fcn_handle, octave_fcn_handle, assign);
-}
-
-/*
-;;; Local Variables: ***
-;;; mode: C++ ***
-;;; End: ***
-*/
--- a/src/ov-fcn-handle.cc	Mon Aug 02 19:04:20 2004 +0000
+++ b/src/ov-fcn-handle.cc	Mon Aug 02 22:09:47 2004 +0000
@@ -35,44 +35,10 @@
 #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,
@@ -118,69 +84,6 @@
   return retval;
 }
 
-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
 {
@@ -191,7 +94,7 @@
 void
 octave_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax) const
 {
-  octave_print_internal (os, name_array (), pr_as_read_syntax,
+  octave_print_internal (os, nm, pr_as_read_syntax,
 			 current_print_indent_level ());
 }
 
@@ -203,7 +106,7 @@
   octave_function *f = lookup_function (nm);
 
   if (f)
-    return fcn_handle_array (f, nm);
+    retval = octave_value (f, nm);
   else
     error ("error creating function handle \"@%s\"", nm.c_str ());
 
--- a/src/ov-fcn-handle.h	Mon Aug 02 19:04:20 2004 +0000
+++ b/src/ov-fcn-handle.h	Mon Aug 02 22:09:47 2004 +0000
@@ -40,114 +40,18 @@
 
 // Function handles.
 
-class fcn_handle_elt
-{
-public:
-
-  fcn_handle_elt (void) : fcn (0), nm ("@[]") { }
-
-  fcn_handle_elt (octave_function *f, const std::string& n)
-    : fcn (f), nm (std::string ("@") + n) { }
-
-  fcn_handle_elt (const fcn_handle_elt& fhe)
-    : fcn (fhe.fcn), nm (fhe.nm) { }
-
-  fcn_handle_elt& operator = (const fcn_handle_elt& fhe)
-    {
-      if (this != &fhe)
-	{
-	  fcn = fhe.fcn;
-	  nm  = fhe.nm;
-	}
-
-      return *this;
-    }
-
-  ~fcn_handle_elt (void) { }
-
-  octave_function *function_value (void) { return fcn; }
-
-  std::string name (void) const { return nm; }
-
-private:
-
-  // The function we are handling.
-  octave_function *fcn;
-
-  // The name of the handle, including the "@".
-  std::string nm;
-};
-
-class fcn_handle_array : public ArrayN<fcn_handle_elt>
+class
+octave_fcn_handle : public octave_base_value
 {
 public:
 
-  fcn_handle_array (void) : ArrayN<fcn_handle_elt> () { }
-
-  fcn_handle_array (const dim_vector& dv,
-		    const fcn_handle_elt& val = resize_fill_value ())
-    : ArrayN<fcn_handle_elt> (dv, val) { }
-
-  fcn_handle_array (octave_function *f, const std::string& nm)
-    : ArrayN<fcn_handle_elt> (dim_vector (1, 1), fcn_handle_elt (f, nm)) { }
-
-  fcn_handle_array (const ArrayN<fcn_handle_elt>& fa)
-    : ArrayN<fcn_handle_elt> (fa) { }
-
-  fcn_handle_array (const fcn_handle_array& fa)
-    : ArrayN<fcn_handle_elt> (fa) { }
-
-  ~fcn_handle_array (void) { }
-
-  fcn_handle_array& operator = (const fcn_handle_array& fa)
-    {
-      if (this != &fa)
-	ArrayN<fcn_handle_elt>::operator = (fa);
-
-      return *this;
-    }
-
-  fcn_handle_array squeeze (void) const
-    { return ArrayN<fcn_handle_elt>::squeeze (); }
-
-  boolNDArray all (int dim = -1) const;
-  boolNDArray any (int dim = -1) const;
-
-  ArrayN<std::string> names (void) const;
-
-  static int compute_index (Array<int>& ra_idx,
-			    const dim_vector& dimensions);
-
-  static fcn_handle_elt resize_fill_value (void)
-    {
-      static fcn_handle_elt nil_handle = fcn_handle_elt ();
-      return nil_handle;
-    }
-};
-
-class
-octave_fcn_handle : public octave_base_matrix<fcn_handle_array>
-{
-public:
-
-  octave_fcn_handle (void)
-    : octave_base_matrix<fcn_handle_array> () { }
+  octave_fcn_handle (void) : fcn (0), nm () { }
 
   octave_fcn_handle (octave_function *f, const std::string& n)
-    : octave_base_matrix<fcn_handle_array>
-        (fcn_handle_array (dim_vector (1, 1), fcn_handle_elt (f, n))) { }
-
-  octave_fcn_handle (const fcn_handle_array& fha)
-    : octave_base_matrix<fcn_handle_array> (fha) { }
-
-  octave_fcn_handle (const octave_fcn_handle& fh)
-    : octave_base_matrix<fcn_handle_array> (fh) { }
+    : fcn (f), nm (n) { }
 
   ~octave_fcn_handle (void) { }
 
-  octave_value *clone (void) const { return new octave_fcn_handle (*this); }
-  octave_value *empty_clone (void) const { return new octave_fcn_handle (); }
-
   octave_value subsref (const std::string&,
 			const std::list<octave_value_list>&)
     {
@@ -159,35 +63,37 @@
 			     const std::list<octave_value_list>& idx,
 			     int nargout);
 
-  bool is_matrix_type (void) const { return false; }
-
-  bool is_numeric_type (void) const { return false; }
-
-  bool is_constant (void) const { return false; }
-
-  bool is_true (void) { return false; }
+  bool is_defined (void) const { return true; }
 
   bool is_function_handle (void) const { return true; }
 
-  octave_function *function_value (bool = false);
+  octave_function *function_value (bool = false) { return fcn; }
 
-  std::string name (void) const;
+  std::string name (void) const { return nm; }
 
   octave_fcn_handle *fcn_handle_value (bool = false) { return this; }
 
-  fcn_handle_array fcn_handle_array_value (void) const { return matrix; }
-
-  ArrayN<std::string> name_array (void) const { return matrix.names (); }
-
   void print (std::ostream& os, bool pr_as_read_syntax = false) const;
 
   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
 
 private:
 
+  // No copying!
+
+  octave_fcn_handle (const octave_fcn_handle& fh);
+
+  octave_fcn_handle& operator = (const octave_fcn_handle& fh);
+
   DECLARE_OCTAVE_ALLOCATOR
 
   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
+
+  // The function we are handling.
+  octave_function *fcn;
+
+  // The name of the handle, including the "@".
+  std::string nm;
 };
 
 extern octave_value make_fcn_handle (const std::string& nm);
--- a/src/ov.cc	Mon Aug 02 19:04:20 2004 +0000
+++ b/src/ov.cc	Mon Aug 02 22:09:47 2004 +0000
@@ -740,12 +740,6 @@
   rep->count = 1;
 }
 
-octave_value::octave_value (const fcn_handle_array& fha)
-  : rep (new octave_fcn_handle (fha))
-{
-  rep->count = 1;
-}
-
 octave_value::octave_value (octave_function *f, const std::string& nm)
   : rep (new octave_fcn_handle (f, nm))
 {
--- a/src/ov.h	Mon Aug 02 19:04:20 2004 +0000
+++ b/src/ov.h	Mon Aug 02 22:09:47 2004 +0000
@@ -45,7 +45,6 @@
 #include "str-vec.h"
 
 class Cell;
-class fcn_handle_array;
 class streamoff_array;
 class Octave_map;
 class octave_stream;
@@ -238,7 +237,6 @@
   octave_value (const octave_stream& s, int n);
   octave_value (const streamoff_array& off);
   octave_value (octave_function *f);
-  octave_value (const fcn_handle_array& fha);
   octave_value (octave_function *f, const std::string &nm); // function handle
   octave_value (const octave_value_list& m, bool is_cs_list = false);
   octave_value (octave_value::magic_colon);
--- a/src/pr-output.cc	Mon Aug 02 19:04:20 2004 +0000
+++ b/src/pr-output.cc	Mon Aug 02 22:09:47 2004 +0000
@@ -1997,6 +1997,15 @@
 }
 
 void
+octave_print_internal (std::ostream& os, const std::string& s,
+		       bool pr_as_read_syntax, int extra_indent)
+{
+  ArrayN<std::string> nda (dim_vector (1, 1), s);
+
+  octave_print_internal (os, nda, pr_as_read_syntax, extra_indent);
+}
+
+void
 octave_print_internal (std::ostream& os, const ArrayN<std::string>& nda,
 		       bool pr_as_read_syntax, int /* extra_indent */)
 {
--- a/src/pr-output.h	Mon Aug 02 19:04:20 2004 +0000
+++ b/src/pr-output.h	Mon Aug 02 22:09:47 2004 +0000
@@ -98,6 +98,11 @@
 		       bool pr_as_string = false);
 
 extern void
+octave_print_internal (std::ostream& os, const std::string& s,
+		       bool pr_as_read_syntax = false,
+		       int extra_indent = 0);
+
+extern void
 octave_print_internal (std::ostream& os, const ArrayN<std::string>& sa,
 		       bool pr_as_read_syntax = false,
 		       int extra_indent = 0);