]> git.tdb.fi Git - ext/sigc++-2.0.git/blob - sigc++/connection.cc
Adjust the name of the library to match upstream
[ext/sigc++-2.0.git] / sigc++ / connection.cc
1 /*
2  * Copyright 2002, The libsigc++ Development Team
3  *
4  *  This library is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Lesser General Public
6  *  License as published by the Free Software Foundation; either
7  *  version 2.1 of the License, or (at your option) any later version.
8  *
9  *  This library is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  *  Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public
15  *  License along with this library; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  */
19
20 #include <sigc++/connection.h>
21
22 namespace sigc {
23
24 connection::connection() noexcept
25 : slot_(nullptr)
26 {}
27
28 connection::connection(const connection& c)
29 : slot_(c.slot_)
30 {
31   //Let the connection forget about the signal handler when the handler object dies:
32   if (slot_)
33     slot_->add_destroy_notify_callback(this, &notify);
34 }
35
36 connection::connection(slot_base& sl)
37 : slot_(&sl)
38 {
39   //Let the connection forget about the signal handler when the handler object dies:
40   slot_->add_destroy_notify_callback(this, &notify);
41 }
42
43 connection& connection::operator=(const connection& c)
44 {
45   set_slot(c.slot_);
46   return *this;
47 }
48
49 connection::~connection()
50 {
51   if (slot_)
52     slot_->remove_destroy_notify_callback(this);
53 }
54
55 bool connection::empty() const noexcept
56 {
57   return (!slot_ || slot_->empty());
58 }
59
60 bool connection::connected() const noexcept
61 {
62   return !empty();
63 }
64
65 bool connection::blocked() const noexcept
66 {
67   return (slot_ ? slot_->blocked() : false);
68 }
69
70 bool connection::block(bool should_block) noexcept
71 {
72   return (slot_ ? slot_->block(should_block) : false);
73 }
74
75 bool connection::unblock() noexcept
76 {
77   return (slot_ ? slot_->unblock() : false);
78 }
79
80 void connection::disconnect()
81 {
82   if (slot_)
83     slot_->disconnect(); // This notifies slot_'s parent.
84
85
86 connection::operator bool() noexcept
87 {
88   return !empty();
89 }
90     
91 void connection::set_slot(slot_base* sl)
92 {
93   if (slot_)
94     slot_->remove_destroy_notify_callback(this);
95
96   slot_ = sl;
97
98   if (slot_)
99     slot_->add_destroy_notify_callback(this, &notify);
100 }
101
102 void* connection::notify(void* data)
103 {
104   auto self = reinterpret_cast<connection*>(data);
105   self->slot_ = nullptr;
106   return nullptr;
107 }
108
109 } /* namespace sigc */