octave-maintainers
[Top][All Lists]
Advanced

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

Re: How to check for equality between 2 octave_value objects?


From: John W. Eaton
Subject: Re: How to check for equality between 2 octave_value objects?
Date: Fri, 08 Aug 2008 11:12:35 -0400

On  8-Aug-2008, Michael Goffioul wrote:

| Thinking about possible implementations, you might also
| consider to add a method to the octave_value/octave_base_value
| class like bool isequal (const octave_value& ov) and leave the
| work of equality check to the derived class of octave_base_value.

I suggested the other method because I think all other binary
operators are handled by using a lookup table on both types rather
than dispatching on the first and expecting that function to somehow
be able to handle all others.  However, if what you are looking for is
precise equality (integers do not compare equal to floats, for
example), then this approach might be OK.  You could do something like
the following (untested):

  bool octave_value::isequal (const octave_value& a) const
  {
    return rep->isequal (a);
  }

with (for example)

  bool octave_cell::isequal (const octave_value& a) const
  {
    bool retval = false;

    try
      {
        // Use dynamic cast because we want a precise type test
        // without the possibility for type conversion performed by
        // an extractor function.

        const octave_cell& a_cell
          = dynamic_cast<const octave_cell&> (a.get_rep ());

        retval = isequal (matrix, a_cell.matrix);
      }
    catch (std::bad_cast) { /* do nothing */ }

    return retval;
  }

and

  bool isequal (const Cell& a, const Cell& b);


jwe


reply via email to

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