[Signals2] Signal disconnect wrapper won't work

View: New views
6 Messages — Rating Filter:   Alert me  

[Signals2] Signal disconnect wrapper won't work

by Marc DelaCruz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hopefully this is not another simple oversight on my part but I have code like below and the disconnect wrapper does not work.

Thanks.

typedef boost::signals2::signal<void ()> VoidSignal;
typedef VoidSignal::slot_type VoidSlot;
class x{
public:
void somefuncA()
{
    cerr << "Bada bing" << endl;
}
void somefuncB()
{
    cerr << "Bada boom " << endl;
}
};


void disconnect(VoidSlot const& rF, VoidSignal& rSig)
{
    rSig.disconnect(rF); //won't compile
    //rSig.disconnect(&rF); //compiles but doesn't disconnect
}


int main()
{
    x myX;
    VoidSignal sig;
    sig.connect(VoidSlot(&x::somefuncB, &myX));
    disconnect(VoidSlot(&x::somefuncB, &myX, sig); //doesn't work/compile as expected
    disconnect(boost::bind(&x::somefuncB, &myX, sig); //doesn't work/compile either
    sig(); // will still invoke somefuncB
    return 0;
}
_______________________________________________
Boost-users mailing list
Boost-users@...
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Re: [Signals2] Signal disconnect wrapper won't work

by Steven Watanabe-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

AMDG

Marc dela Cruz wrote:

> Hopefully this is not another simple oversight on my part but I have code like below and the disconnect wrapper does not work.
>
> Thanks.
>
> typedef boost::signals2::signal<void ()> VoidSignal;
> typedef VoidSignal::slot_type VoidSlot;
> class x{
> public:
> void somefuncA()
> {
>     cerr << "Bada bing" << endl;
> }
> void somefuncB()
> {
>     cerr << "Bada boom " << endl;
> }
> };
>
>
> void disconnect(VoidSlot const& rF, VoidSignal& rSig)
> {
>     rSig.disconnect(rF); //won't compile
>     //rSig.disconnect(&rF); //compiles but doesn't disconnect
> }
>
>
> int main()
> {
>     x myX;
>     VoidSignal sig;
>     sig.connect(VoidSlot(&x::somefuncB, &myX));
>     disconnect(VoidSlot(&x::somefuncB, &myX, sig); //doesn't work/compile as expected
>     disconnect(boost::bind(&x::somefuncB, &myX, sig); //doesn't work/compile either
>     sig(); // will still invoke somefuncB
>     return 0;
> }
>  

Ignoring all the minor syntax errors, my guess is that
the basic problem is
http://www.boost.org/doc/html/function/faq.html#id1877737

In Christ,
Steven Watanabe

_______________________________________________
Boost-users mailing list
Boost-users@...
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Re: [Signals2] Signal disconnect wrapper won't work

by Marc DelaCruz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

So I guess the 'best' workaround would be to do something like below?

template<typename T>
void disconnect (void (T::*pMemFunc)(void), T& rObj, VoidSignal& rSig)
{
    rSig.disconnect(VoidSlot(pMemFunc, rObj));
}

Thanks for the help.

-----Original Message-----
From: boost-users-bounces@...
[mailto:boost-users-bounces@...]On Behalf Of Steven Watanabe
Sent: Tuesday, July 07, 2009 9:42 AM
To: boost-users@...
Subject: Re: [Boost-users] [Signals2] Signal disconnect wrapper won't
work


AMDG

Marc dela Cruz wrote:
> Hopefully this is not another simple oversight on my part but I have code
like below and the disconnect wrapper does not work.

>
> Thanks.
>
> typedef boost::signals2::signal<void ()> VoidSignal;
> typedef VoidSignal::slot_type VoidSlot;
> class x{
> public:
> void somefuncA()
> {
>     cerr << "Bada bing" << endl;
> }
> void somefuncB()
> {
>     cerr << "Bada boom " << endl;
> }
> };
>
>
> void disconnect(VoidSlot const& rF, VoidSignal& rSig)
> {
>     rSig.disconnect(rF); //won't compile
>     //rSig.disconnect(&rF); //compiles but doesn't disconnect
> }
>
>
> int main()
> {
>     x myX;
>     VoidSignal sig;
>     sig.connect(VoidSlot(&x::somefuncB, &myX));
>     disconnect(VoidSlot(&x::somefuncB, &myX, sig); //doesn't work/compile
as expected
>     disconnect(boost::bind(&x::somefuncB, &myX, sig); //doesn't
work/compile either
>     sig(); // will still invoke somefuncB
>     return 0;
> }
>

Ignoring all the minor syntax errors, my guess is that
the basic problem is
http://www.boost.org/doc/html/function/faq.html#id1877737

In Christ,
Steven Watanabe

_______________________________________________
Boost-users mailing list
Boost-users@...
http://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
Boost-users@...
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Re: [Signals2] Signal disconnect wrapper won't work

by Frank Mori Hess :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 07 July 2009, Marc DelaCruz wrote:
> So I guess the 'best' workaround would be to do something like below?
>
> template<typename T>
> void disconnect (void (T::*pMemFunc)(void), T& rObj, VoidSignal& rSig)
> {
>     rSig.disconnect(VoidSlot(pMemFunc, rObj));
> }
>

That doesn't look like it would compile.  signals2::slot objects aren't
equality comparable because boost::function objects aren't.  I don't believe
the function objects returned by bind are either.  The best workaround would
be to not use disconnect-by-slot at all and use the connection object
returned by the connect call to disconnect.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkpTajsACgkQ5vihyNWuA4X0bgCeKOe4rBBByM5n2/9VB/iJERKc
EdUAn3BT44t4LUZJrAa1gcTY3NlNP33A
=10Wb
-----END PGP SIGNATURE-----
_______________________________________________
Boost-users mailing list
Boost-users@...
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Re: [Signals2] Signal disconnect wrapper won't work

by Marc DelaCruz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Doing the following seems to work. I have equivalent slots tied to the
signal and
needed to disconnect only specific ones. I guess I could force a grouping
for each added
slot and disconnect via the grouping.

template<typename T>
void disconnect (void (T::*pMemFunc)(), T* pObj, VoidSignal& rSig)
{
     rSig.disconnect(boost::bind(pMemFunc, pObj));
}

-----Original Message-----
From: boost-users-bounces@...
[mailto:boost-users-bounces@...]On Behalf Of Frank Mori Hess
Sent: Tuesday, July 07, 2009 10:31 AM
To: boost-users@...
Subject: Re: [Boost-users] [Signals2] Signal disconnect wrapper won't
work


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 07 July 2009, Marc DelaCruz wrote:
> So I guess the 'best' workaround would be to do something like below?
>
> template<typename T>
> void disconnect (void (T::*pMemFunc)(void), T& rObj, VoidSignal& rSig)
> {
>     rSig.disconnect(VoidSlot(pMemFunc, rObj));
> }
>

That doesn't look like it would compile.  signals2::slot objects aren't
equality comparable because boost::function objects aren't.  I don't believe
the function objects returned by bind are either.  The best workaround would
be to not use disconnect-by-slot at all and use the connection object
returned by the connect call to disconnect.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkpTajsACgkQ5vihyNWuA4X0bgCeKOe4rBBByM5n2/9VB/iJERKc
EdUAn3BT44t4LUZJrAa1gcTY3NlNP33A
=10Wb
-----END PGP SIGNATURE-----
_______________________________________________
Boost-users mailing list
Boost-users@...
http://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
Boost-users@...
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Re: [Signals2] Signal disconnect wrapper won't work

by Frank Mori Hess :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 07 July 2009, Marc DelaCruz wrote:
> Doing the following seems to work.

So it turns out Boost.Bind does return function objects that are equality
comparable, albeit not with the proper semantics for comparison against a
boost::function.  However, Boost.Bind also provides undocumented
function_equal overloads which do make comparison against boost::function
objects work.  So you can use a boost::bind return value to
disconnect-by-slot, although IMO using signals2::connection objects is still
preferable.

> I have equivalent slots tied to the
> signal and
> needed to disconnect only specific ones. I guess I could force a grouping
> for each added
> slot and disconnect via the grouping.
>
> template<typename T>
> void disconnect (void (T::*pMemFunc)(), T* pObj, VoidSignal& rSig)
> {
>      rSig.disconnect(boost::bind(pMemFunc, pObj));
> }
>
> -----Original Message-----
> From: boost-users-bounces@...
> [mailto:boost-users-bounces@...]On Behalf Of Frank Mori Hess
> Sent: Tuesday, July 07, 2009 10:31 AM
> To: boost-users@...
> Subject: Re: [Boost-users] [Signals2] Signal disconnect wrapper won't
> work


> I don't
> believe the function objects returned by bind are either.  The best
> workaround would be to not use disconnect-by-slot at all and use the
> connection object returned by the connect call to disconnect.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkpTtqwACgkQ5vihyNWuA4Ul5QCffTidOo2dPMGANu67sex0ZX3V
X4sAoOFgy3ZY+pawBzC+e0SGHL3505ew
=+AOn
-----END PGP SIGNATURE-----
_______________________________________________
Boost-users mailing list
Boost-users@...
http://lists.boost.org/mailman/listinfo.cgi/boost-users