[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Oct-file error message construction and octave_value conversions
From: |
Andrew Janke |
Subject: |
Oct-file error message construction and octave_value conversions |
Date: |
Tue, 29 Jan 2019 19:39:38 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 |
Hi, folks,
Thanks for bearing with me and all my questions on oct-files in IRC.
I'm trying to construct detailed error messages for some of my oct
functions that incorporate size, type, and value info about their
inputs, but having a hard time doing so. Here's what I'm trying:
#include <cmath> #include <iostream> #include <octave/oct.h> DEFUN_DLD
(s01_02_error_msg_string_construction, args, nargout,
"Error message construction using argument type")
{
octave_value x = args(0);
std::string x_type_name = x.type_name ();
std::string msg =std::string ("Type of arg 1 is: ")+ x_type_name;
error (msg.c_str ());
builtin_type_t x_type = x.builtin_type ();
std::string msg2 =std::string ("Builtin type id of arg 1 is: ")+ x_type;
error (msg2.c_str ());
octave_idx_type n_elems = x.numel ();
std::string msg3 =std::string ("Numel in arg 1: ")+ n_elems;
error (msg3.c_str ());
}
The first "msg = ..." statement works. But each of those
other "msgX = ..." lines is giving me a compiler error. It's complaining
that "no viable conversion from 'octave_value' to 'std::string'". Which is
weird,
because builtin_type_t and octave_idx_type are not octave_values, are they?
builtin_type_t is an enum, and octave_idx_type is a typedef to an integer type.
Why does the compiler think an octave_value is involved here?
(BTW, yes, I know I should be using type_name() and not builtin_type(); I'm just
including it here to help track down the conversion issue I'm not
understanding.)
I'd like to stick with constructing std::string messages instead of using the
printf style
controls that error accepts (like 'error ("Numel in arg 1: %ld", (long)
octave_idx_type)')
because I want to use these with generic templated functions that will use the
template
types in the error message construction; "std::string + x" is polymorphic, but
printf
placeholders are not.
Cheers,
Andrew
- Oct-file error message construction and octave_value conversions,
Andrew Janke <=