# HG changeset patch # User John W. Eaton # Date 1444416109 14400 # Node ID e5986cba4ca820d0c2e17bda566e6a79f0da55b3 # Parent ba2b07c13913e9dfe7cce172987ab268f46bea24 new octave_value::cell_value method with optional error message * ov.h, ov.cc (octave_value::cell_value): New method. * ov-base.h, ov-base.cc (octave_base_value::cell_value): New default method. * ov-cell.h, ov-cell.cc (octave_cell::cell_value): New method. diff -r ba2b07c13913 -r e5986cba4ca8 libinterp/octave-value/ov-base.cc --- a/libinterp/octave-value/ov-base.cc Fri Oct 09 10:06:39 2015 -0400 +++ b/libinterp/octave-value/ov-base.cc Fri Oct 09 14:41:49 2015 -0400 @@ -537,6 +537,33 @@ return retval; } +Cell +octave_base_value::cell_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 Cell (); +} + Matrix octave_base_value::matrix_value (bool) const { diff -r ba2b07c13913 -r e5986cba4ca8 libinterp/octave-value/ov-base.h --- a/libinterp/octave-value/ov-base.h Fri Oct 09 10:06:39 2015 -0400 +++ b/libinterp/octave-value/ov-base.h Fri Oct 09 14:41:49 2015 -0400 @@ -481,6 +481,8 @@ virtual Cell cell_value (void) const; + virtual Cell cell_value (const char *fmt, va_list args) const; + virtual Matrix matrix_value (bool = false) const; virtual FloatMatrix float_matrix_value (bool = false) const; diff -r ba2b07c13913 -r e5986cba4ca8 libinterp/octave-value/ov-cell.h --- a/libinterp/octave-value/ov-cell.h Fri Oct 09 10:06:39 2015 -0400 +++ b/libinterp/octave-value/ov-cell.h Fri Oct 09 14:41:49 2015 -0400 @@ -135,6 +135,8 @@ Cell cell_value (void) const { return matrix; } + Cell cell_value (const char *, va_list) const { return matrix; } + octave_value_list list_value (void) const; octave_value convert_to_str_internal (bool pad, bool, char type) const diff -r ba2b07c13913 -r e5986cba4ca8 libinterp/octave-value/ov.cc --- a/libinterp/octave-value/ov.cc Fri Oct 09 10:06:39 2015 -0400 +++ b/libinterp/octave-value/ov.cc Fri Oct 09 14:41:49 2015 -0400 @@ -1550,6 +1550,15 @@ return rep->cell_value (); } +Cell +octave_value::cell_value (const char *fmt, ...) const +{ + va_list args; + va_start (args,fmt); + return rep->cell_value (fmt, args); + va_end (args); +} + // Define the idx_type_value function here instead of in ov.h to avoid // needing definitions for the SIZEOF_X macros in ov.h. diff -r ba2b07c13913 -r e5986cba4ca8 libinterp/octave-value/ov.h --- a/libinterp/octave-value/ov.h Fri Oct 09 10:06:39 2015 -0400 +++ b/libinterp/octave-value/ov.h Fri Oct 09 14:41:49 2015 -0400 @@ -770,6 +770,8 @@ Cell cell_value (void) const; + Cell cell_value (const char *fmt, ...) const; + Matrix matrix_value (bool frc_str_conv = false) const { return rep->matrix_value (frc_str_conv); }