File: scoped_connection.cc

package info (click to toggle)
libsigc%2B%2B-3.0 3.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,352 kB
  • sloc: cpp: 6,829; xml: 347; makefile: 197; python: 148; sh: 73
file content (117 lines) | stat: -rw-r--r-- 2,747 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * Copyright 2023, The libsigc++ Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#include <sigc++/scoped_connection.h>
#include <utility>

namespace sigc
{

// All we are doing is assigning weak_raw_ptr, which is noexcept, so declare it.
// connectionʼs copy operators can be noexcept for that reason, if breaking ABI.
scoped_connection::scoped_connection(connection c) noexcept
: conn_(std::move(c))
{
}

scoped_connection&
scoped_connection::operator=(connection c)
{
  conn_.disconnect();
  conn_ = std::move(c);
  return *this;
}

// We do not implement move-ctor in terms of move-assign, so we can be noexcept,
// as we do not need to call the maybe-throwing disconnect() for obvious reason.
scoped_connection::scoped_connection(scoped_connection&& sc) noexcept
: conn_(std::exchange(sc.conn_, connection()))
{
}

scoped_connection&
scoped_connection::operator=(scoped_connection&& sc)
{
  conn_.disconnect();
  conn_ = std::exchange(sc.conn_, connection());
  return *this;
}

scoped_connection::~scoped_connection()
{
  conn_.disconnect();
}

bool
scoped_connection::empty() const noexcept
{
  return conn_.empty();
}

bool
scoped_connection::connected() const noexcept
{
  return conn_.connected();
}

bool
scoped_connection::blocked() const noexcept
{
  return conn_.blocked();
}

bool
scoped_connection::block(bool should_block) noexcept
{
  return conn_.block(should_block);
}

bool
scoped_connection::unblock() noexcept
{
  return conn_.unblock();
}

void
scoped_connection::disconnect()
{
  conn_.disconnect();
}

scoped_connection::operator bool() const noexcept
{
  return conn_.operator bool();
}

// Swapping can be noexcept, as it does not need to disconnect either connection
// because they will still stay alive, just in opposite instances post-swapping.
void
swap(scoped_connection& sca, scoped_connection& scb) noexcept
{
  using std::swap;
  swap(sca.conn_, scb.conn_);
}

connection
scoped_connection::release() noexcept
{
  return std::exchange(conn_, connection());
}

} /* namespace sigc */