diff src/ov.cc @ 2413:44753e0cadf2

[project @ 1996-10-15 17:02:26 by jwe]
author jwe
date Tue, 15 Oct 1996 17:02:26 +0000
parents 367485171742
children de430cdd9234
line wrap: on
line diff
--- a/src/ov.cc	Tue Oct 15 16:54:58 1996 +0000
+++ b/src/ov.cc	Tue Oct 15 17:02:26 1996 +0000
@@ -316,147 +316,12 @@
 }
 
 static void
-gripe_indexed_assignment (const string& tn1, const string& tn2)
-{
-  error ("assignment of %s to indexed %s not implemented",
-	 tn2.c_str (), tn1.c_str ());
-}
-
-static void
 gripe_no_conversion (const string& tn1, const string& tn2)
 {
   error ("no suitable conversion found for assignment of %s to indexed %s",
 	 tn2.c_str (), tn1.c_str ());
 }
 
-static void
-gripe_conversion_failed (const string& tn1, const string& tn2)
-{
-  error ("type conversion for assignment of %s to indexed %s failed",
-	 tn2.c_str (), tn1.c_str ());
-}
-
-bool
-octave_value::convert_and_assign (const octave_value_list& idx,
-				  const octave_value& rhs)
-{
-  bool assignment_ok = false;
-
-  int t_lhs = type_id ();
-  int t_rhs = rhs.type_id ();
-
-  int t_result
-    = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs);
-
-  if (t_result >= 0)
-    {
-      octave_value::type_conv_fcn cf
-	= octave_value_typeinfo::lookup_widening_op (t_lhs, t_result);
-
-      if (cf)
-	{
-	  octave_value *tmp = cf (*rep);
-
-	  if (tmp)
-	    {
-	      if (tmp != rep)
-		{
-		  if (--rep->count == 0)
-		    delete rep;
-
-		  rep = tmp;
-		  rep->count = 1;
-		}
-	      else
-		delete tmp;
-
-	      assignment_ok = try_assignment (idx, rhs);
-	    }
-	  else
-	    gripe_conversion_failed (type_name (), rhs.type_name ());
-	}
-      else
-	gripe_indexed_assignment (type_name (), rhs.type_name ());
-    }
-
-  return (assignment_ok && ! error_state);
-}
-
-bool
-octave_value::try_assignment_with_conversion (const octave_value_list& idx,
-					      const octave_value& rhs)
-{
-  bool assignment_ok = convert_and_assign (idx, rhs);
-
-  if (! (error_state || assignment_ok))
-    {
-      octave_value tmp_rhs;
-      octave_value::type_conv_fcn cf_rhs = rhs.numeric_conversion_function ();
-
-      if (cf_rhs)
-	tmp_rhs = octave_value (cf_rhs (*rhs.rep));
-      else
-	tmp_rhs = rhs;
-
-      octave_value *old_rep = 0;
-      octave_value::type_conv_fcn cf_this = numeric_conversion_function ();
-
-      if (cf_this)
-	{
-	  old_rep = rep;
-	  rep = cf_this (*rep);
-	  rep->count = 1;
-	}
-
-      cerr << type_name () << "\n";
-      cerr << tmp_rhs.type_name () << "\n";
-
-      if (cf_this || cf_rhs)
-	{
-	  assignment_ok = try_assignment (idx, tmp_rhs);
-
-	  if (! (error_state || assignment_ok))
-	    assignment_ok = convert_and_assign (idx, tmp_rhs);
-	}
-
-      if (! assignment_ok && old_rep)
-	{
-	  if (--rep->count == 0)
-	    delete rep;
-
-	  rep = old_rep;
-	  old_rep = 0;
-	}
-
-      if (old_rep && --old_rep->count == 0)
-	delete old_rep;
-    }
-
-  return (assignment_ok && ! error_state);
-}
-
-bool
-octave_value::try_assignment (const octave_value_list& idx,
-			      const octave_value& rhs)
-{
-  bool retval = false;
-
-  int t_lhs = type_id ();
-  int t_rhs = rhs.type_id ();
-
-  octave_value::assign_op_fcn f
-    = octave_value_typeinfo::lookup_assign_op (t_lhs, t_rhs);
-
-  if (f)
-    {
-      f (*rep, idx, *(rhs.rep));
-
-      retval = (! error_state);
-    }
-
-  return retval;
-}
-
 octave_value&
 octave_value::assign (const octave_value_list& idx, const octave_value& rhs)
 {
@@ -627,6 +492,141 @@
 }
 
 static void
