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