octave-maintainers
[Top][All Lists]
Advanced

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

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


From: Michael Goffioul
Subject: Re: Checking octave_value equality (==) without generating an error?
Date: Sat, 22 Nov 2014 17:17:30 -0500

On Sat, Nov 22, 2014 at 4:45 PM, Daniel J Sebald <address@hidden> wrote:
Try "try".

Not sure I'm following... I was referring to a method/function in C++. Even something like the following will print an error message at octave prompt:

bool result;
// Assign ov1 and ov2 such that they're not comparable ({} == false)
octave_value ov1 (Cell ());
octave_value ov2 (false);
try
{
  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;

  try
  {
    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.

Michael.


reply via email to

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