diff libinterp/octave-value/ov-base.cc @ 20611:40ed9b46a800

new octave_value::string_value method with optional error message * ov.h (octave_value::string_vector): New method. ov-base.cc, ov-base.h (octave_base_value::string_vector): New default method. ov-str-mat.cc, ov-str-mat.h (octave_char_matrix_str::string_value): New method.
author John W. Eaton <jwe@octave.org>
date Thu, 08 Oct 2015 16:43:22 -0400
parents f90c8372b7ba
children e5986cba4ca8
line wrap: on
line diff
--- a/libinterp/octave-value/ov-base.cc	Thu Oct 08 20:15:19 2015 +0100
+++ b/libinterp/octave-value/ov-base.cc	Thu Oct 08 16:43:22 2015 -0400
@@ -910,6 +910,33 @@
   return retval;
 }
 
+std::string
+octave_base_value::string_value (const char *fmt, va_list args) const
+{
+  // Note that this method does not need to be particularly efficient
+  // since it is already an error to end up here.
+
+  // FIXME: do we want both the wrong-type-argument error and any custom
+  // error message, or just the custom error message, or should that
+  // behavior be optional in some way?
+
+  try
+    {
+      std::string tn = type_name ();
+
+      error ("wrong type argument '%s'\n", tn.c_str ());
+    }
+  catch (const octave_execution_exception&)
+    {
+      if (fmt)
+        verror (fmt, args);
+
+      throw;
+    }
+
+  return std::string ();
+}
+
 Array<std::string>
 octave_base_value::cellstr_value (void) const
 {