1 // Boost.Signals2 library
3 // Copyright Frank Mori Hess 2007-2008.
4 // Use, modification and
5 // distribution is subject to the Boost Software License, Version
6 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // For more information, see http://www.boost.org
11 #ifndef BOOST_SIGNALS2_SHARED_CONNECTION_BLOCK_HPP
12 #define BOOST_SIGNALS2_SHARED_CONNECTION_BLOCK_HPP
14 #include <boost/shared_ptr.hpp>
15 #include <boost/signals2/connection.hpp>
16 #include <boost/weak_ptr.hpp>
22 class shared_connection_block
25 shared_connection_block(const signals2::connection &conn = signals2::connection(),
26 bool initially_blocked = true):
27 _weak_connection_body(conn._weak_connection_body)
29 if(initially_blocked) block();
33 if(blocking()) return;
34 boost::shared_ptr<detail::connection_body_base> connection_body(_weak_connection_body.lock());
35 if(connection_body == 0)
37 // Make _blocker non-empty so the blocking() method still returns the correct value
38 // after the connection has expired.
39 _blocker.reset(static_cast<int*>(0));
42 _blocker = connection_body->get_blocker();
50 shared_ptr<void> empty;
51 return _blocker < empty || empty < _blocker;
53 signals2::connection connection() const
55 return signals2::connection(_weak_connection_body);
58 boost::weak_ptr<detail::connection_body_base> _weak_connection_body;
59 shared_ptr<void> _blocker;
62 } // end namespace boost
64 #endif // BOOST_SIGNALS2_SHARED_CONNECTION_BLOCK_HPP