diff src/ov-fcn-handle.cc @ 10261:a4fb4675accb

make printing of handles more Matlab-compatible
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 03 Feb 2010 13:35:41 +0100
parents 2d47356a7a1a
children 57a59eae83cc
line wrap: on
line diff
--- a/src/ov-fcn-handle.cc	Wed Feb 03 12:49:17 2010 +0100
+++ b/src/ov-fcn-handle.cc	Wed Feb 03 13:35:41 2010 +0100
@@ -68,13 +68,15 @@
 				     "function handle",
 				     "function_handle");
 
+const std::string octave_fcn_handle::anonymous ("@<anonymous>");
+
 octave_fcn_handle::octave_fcn_handle (const octave_value& f,
 				      const std::string& n)
   : fcn (f), nm (n)
 {
   octave_user_function *uf = fcn.user_function_value (true);
 
-  if (uf)
+  if (uf && nm != anonymous)
     symbol_table::cache_name (uf->scope (), nm);
 }
 
@@ -284,7 +286,7 @@
 bool
 octave_fcn_handle::save_ascii (std::ostream& os)
 {
-  if (nm == "@<anonymous>")
+  if (nm == anonymous)
     {
       os << nm << "\n";
 
@@ -349,7 +351,7 @@
 
   is >> nm;
 
-  if (nm == "@<anonymous>")
+  if (nm == anonymous)
     {
       skip_preceeding_newline (is);
 
@@ -447,7 +449,7 @@
 bool
 octave_fcn_handle::save_binary (std::ostream& os, bool& save_as_floats)
 {
-  if (nm == "@<anonymous>")
+  if (nm == anonymous)
     {
       std::ostringstream nmbuf;
 
@@ -526,15 +528,17 @@
   if (! is)
     return false;
 
-  if (nm.length() >= 12 && nm.substr (0, 12) == "@<anonymous>")
+  size_t anl = anonymous.length ();
+
+  if (nm.length() >= anl && nm.substr (0, anl) == anonymous)
     {
       octave_idx_type len = 0;
 
-      if (nm.length() > 12)
+      if (nm.length() > anl)
 	{
-	  std::istringstream nm_is (nm.substr(12));
+	  std::istringstream nm_is (nm.substr (anl));
 	  nm_is >> len;
-	  nm = nm.substr(0,12);
+	  nm = nm.substr (0, anl);
 	}
 
       if (! is.read (reinterpret_cast<char *> (&tmp), 4))
@@ -679,7 +683,7 @@
     }
   H5Dclose (data_hid);
 
-  if (nm == "@<anonymous>")
+  if (nm == anonymous)
     {
       std::ostringstream buf;
       print_raw (buf, true);
@@ -934,7 +938,7 @@
   H5Dclose (data_hid);
   nm = nm_tmp;
 
-  if (nm == "@<anonymous>")
+  if (nm == anonymous)
     {
 #if HAVE_HDF5_18
       data_hid = H5Dopen (group_hid, "fcn", H5P_DEFAULT);
@@ -1264,7 +1268,7 @@
 {
   bool printed = false;
 
-  if (nm == "@<anonymous>")
+  if (nm == anonymous)
     {
       tree_print_code tpc (os);
 
@@ -1319,7 +1323,7 @@
     }
 
   if (! printed)
-    octave_print_internal (os, nm, pr_as_read_syntax,
+    octave_print_internal (os, "@" + nm, pr_as_read_syntax,
 			   current_print_indent_level ());
 }
 
@@ -1563,7 +1567,7 @@
 
 	      std::string fh_nm = fh->fcn_name ();
 
-	      if (fh_nm == "@<anonymous>")
+	      if (fh_nm == octave_fcn_handle::anonymous)
 		{
 		  std::ostringstream buf;
 		  fh->print_raw (buf);
@@ -1593,7 +1597,7 @@
 
 	      std::string nm = fcn->fcn_file_name ();
 
-	      if (fh_nm == "@<anonymous>")
+	      if (fh_nm == octave_fcn_handle::anonymous)
 		{
 		  m.assign ("file", nm);
 
@@ -1655,7 +1659,7 @@
 	{
 	  std::string fh_nm = fh->fcn_name ();
 
-	  if (fh_nm == "@<anonymous>")
+	  if (fh_nm == octave_fcn_handle::anonymous)
 	    {
 	      std::ostringstream buf;