Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:08:48

0001 // Boost.Signals2 library
0002 
0003 // Copyright Frank Mori Hess 2007-2008.
0004 // Use, modification and
0005 // distribution is subject to the Boost Software License, Version
0006 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 // For more information, see http://www.boost.org
0010 
0011 #ifndef BOOST_SIGNALS2_SHARED_CONNECTION_BLOCK_HPP
0012 #define BOOST_SIGNALS2_SHARED_CONNECTION_BLOCK_HPP
0013 
0014 #include <boost/shared_ptr.hpp>
0015 #include <boost/signals2/connection.hpp>
0016 #include <boost/weak_ptr.hpp>
0017 
0018 namespace boost
0019 {
0020   namespace signals2
0021   {
0022     class shared_connection_block
0023     {
0024     public:
0025       shared_connection_block(const signals2::connection &conn = signals2::connection(),
0026         bool initially_blocked = true):
0027         _weak_connection_body(conn._weak_connection_body)
0028       {
0029         if(initially_blocked) block();
0030       }
0031       void block()
0032       {
0033         if(blocking()) return;
0034         boost::shared_ptr<detail::connection_body_base> connection_body(_weak_connection_body.lock());
0035         if(connection_body == 0)
0036         {
0037           // Make _blocker non-empty so the blocking() method still returns the correct value
0038           // after the connection has expired.
0039           _blocker.reset(static_cast<int*>(0));
0040           return;
0041         }
0042         _blocker = connection_body->get_blocker();
0043       }
0044       void unblock()
0045       {
0046         _blocker.reset();
0047       }
0048       bool blocking() const
0049       {
0050         shared_ptr<void> empty;
0051         return _blocker < empty || empty < _blocker;
0052       }
0053       signals2::connection connection() const
0054       {
0055         return signals2::connection(_weak_connection_body);
0056       }
0057     private:
0058       boost::weak_ptr<detail::connection_body_base> _weak_connection_body;
0059       shared_ptr<void> _blocker;
0060     };
0061   }
0062 } // end namespace boost
0063 
0064 #endif // BOOST_SIGNALS2_SHARED_CONNECTION_BLOCK_HPP