1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/signals/connection.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,213 @@
1.4 +// Boost.Signals library
1.5 +
1.6 +// Copyright Douglas Gregor 2001-2004. Use, modification and
1.7 +// distribution is subject to the Boost Software License, Version
1.8 +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
1.9 +// http://www.boost.org/LICENSE_1_0.txt)
1.10 +
1.11 +// For more information, see http://www.boost.org
1.12 +
1.13 +#ifndef BOOST_SIGNALS_CONNECTION_HPP
1.14 +#define BOOST_SIGNALS_CONNECTION_HPP
1.15 +
1.16 +#include <boost/signals/detail/signals_common.hpp>
1.17 +#include <boost/smart_ptr.hpp>
1.18 +#include <boost/operators.hpp>
1.19 +#include <boost/any.hpp>
1.20 +#include <list>
1.21 +#include <cassert>
1.22 +#include <utility>
1.23 +
1.24 +#ifdef BOOST_HAS_ABI_HEADERS
1.25 +# include BOOST_ABI_PREFIX
1.26 +#endif
1.27 +
1.28 +namespace boost {
1.29 + namespace BOOST_SIGNALS_NAMESPACE {
1.30 + class trackable;
1.31 +
1.32 + namespace detail {
1.33 + // Represents an object that has been bound as part of a slot, and how
1.34 + // to notify that object of a disconnect
1.35 + struct bound_object {
1.36 + void* obj;
1.37 + void* data;
1.38 + void (*disconnect)(void*, void*);
1.39 +
1.40 + bool operator==(const bound_object& other) const
1.41 + { return obj == other.obj && data == other.data; }
1.42 + bool operator<(const bound_object& other) const
1.43 + { return obj < other.obj; }
1.44 +
1.45 + // To support intel 80 compiler, 2004/03/18 (Mark Rodgers)
1.46 + bool operator!=(const bound_object& other) const
1.47 + { return !(*this==other); }
1.48 + bool operator>(const bound_object& other) const
1.49 + { return !(*this < other); }
1.50 + };
1.51 +
1.52 + // Describes the connection between a signal and the objects that are
1.53 + // bound for a specific slot. Enables notification of the signal and the
1.54 + // slots when a disconnect is requested.
1.55 + struct basic_connection {
1.56 + void* signal;
1.57 + void* signal_data;
1.58 + void (*signal_disconnect)(void*, void*);
1.59 + bool blocked_;
1.60 +
1.61 + std::list<bound_object> bound_objects;
1.62 + };
1.63 + } // end namespace detail
1.64 +
1.65 + // The user may freely pass around the "connection" object and terminate
1.66 + // the connection at any time using disconnect().
1.67 + class BOOST_SIGNALS_DECL connection :
1.68 + private less_than_comparable1<connection>,
1.69 + private equality_comparable1<connection>
1.70 + {
1.71 + public:
1.72 + connection() : con(), controlling_connection(false) {}
1.73 + connection(const connection&);
1.74 + ~connection();
1.75 +
1.76 + // Block he connection: if the connection is still active, there
1.77 + // will be no notification
1.78 + void block(bool should_block = true) { con->blocked_ = should_block; }
1.79 + void unblock() { con->blocked_ = false; }
1.80 + bool blocked() const { return !connected() || con->blocked_; }
1.81 +
1.82 + // Disconnect the signal and slot, if they are connected
1.83 + void disconnect() const;
1.84 +
1.85 + // Returns true if the signal and slot are connected
1.86 + bool connected() const { return con.get() && con->signal_disconnect; }
1.87 +
1.88 + // Comparison of connections
1.89 + bool operator==(const connection& other) const;
1.90 + bool operator<(const connection& other) const;
1.91 +
1.92 + // Connection assignment
1.93 + connection& operator=(const connection& other) ;
1.94 +
1.95 + // Swap connections
1.96 + void swap(connection& other);
1.97 +
1.98 + public: // TBD: CHANGE THIS
1.99 + // Set whether this connection object is controlling or not
1.100 + void set_controlling(bool control = true)
1.101 + { controlling_connection = control; }
1.102 +
1.103 + shared_ptr<BOOST_SIGNALS_NAMESPACE::detail::basic_connection>
1.104 + get_connection() const
1.105 + { return con; }
1.106 +
1.107 + private:
1.108 + friend class detail::signal_base_impl;
1.109 + friend class detail::slot_base;
1.110 + friend class trackable;
1.111 +
1.112 + // Reset this connection to refer to a different actual connection
1.113 + void reset(BOOST_SIGNALS_NAMESPACE::detail::basic_connection*);
1.114 +
1.115 + // Add a bound object to this connection (not for users)
1.116 + void add_bound_object(const BOOST_SIGNALS_NAMESPACE::detail::bound_object& b);
1.117 +
1.118 + friend class BOOST_SIGNALS_NAMESPACE::detail::bound_objects_visitor;
1.119 +
1.120 + // Pointer to the actual contents of the connection
1.121 + shared_ptr<BOOST_SIGNALS_NAMESPACE::detail::basic_connection> con;
1.122 +
1.123 + // True if the destruction of this connection object should disconnect
1.124 + bool controlling_connection;
1.125 + };
1.126 +
1.127 + // Similar to connection, but will disconnect the connection when it is
1.128 + // destroyed unless release() has been called.
1.129 + class BOOST_SIGNALS_DECL scoped_connection : public connection {
1.130 + public:
1.131 + scoped_connection() : connection(), released(false) {}
1.132 + scoped_connection(const connection&);
1.133 + scoped_connection(const scoped_connection&);
1.134 + ~scoped_connection();
1.135 +
1.136 + connection release();
1.137 +
1.138 + inline void swap(scoped_connection&);
1.139 +
1.140 + scoped_connection& operator=(const connection&);
1.141 + scoped_connection& operator=(const scoped_connection&);
1.142 +
1.143 + private:
1.144 + bool released;
1.145 + };
1.146 +
1.147 + namespace detail {
1.148 + struct connection_slot_pair {
1.149 + connection first;
1.150 + any second;
1.151 +
1.152 + connection_slot_pair() {}
1.153 +
1.154 + connection_slot_pair(const connection& c, const any& a)
1.155 + : first(c), second(a)
1.156 + {
1.157 + }
1.158 +
1.159 + // Dummys to allow explicit instantiation to work
1.160 + bool operator==(const connection_slot_pair&) const { return false; }
1.161 + bool operator<(const connection_slot_pair&) const { return false;}
1.162 + };
1.163 +
1.164 + // Determines if the underlying connection is disconnected
1.165 + struct is_disconnected {
1.166 + typedef connection_slot_pair argument_type;
1.167 + typedef bool result_type;
1.168 +
1.169 + inline bool operator()(const argument_type& c) const
1.170 + {
1.171 + return !c.first.connected();
1.172 + }
1.173 + };
1.174 +
1.175 + // Determines if the underlying connection is callable, ie if
1.176 + // it is connected and not blocked
1.177 + struct is_callable {
1.178 + typedef connection_slot_pair argument_type;
1.179 + typedef bool result_type;
1.180 +
1.181 + inline bool operator()(const argument_type& c) const
1.182 + {
1.183 + return c.first.connected() && !c.first.blocked() ;
1.184 + }
1.185 + };
1.186 +
1.187 + // Autodisconnects the bound object when it is destroyed unless the
1.188 + // release method is invoked.
1.189 + class auto_disconnect_bound_object {
1.190 + public:
1.191 + auto_disconnect_bound_object(const bound_object& b) :
1.192 + binding(b), auto_disconnect(true)
1.193 + {
1.194 + }
1.195 +
1.196 + ~auto_disconnect_bound_object()
1.197 + {
1.198 + if (auto_disconnect)
1.199 + binding.disconnect(binding.obj, binding.data);
1.200 + }
1.201 +
1.202 + void release() { auto_disconnect = false; }
1.203 +
1.204 + private:
1.205 + bound_object binding;
1.206 + bool auto_disconnect;
1.207 + };
1.208 + } // end namespace detail
1.209 + } // end namespace BOOST_SIGNALS_NAMESPACE
1.210 +} // end namespace boost
1.211 +
1.212 +#ifdef BOOST_HAS_ABI_HEADERS
1.213 +# include BOOST_ABI_SUFFIX
1.214 +#endif
1.215 +
1.216 +#endif // BOOST_SIGNALS_CONNECTION_HPP