annotate DEPENDENCIES/generic/include/boost/signals/connection.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Boost.Signals library
Chris@16 2
Chris@16 3 // Copyright Douglas Gregor 2001-2004. Use, modification and
Chris@16 4 // distribution is subject to the Boost Software License, Version
Chris@16 5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 6 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7
Chris@16 8 // For more information, see http://www.boost.org
Chris@16 9
Chris@16 10 #ifndef BOOST_SIGNALS_CONNECTION_HPP
Chris@16 11 #define BOOST_SIGNALS_CONNECTION_HPP
Chris@16 12
Chris@16 13 #include <boost/signals/detail/signals_common.hpp>
Chris@16 14 #include <boost/smart_ptr.hpp>
Chris@16 15 #include <boost/operators.hpp>
Chris@16 16 #include <boost/any.hpp>
Chris@16 17 #include <list>
Chris@16 18 #include <cassert>
Chris@16 19 #include <utility>
Chris@16 20
Chris@16 21 #ifdef BOOST_HAS_ABI_HEADERS
Chris@16 22 # include BOOST_ABI_PREFIX
Chris@16 23 #endif
Chris@16 24
Chris@16 25 namespace boost {
Chris@16 26 namespace BOOST_SIGNALS_NAMESPACE {
Chris@16 27 class trackable;
Chris@16 28
Chris@16 29 namespace detail {
Chris@16 30 // Represents an object that has been bound as part of a slot, and how
Chris@16 31 // to notify that object of a disconnect
Chris@16 32 struct bound_object {
Chris@16 33 void* obj;
Chris@16 34 void* data;
Chris@16 35 void (*disconnect)(void*, void*);
Chris@16 36
Chris@16 37 bool operator==(const bound_object& other) const
Chris@16 38 { return obj == other.obj && data == other.data; }
Chris@16 39 bool operator<(const bound_object& other) const
Chris@16 40 { return obj < other.obj; }
Chris@16 41
Chris@16 42 // To support intel 80 compiler, 2004/03/18 (Mark Rodgers)
Chris@16 43 bool operator!=(const bound_object& other) const
Chris@16 44 { return !(*this==other); }
Chris@16 45 bool operator>(const bound_object& other) const
Chris@16 46 { return !(*this < other); }
Chris@16 47 };
Chris@16 48
Chris@16 49 // Describes the connection between a signal and the objects that are
Chris@16 50 // bound for a specific slot. Enables notification of the signal and the
Chris@16 51 // slots when a disconnect is requested.
Chris@16 52 struct basic_connection {
Chris@16 53 void* signal;
Chris@16 54 void* signal_data;
Chris@16 55 void (*signal_disconnect)(void*, void*);
Chris@16 56 bool blocked_;
Chris@16 57
Chris@16 58 std::list<bound_object> bound_objects;
Chris@16 59 };
Chris@16 60 } // end namespace detail
Chris@16 61
Chris@16 62 // The user may freely pass around the "connection" object and terminate
Chris@16 63 // the connection at any time using disconnect().
Chris@16 64 class BOOST_SIGNALS_DECL connection :
Chris@16 65 private less_than_comparable1<connection>,
Chris@16 66 private equality_comparable1<connection>
Chris@16 67 {
Chris@16 68 public:
Chris@16 69 connection() : con(), controlling_connection(false) {}
Chris@16 70 connection(const connection&);
Chris@16 71 ~connection();
Chris@16 72
Chris@16 73 // Block he connection: if the connection is still active, there
Chris@16 74 // will be no notification
Chris@16 75 void block(bool should_block = true) { con->blocked_ = should_block; }
Chris@16 76 void unblock() { con->blocked_ = false; }
Chris@16 77 bool blocked() const { return !connected() || con->blocked_; }
Chris@16 78
Chris@16 79 // Disconnect the signal and slot, if they are connected
Chris@16 80 void disconnect() const;
Chris@16 81
Chris@16 82 // Returns true if the signal and slot are connected
Chris@16 83 bool connected() const { return con.get() && con->signal_disconnect; }
Chris@16 84
Chris@16 85 // Comparison of connections
Chris@16 86 bool operator==(const connection& other) const;
Chris@16 87 bool operator<(const connection& other) const;
Chris@16 88
Chris@16 89 // Connection assignment
Chris@16 90 connection& operator=(const connection& other) ;
Chris@16 91
Chris@16 92 // Swap connections
Chris@16 93 void swap(connection& other);
Chris@16 94
Chris@16 95 public: // TBD: CHANGE THIS
Chris@16 96 // Set whether this connection object is controlling or not
Chris@16 97 void set_controlling(bool control = true)
Chris@16 98 { controlling_connection = control; }
Chris@16 99
Chris@16 100 shared_ptr<BOOST_SIGNALS_NAMESPACE::detail::basic_connection>
Chris@16 101 get_connection() const
Chris@16 102 { return con; }
Chris@16 103
Chris@16 104 private:
Chris@16 105 friend class detail::signal_base_impl;
Chris@16 106 friend class detail::slot_base;
Chris@16 107 friend class trackable;
Chris@16 108
Chris@16 109 // Reset this connection to refer to a different actual connection
Chris@16 110 void reset(BOOST_SIGNALS_NAMESPACE::detail::basic_connection*);
Chris@16 111
Chris@16 112 // Add a bound object to this connection (not for users)
Chris@16 113 void add_bound_object(const BOOST_SIGNALS_NAMESPACE::detail::bound_object& b);
Chris@16 114
Chris@16 115 friend class BOOST_SIGNALS_NAMESPACE::detail::bound_objects_visitor;
Chris@16 116
Chris@16 117 // Pointer to the actual contents of the connection
Chris@16 118 shared_ptr<BOOST_SIGNALS_NAMESPACE::detail::basic_connection> con;
Chris@16 119
Chris@16 120 // True if the destruction of this connection object should disconnect
Chris@16 121 bool controlling_connection;
Chris@16 122 };
Chris@16 123
Chris@16 124 // Similar to connection, but will disconnect the connection when it is
Chris@16 125 // destroyed unless release() has been called.
Chris@16 126 class BOOST_SIGNALS_DECL scoped_connection : public connection {
Chris@16 127 public:
Chris@16 128 scoped_connection() : connection(), released(false) {}
Chris@16 129 scoped_connection(const connection&);
Chris@16 130 scoped_connection(const scoped_connection&);
Chris@16 131 ~scoped_connection();
Chris@16 132
Chris@16 133 connection release();
Chris@16 134
Chris@16 135 void swap(scoped_connection&);
Chris@16 136
Chris@16 137 scoped_connection& operator=(const connection&);
Chris@16 138 scoped_connection& operator=(const scoped_connection&);
Chris@16 139
Chris@16 140 private:
Chris@16 141 bool released;
Chris@16 142 };
Chris@16 143
Chris@16 144 namespace detail {
Chris@16 145 struct connection_slot_pair {
Chris@16 146 connection first;
Chris@16 147 any second;
Chris@16 148
Chris@16 149 connection_slot_pair() {}
Chris@16 150
Chris@16 151 connection_slot_pair(const connection& c, const any& a)
Chris@16 152 : first(c), second(a)
Chris@16 153 {
Chris@16 154 }
Chris@16 155
Chris@16 156 // Dummys to allow explicit instantiation to work
Chris@16 157 bool operator==(const connection_slot_pair&) const { return false; }
Chris@16 158 bool operator<(const connection_slot_pair&) const { return false;}
Chris@16 159 };
Chris@16 160
Chris@16 161 // Determines if the underlying connection is disconnected
Chris@16 162 struct is_disconnected {
Chris@16 163 typedef connection_slot_pair argument_type;
Chris@16 164 typedef bool result_type;
Chris@16 165
Chris@16 166 inline bool operator()(const argument_type& c) const
Chris@16 167 {
Chris@16 168 return !c.first.connected();
Chris@16 169 }
Chris@16 170 };
Chris@16 171
Chris@16 172 // Determines if the underlying connection is callable, ie if
Chris@16 173 // it is connected and not blocked
Chris@16 174 struct is_callable {
Chris@16 175 typedef connection_slot_pair argument_type;
Chris@16 176 typedef bool result_type;
Chris@16 177
Chris@16 178 inline bool operator()(const argument_type& c) const
Chris@16 179 {
Chris@16 180 return c.first.connected() && !c.first.blocked() ;
Chris@16 181 }
Chris@16 182 };
Chris@16 183
Chris@16 184 // Autodisconnects the bound object when it is destroyed unless the
Chris@16 185 // release method is invoked.
Chris@16 186 class auto_disconnect_bound_object {
Chris@16 187 public:
Chris@16 188 auto_disconnect_bound_object(const bound_object& b) :
Chris@16 189 binding(b), auto_disconnect(true)
Chris@16 190 {
Chris@16 191 }
Chris@16 192
Chris@16 193 ~auto_disconnect_bound_object()
Chris@16 194 {
Chris@16 195 if (auto_disconnect)
Chris@16 196 binding.disconnect(binding.obj, binding.data);
Chris@16 197 }
Chris@16 198
Chris@16 199 void release() { auto_disconnect = false; }
Chris@16 200
Chris@16 201 private:
Chris@16 202 bound_object binding;
Chris@16 203 bool auto_disconnect;
Chris@16 204 };
Chris@16 205 } // end namespace detail
Chris@16 206 } // end namespace BOOST_SIGNALS_NAMESPACE
Chris@16 207 } // end namespace boost
Chris@16 208
Chris@16 209 #ifdef BOOST_HAS_ABI_HEADERS
Chris@16 210 # include BOOST_ABI_SUFFIX
Chris@16 211 #endif
Chris@16 212
Chris@16 213 #endif // BOOST_SIGNALS_CONNECTION_HPP