Signals Library
connection.hpp
1 #ifndef SIGNALS_CONNECTION_HPP
2 #define SIGNALS_CONNECTION_HPP
3 #include <memory>
4 #include <utility>
5 
6 #include "detail/connection_impl_base.hpp"
7 
8 namespace sig {
9 
11 
13 class Connection {
14  public:
16  Connection() = default;
17 
19 
24  explicit Connection(std::weak_ptr<Connection_impl_base> wp_cib)
25  : pimpl_{std::move(wp_cib)}
26  {}
27 
29 
32  void disconnect() const
33  {
34  if (!this->pimpl_.expired())
35  pimpl_.lock()->disconnect();
36  }
37 
39 
40  auto connected() const -> bool
41  {
42  if (!this->pimpl_.expired())
43  return pimpl_.lock()->connected();
44  return false;
45  }
46 
48 
51  auto blocked() const -> bool
52  {
53  if (!this->pimpl_.expired())
54  return pimpl_.lock()->blocked();
55  return false;
56  }
57 
59  auto operator==(Connection const& x) const -> bool
60  {
61  return pimpl_.lock() == x.pimpl_.lock();
62  }
63 
65  auto operator<(Connection const& x) const -> bool
66  {
67  return pimpl_.lock() < x.pimpl_.lock();
68  }
69 
70  friend class Shared_connection_block;
71 
72  private:
73  std::weak_ptr<Connection_impl_base> pimpl_;
74 };
75 
77 inline auto operator!=(Connection const& x, Connection const& y) -> bool
78 {
79  return !(x == y);
80 }
81 
82 } // namespace sig
83 #endif // SIGNALS_CONNECTION_HPP
sig::Connection::Connection
Connection()=default
Default constructors a connection that refers to no real connection.
sig::Shared_connection_block
Blocks a Signal/Slot Connection.
Definition: shared_connection_block.hpp:13
sig::Connection::disconnect
void disconnect() const
Disconnects the connection.
Definition: connection.hpp:32
sig
Definition: connection.hpp:8
sig::Connection::Connection
Connection(std::weak_ptr< Connection_impl_base > wp_cib)
Constructor used by the Signal::connect() function.
Definition: connection.hpp:24
sig::Connection::blocked
auto blocked() const -> bool
Query whether the connection is currently blocked or not.
Definition: connection.hpp:51
sig::Connection::operator==
auto operator==(Connection const &x) const -> bool
Return true if both parameters refer to the same Signal/Slot connection.
Definition: connection.hpp:59
sig::Connection
Represents the connection made when a Slot is connected to a Signal.
Definition: connection.hpp:13
sig::Connection::connected
auto connected() const -> bool
Query whether the connection is connected or not.
Definition: connection.hpp:40
sig::Connection::operator<
auto operator<(Connection const &x) const -> bool
Does pointer less than comparison of underlying implementation.
Definition: connection.hpp:65
sig::operator!=
auto operator!=(Connection const &x, Connection const &y) -> bool
Returns !(*this == x)
Definition: connection.hpp:77