libsigc++ 3.8.1

Public Member Functions | List of all members
sigc::connection Struct Reference
Signals

Convenience class for safe disconnection. More...

`#include <sigc++/connection.h>`

## Public Member Functions
| connection () noexcept
| Constructs an empty connection object.
| connection (const connection & c)
| Constructs a connection object copying an existing one.
| connection (slot_base & slot)
| Constructs a connection object from a slot object.
| ~connection ()
bool | block (bool should_block=true) noexcept
| Sets or unsets the blocking state of this connection.
bool | blocked () const noexcept
| Returns whether the connection is blocked.
bool | connected () const noexcept
| Returns whether the connection is still active.
void | disconnect ()
| Disconnects the referred slot.
bool | empty () const noexcept
| Returns whether the connection is still active.
| operator bool () const noexcept
| Returns whether the connection is still active.
connection & | operator= (const connection &src)
| Overrides this connection object copying another one.
bool | unblock () noexcept
| Unsets the blocking state of this connection.

## Detailed Description

Convenience class for safe disconnection.

This may be used to disconnect the referred slot at any time (disconnect()). sigc::signal::connect() and sigc::signal::connect_first() return a sigc::connection.

sigc::connection conn = sig.connect(sigc::mem_fun(a, &A::foo));
sigc::mem_fun
decltype(auto) mem_fun(T_return(T_obj::*func)(T_arg...))
Creates a functor of type sigc::mem_functor which wraps a method.
Definition mem_fun.h:186
sigc::ptr_fun
decltype(auto) ptr_fun(T_return(*func)(T_args...))
Creates a functor of type sigc::pointer_functor which wraps an existing non-member function.
Definition ptr_fun.h:107
sigc::connection
Convenience class for safe disconnection.
Definition connection.h:50

If the slot has already been destroyed, disconnect() does nothing. empty() or operator bool() can be used to test whether the connection is still active. The connection can be blocked (block(), unblock()).

sigc::connection doesnʼt disconnect the slot automatically upon destruction. You do not need to keep the sigc::connection object to retain the connection of the slot to the signal. See also sigc::scoped_connection, which does disconnect automatically when the connection object is destroyed or replaced.

## Constructor & Destructor Documentation

## ◆ connection() [1/3]

sigc::connection::connection | ( |  | ) |
| noexcept

Constructs an empty connection object.

## ◆ connection() [2/3]

sigc::connection::connection | ( | const connection & | c | ) |

Constructs a connection object copying an existing one.

Parameters

  c | The connection object to make a copy from.

## ◆ connection() [3/3]

sigc::connection::connection | ( | slot_base & | slot | ) |
| explicit

Constructs a connection object from a slot object.

Parameters

  slot | The slot to operate on.

## ◆ ~connection()

sigc::connection::~connection | ( |  | ) |

## Member Function Documentation

## ◆ block()

bool sigc::connection::block | ( | bool | should_block = `true` | ) |
| noexcept

Sets or unsets the blocking state of this connection.

See slot_base::block() for details.

Parameters

  should_block | Indicates whether the blocking state should be set or unset.

Returns
  `true` if the connection has been in blocking state before.

## ◆ blocked()

bool sigc::connection::blocked | ( |  | ) | const
| noexcept

Returns whether the connection is blocked.

Returns
  `true` if the connection is blocked.

## ◆ connected()

bool sigc::connection::connected | ( |  | ) | const
| noexcept

Returns whether the connection is still active.

Returns
  `true` if the connection is still active.

## ◆ disconnect()

void sigc::connection::disconnect | ( |  | ) |

Disconnects the referred slot.

## ◆ empty()

bool sigc::connection::empty | ( |  | ) | const
| noexcept

Returns whether the connection is still active.

Returns
  `false` if the connection is still active.

## ◆ operator bool()

sigc::connection::operator bool | ( |  | ) | const
| explicit noexcept

Returns whether the connection is still active.

Returns
  `true` if the connection is still active.

## ◆ operator=()

connection & sigc::connection::operator= | ( | const connection & | src | ) |

Overrides this connection object copying another one.

Parameters

  src | The connection object to make a copy from.

## ◆ unblock()

bool sigc::connection::unblock | ( |  | ) |
| noexcept

Unsets the blocking state of this connection.

Returns
  `true` if the connection has been in blocking state before.