+gripe_indexed_assignment (const string& tn1, const string& tn2)
+{
+  error ("assignment of %s to indexed %s not implemented",
+	 tn2.c_str (), tn1.c_str ());
+}
+
+static void
+gripe_conversion_failed (const string& tn1, const string& tn2)
+{
+  error ("type conversion for assignment of %s to indexed %s failed",
+	 tn2.c_str (), tn1.c_str ());
+}
+
+bool
+octave_value::convert_and_assign (const octave_value_list& idx,
+				  const octave_value& rhs)
+{
+  bool assignment_ok = false;
+
+  int t_lhs = type_id ();
+  int t_rhs = rhs.type_id ();
+
+  int t_result
+    = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs);
+
+  if (t_result >= 0)
+    {
+      octave_value::type_conv_fcn cf
+	= octave_value_typeinfo::lookup_widening_op (t_lhs, t_result);
+
+      if (cf)
+	{
+	  octave_value *tmp = cf (*rep);
+
+	  if (tmp)
+	    {
+	      if (tmp != rep)
+		{
+		  if (--rep->count == 0)
+		    delete rep;
+
+		  rep = tmp;
+		  rep->count = 1;
+		}
+	      else
+		delete tmp;
+
+	      assignment_ok = try_assignment (idx, rhs);
+	    }
+	  else
+	    gripe_conversion_failed (type_name (), rhs.type_name ());
+	}
+      else
+	gripe_indexed_assignment (type_name (), rhs.type_name ());
+    }
+
+  return (assignment_ok && ! error_state);
+}
+
+bool
+octave_value::try_assignment_with_conversion (const octave_value_list& idx,
+					      const octave_value& rhs)
+{
+  bool assignment_ok = convert_and_assign (idx, rhs);
+
+  if (! (error_state || assignment_ok))
+    {
+      octave_value tmp_rhs;
+      octave_value::type_conv_fcn cf_rhs = rhs.numeric_conversion_function ();
+
+      if (cf_rhs)
+	tmp_rhs = octave_value (cf_rhs (*rhs.rep));
+      else
+	tmp_rhs = rhs;
+
+      octave_value *old_rep = 0;
+      octave_value::type_conv_fcn cf_this = numeric_conversion_function ();
+
+      if (cf_this)
+	{
+	  old_rep = rep;
+	  rep = cf_this (*rep);
+	  rep->count = 1;
+	}
+
+      cerr << type_name () << "\n";
+      cerr << tmp_rhs.type_name () << "\n";
+
+      if (cf_this || cf_rhs)
+	{
+	  assignment_ok = try_assignment (idx, tmp_rhs);
+
+	  if (! (error_state || assignment_ok))
+	    assignment_ok = convert_and_assign (idx, tmp_rhs);
+	}
+
+      if (! assignment_ok && old_rep)
+	{
+	  if (--rep->count == 0)
+	    delete rep;
+
+	  rep = old_rep;
+	  old_rep = 0;
+	}
+
+      if (old_rep && --old_rep->count == 0)
+	delete old_rep;
+    }
+
+  return (assignment_ok && ! error_state);
+}
+
+bool
+octave_value::try_assignment (const octave_value_list& idx,
+			      const octave_value& rhs)
+{
+  bool retval = false;
+
+  int t_lhs = type_id ();
+  int t_rhs = rhs.type_id ();
+
+  octave_value::assign_op_fcn f
+    = octave_value_typeinfo::lookup_assign_op (t_lhs, t_rhs);
+
+  if (f)
+    {
+      f (*rep, idx, *(rhs.rep));
+
+      retval = (! error_state);
+    }
+
+  return retval;
+}
+
+static void
 gripe_binary_op (const string& on, const string& tn1, const string& tn2)
 {
   error ("binary operator %s not implemented for %s by %s operations",