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



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




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