fix doc example typo
[boost.git] / boost / signals2 / shared_connection_block.hpp
blobe083cef853bbea56b8832bf18e7566b6c78e3925
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>
18 namespace boost
20 namespace signals2
22 class shared_connection_block
24 public:
25 shared_connection_block(const connection &conn):
26 _weak_connection_body(conn._weak_connection_body)
28 block();
30 void block()
32 if(blocking()) return;
33 boost::shared_ptr<detail::connection_body_base> connection_body(_weak_connection_body.lock());
34 if(connection_body == 0)
36 // Make _blocker non-empty so the blocking() method still returns the correct value
37 // after the connection has expired.
38 _blocker.reset(static_cast<int*>(0));
39 return;
41 _blocker = connection_body->get_blocker();
43 void unblock()
45 _blocker.reset();
47 bool blocking() const
49 shared_ptr<void> empty;
50 return _blocker < empty || empty < _blocker;
52 private:
53 boost::weak_ptr<detail::connection_body_base> _weak_connection_body;
54 shared_ptr<void> _blocker;
57 } // end namespace boost
59 #endif // BOOST_SIGNALS2_SHARED_CONNECTION_BLOCK_HPP