diff libinterp/octave-value/ov.cc @ 20700:68e3a747ca02

rename octave_value value extractors that accept error message args * ov.h, ov.cc (octave_value::xcell_value, octave_value::xstring_value, octave_value::xcellstr_value): Rename functions that accept error message args. Handle error directly. Only forward to functions that don't attempt type conversion. Change all uses. * ov-base.h, ov-base.cc (octave_base_value::xstring_value): Don't do type conversion. (octave_base_value::cell_value, octave_base_value::cellstr_value): Delete versions that accept error message args. * ov-str-mat.h, ov-str-mat.cc (octave_char_matrix_str::string_value, octave_char_matrix_str::cell_value): Delete.
author John W. Eaton <jwe@octave.org>
date Fri, 13 Nov 2015 14:10:26 -0500
parents 5f04bfc7c17a
children 85e5efae848a
line wrap: on
line diff
--- a/libinterp/octave-value/ov.cc	Thu Nov 12 19:27:25 2015 -0800
+++ b/libinterp/octave-value/ov.cc	Fri Nov 13 14:10:26 2015 -0500
@@ -1550,17 +1550,6 @@
   return rep->cell_value ();
 }
 
-Cell
-octave_value::cell_value (const char *fmt, ...) const
-{
-  Cell retval;
-  va_list args;
-  va_start (args,fmt);
-  retval = rep->cell_value (fmt, args);
-  va_end (args);
-  return retval;
-}
-
 // Define the idx_type_value function here instead of in ov.h to avoid
 // needing definitions for the SIZEOF_X macros in ov.h.
 
@@ -1895,6 +1884,42 @@
                                            type_name (), "complex vector"));
 }
 
+// NAME can't always be "x ## FCN" because some of the original
+// value extraction functions perform implicit type conversions that we
+// wish to avoid for these functions.
+
+#define XVALUE_EXTRACTOR(TYPE, NAME, FCN) \
+  TYPE \
+  octave_value::NAME (const char *fmt, ...) const \
+  { \
+    TYPE retval; \
+ \
+    try \
+      { \
+        retval = FCN (); \
+      } \
+    catch (const octave_execution_exception&) \
+      { \
+        if (fmt) \
+          { \
+            va_list args; \
+            va_start (args, fmt); \
+            verror (fmt, args); \
+            va_end (args); \
+          } \
+ \
+        throw; \
+      } \
+ \
+    return retval; \
+  }
+
+XVALUE_EXTRACTOR (Cell, xcell_value, cell_value)
+XVALUE_EXTRACTOR (std::string, xstring_value, rep->xstring_value)
+XVALUE_EXTRACTOR (Array<std::string>, xcellstr_value, cellstr_value)
+
+#undef XVALUE_EXTRACTOR
+
 octave_value
 octave_value::storable_value (void) const
 {
@@ -2845,7 +2870,7 @@
 
       for (int k = 0; k < nel; k++)
         {
-          std::string item = type(k).string_value ("%s: type(%d) must be a string", name, k+1);
+          std::string item = type(k).xstring_value ("%s: type(%d) must be a string", name, k+1);
 
           if (item == "{}")
             type_string[k] = '{';