Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Disconnecting

Connections can be terminated in two ways. One is through the "trackable" mechanism of Boost.Signals, which will automatically destroy connections to a trackable object when the object is destroyed. The other way is through the disconnect_all_slots method of the signal sender.

Table 1.8. disconnect example

fused

unfused

        signals::storage<void (), signals::unfused> banger;
        {
            signals::counter<void (), signals::unfused> counter;
            signals::storage<void (float), signals::unfused> floater;
            floater(2.5f);
            signals::storage<void (float), signals::unfused> collector(0.0f);
            
            banger
                | counter
                | (floater >>= collector).send_slot();
            
            banger();
            BOOST_CHECK_EQUAL(counter.count(), 1);
            BOOST_CHECK_EQUAL(collector.at<0>(), 2.5f);
        } // counter, floater, and collector are now destroyed and disconnected with Boost.Signals
#ifdef SIGNAL_NETWORK_THREAD_SAFE
        // if Signal Network has detected thread safe signals, we need to
        // touch the signal to disconnect things that are destroyed:
        // unfortunatelly, this call hangs on MSVC!
        // banger();
#endif
        BOOST_CHECK_EQUAL(banger.default_signal().num_slots(), 0u); 
        
        signals::counter<void (), signals::unfused> counter;
        
        banger >>= counter;
        banger.disconnect_all_slots();
        
        banger();
        BOOST_CHECK_EQUAL(counter.count(), 0);
        

Copyright © 2007 Stjepan Rajko

PrevUpHomeNext