Re: [sigc] Disconnection without objects [on 1.2.5]



Eric, could you file a bug report at http://bugzilla.gnome.org/ ?
Just to make sure I don't forget (exam tomorrow => no time today) ...

Regards,

  Martin

Am 2003.07.29 22:24 schrieb(en) Eric Nicolas:
Hi Martin,

Thanks for your quick answer.
This is bad news, but not too bad :-)

Since my post I had a closer look to libsigc++ code, and I
thought my proposal would be possible using a simple implementation
of the "==" operator on slot instances. Something like:

   class SignalBase {
      Connection connect(Slot *slot)
      {
         impl()->push_back(slot);
      }
      disconnect(Slot *slot)
      {
         impl()->erase(slot);
      }
   }

Where "erase()" would simply browse the existing connections and
compare each slot remembered with the one provided using the "=="
operator.

Of course the trick would be in this operator, which would have to
be implemented differently for each kind of slot (functor, pointer-
to-method, ...).

Anyway, this may not be feasible and was just an idea :-)

****

But your proposal of clear() really does the trick for me ! It would be exactly what I need (even though it is less "clean" than removing exactly what has been
connected).
Could you provide this as a patch to 1.2.5 ???

Thanks a lot.

Eric.

Martin Schulze wrote:

Hi Eric!

Unfortunately, this is currently not supported by libsigc++.
Also, there is no easy way to add this feature. In the 1.2
series functionality would have to be added to Signal, Slot,
ObjectSlot, all adaptors types and some internal structures
which would probably mean ABI breakage.
In the upcoming 2.0 series it is practically impossible because
you can use any functor type as slot and we don't want to
add restrictions to this by requiring a "disconnect if you
hold a reference to object xy" function.

libsigc++ doesn't really "keep track" of the objects that
are connected to signal. Rather, the references to your objects
are hidden somewhere deep in internal data structures. This
is the price for the great flexibility of the yet typesafe
library.

However, I think it would make sense to provide a function
SigC::Object::clear() (or SigC::Object::clear_dependencies())
that would destroy _any_ connections that refer to a certain
object. Your example below would read:

class Receiver : public SigC::Object {
  // BTW: always inherit SigC::Object for auto-disconnection

  void connect()
    { emitter_.changed.connect(
        SigC::slot(*this, &Receiver::onChanged)); }

  void disconnect_all()
    { SigC::Object::clear(); }
}

Would this solve your problem? What do others think about it?

Regards,

  Martin


Am 2003.07.29 17:29 schrieb(en) Eric NICOLAS:

Hi,

I'm relatively new to LibSigC++, so bear with me if this something
stupid I'm asking. I've read the docs and had a look to the source
code before posting here.

I would like to be able to disconnect a slot without keeping a
connection object. This should be possible for slots with an
instance in it because the instance pointer is a unique key to
the connection.

If I don't have this, I have in many place in my code to keep
record of the connection objects and this is really a pain and
it duplicates the bookkeeping of the connections which is
already well done in LibSigC++, so should not be required.

So, to be more precise, I'd like this kind of behaviour:

class Emitter {
public:
  SigC::Signal0<void> changed;
};

class Receiver {
public:
  void connect()
  {
    // connect the slot
    emitter_.changed.connect(SigC::slot(*this, &Receiver::
onChanged));
  }

  void disconnect()
  {
    // disconnect the slot
    emitter_.changed.disconnect(SigC::slot(*this,
&Receiver::onChanged));
  }
};

Is this feasible with the current version of the library (1.2.5), or
how
difficult would it be to add this ?

Thanks !

_______________________________________________
libsigc-list mailing list
libsigc-list gnome org
http://mail.gnome.org/mailman/listinfo/libsigc-list




_______________________________________________
libsigc-list mailing list
libsigc-list gnome org
http://mail.gnome.org/mailman/listinfo/libsigc-list



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