octave-maintainers
[Top][All Lists]
Advanced

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

how can I overload the operator <<= ?


From: John W. Eaton
Subject: how can I overload the operator <<= ?
Date: Tue, 12 Sep 2006 15:57:41 -0400

On 12-Sep-2006, Andrea Latina wrote:

| Hi all,
| 
| I'm trying to overload the operator "<<="  to use it with some new
| TYPE that I've defined for octave, let's say:
| 
| my_object_value : public octave_base_value {};...
| 
| So far, I've managed to overload the operator "<<", using:
| 
| my_object_value::register_type();
| DEFBINOP (lshift, a1, a2 );
| INSTALL_BINOP (op_lshift, my_object_value, my_object_value, lshift);
| 
| but I could not succeed in overloading <<=.
| 
| Which of the octave_base_value class's methods should I define into my
| class in order to have this operator working?

If your A <<= B operator will behave exactly as A = (A << B) then I
think you don't need to define anything.  For example, there is this
code in src/ov.cc that is called when performing assignments:

  const octave_value&
  octave_value::assign (assign_op op, const octave_value& rhs)
  {
    if (op == op_asn_eq)
      operator = (rhs);
    else
      {
        // FIXME -- only do the following stuff if we can't find
        // a specific function to call to handle the op= operation for
        // the types we have.

        binary_op binop = op_eq_to_binary_op (op);

        if (! error_state)
          {
            octave_value t = do_binary_op (binop, *this, rhs);

            if (! error_state)
              operator = (t);
          }

        if (error_state)
          gripe_assign_failed_or_no_method (assign_op_as_string (op),
                                            type_name (), rhs.type_name ());
      }

    return *this;
  }

Also, I think the current implementation doesn't really allow you to
define a special function for this operator, so you are actually
forced to have the A OP= B equivalent to A = (A OP B) semantics.  I
think that's the point of the FIXME comment.

jwe


reply via email to

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