Goby v2
connect.h
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Goby Underwater Autonomy Project Libraries
8 // ("The Goby Libraries").
9 //
10 // The Goby Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Goby Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
22 
23 // gives functions for connecting the slots and signals of the goby-acomms libraries together
24 
25 #ifndef CONNECT20110121H
26 #define CONNECT20110121H
27 
28 #include <boost/bind.hpp>
29 #include <boost/signals2.hpp>
30 
31 namespace goby
32 {
33 namespace acomms
34 {
36 template <typename Signal, typename Slot> void connect(Signal* signal, Slot slot)
37 {
38  signal->connect(slot);
39 }
40 
42 template <typename Signal, typename Obj, typename A1>
43 void connect(Signal* signal, Obj* obj, void (Obj::*mem_func)(A1))
44 {
45  connect(signal, boost::bind(mem_func, obj, _1));
46 }
47 
49 template <typename Signal, typename Obj, typename A1, typename A2>
50 void connect(Signal* signal, Obj* obj, void (Obj::*mem_func)(A1, A2))
51 {
52  connect(signal, boost::bind(mem_func, obj, _1, _2));
53 }
54 
56 template <typename Signal, typename Obj, typename A1, typename A2, typename A3>
57 void connect(Signal* signal, Obj* obj, void (Obj::*mem_func)(A1, A2, A3))
58 {
59  connect(signal, boost::bind(mem_func, obj, _1, _2, _3));
60 }
61 
63 template <typename Signal, typename Slot> void disconnect(Signal* signal, Slot slot)
64 {
65  signal->disconnect(slot);
66 }
67 
69 template <typename Signal, typename Obj, typename A1>
70 void disconnect(Signal* signal, Obj* obj, void (Obj::*mem_func)(A1))
71 {
72  disconnect(signal, boost::bind(mem_func, obj, _1));
73 }
74 
76 template <typename Signal, typename Obj, typename A1, typename A2>
77 void disconnect(Signal* signal, Obj* obj, void (Obj::*mem_func)(A1, A2))
78 {
79  disconnect(signal, boost::bind(mem_func, obj, _1, _2));
80 }
81 
83 template <typename Signal, typename Obj, typename A1, typename A2, typename A3>
84 void disconnect(Signal* signal, Obj* obj, void (Obj::*mem_func)(A1, A2, A3))
85 {
86  disconnect(signal, boost::bind(mem_func, obj, _1, _2, _3));
87 }
88 
89 } // namespace acomms
90 } // namespace goby
91 
92 #endif
void connect(Signal *signal, Slot slot)
connect a signal to a slot (e.g. function pointer)
Definition: connect.h:36
The global namespace for the Goby project.
void disconnect(Signal *signal, Slot slot)
disconnect a signal to a slot (e.g. function pointer)
Definition: connect.h:63