changeset 13694:441af0aa125a

char: when converting cell elements containing class objects, call overloaded char function if one exists * ov-class.cc, ov-class.h (octave_class::all_strings): New function.
author John W. Eaton <jwe@octave.org>
date Wed, 12 Oct 2011 21:28:30 -0400
parents cb52dd180d36
children 348857854c52
files src/ov-class.cc src/ov-class.h
diffstat 2 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/ov-class.cc	Wed Oct 12 20:36:19 2011 -0500
+++ b/src/ov-class.cc	Wed Oct 12 21:28:30 2011 -0400
@@ -996,6 +996,35 @@
   return retval;
 }
 
+string_vector
+octave_class::all_strings (bool pad) const
+{
+  string_vector retval;
+
+  octave_value meth = symbol_table::find_method ("char", class_name ());
+
+  if (meth.is_defined ())
+    {
+      octave_value_list args;
+      args(0) = octave_value (new octave_class (map, c_name));
+
+      octave_value_list tmp = feval (meth.function_value (), args, 1);
+
+      if (!error_state && tmp.length () >= 1)
+        {
+          if (tmp(0).is_string ())
+            retval = tmp(0).all_strings (pad);
+          else
+            error ("cname/char method did not return a character string");
+        }
+    }
+  else
+    error ("no char method defined for class %s", class_name().c_str ());
+
+  return retval;
+}
+
+
 void
 octave_class::print (std::ostream& os, bool) const
 {
--- a/src/ov-class.h	Wed Oct 12 20:36:19 2011 -0500
+++ b/src/ov-class.h	Wed Oct 12 21:28:30 2011 -0400
@@ -168,6 +168,8 @@
 
   octave_base_value *unique_parent_class (const std::string&);
 
+  string_vector all_strings (bool pad) const;
+
   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;