[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Checking octave_value equality (==) without generating an error?

From: Daniel J Sebald
Subject: Re: Checking octave_value equality (==) without generating an error?
Date: Sat, 22 Nov 2014 16:35:27 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16

On 11/22/2014 04:17 PM, Michael Goffioul wrote:
On Sat, Nov 22, 2014 at 4:45 PM, Daniel J Sebald <address@hidden
<mailto:address@hidden>> wrote:

    Try "try".

Not sure I'm following... I was referring to a method/function in C++.

Ah... Well, there is such an animal in C++, as you've explored, but it does apparently take more work to define exactly what the exception is.

Even something like the following will print an error message at octave

bool result;
// Assign ov1 and ov2 such that they're not comparable ({} == false)
octave_value ov1 (Cell ());
octave_value ov2 (false);
   result = (ov1 == ov2);
catch (...)
   result = false;

However, now that I'm thinking about it, what I'm looking for is
something along those lines:

bool is_equal_safe (const octave_value& ov1, const octave_value& ov2)
   bool retval;
   unwind_protect frame;

   frame.protect_var (error_state);
   frame.protect_var (warning_state);
   frame.protect_var (discard_error_messages);
   frame.protect_var (warning_error_messages);

   discard_error_messages = true;
   discard_warning_messages = true;

     octave_value ov_cmp_retval = (ov1 == ov2);
     retval = ov_cmp_retval.bool_value ();
   catch (octave_execution_exception)
     retval = false;

   return retval;

But this looks a bit overkill if something similar already exists in
octave code base.

John's the best reference on that one.

It's not that bad, though, as far as code. It looks like the overkill part is having to set up the environment to prevent Octave warnings from happening. If nothing exists, then if it can be written as a macro to replace "(ov1 == ov2)" with any general expression, that might be nice.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]