Midge  v3.9.2
Data Processing Framework
test_slot.cc
Go to the documentation of this file.
1 /*
2  * test_slot.cc
3  *
4  * Created on: Feb 6, 2019
5  * Author: N.S. Oblath
6  */
7 
8 #include "signal_slot.hh"
9 
10 #include <iostream>
11 
12 namespace midge
13 {
14  struct tester
15  {
16  void func( std::string arg1, int arg2 )
17  {
18  std::cout << "(member) " << arg1 << " " << arg2 << std::endl;
19  }
20 
21  void const_func( std::string arg1, int arg2 )
22  {
23  std::cout << "(const member) " << arg1 << " " << arg2 << std::endl;
24  }
25  };
26 }
27 
28 using namespace midge;
29 
30 int main()
31 {
32  // create new slots
33  m_slot< std::string, int > lambda( "", [](std::string arg1, int arg2) {
34  std::cout << "(lambda) " << arg1 << " " << arg2 << std::endl;
35  } );
36 
37  tester the_tester;
38  m_slot< std::string, int > member( "", &the_tester, &tester::func );
39 
40  m_slot< std::string, int > const_member( "", &the_tester, &tester::const_func );
41 
42  // create new signal
43  m_signal< std::string, int > the_signal( "" );
44 
45  // attach a slot
46  int lambda_conn = the_signal.connect( &lambda );
47  int member_conn = the_signal.connect( &member );
48  int const_member_conn = the_signal.connect( &const_member );
49 
50  std::cout << "All slots attached:" << std::endl;
51  the_signal.emit( "The answer:", 42 );
52 
53  std::cout << "Disconnecting the lambda slot using signal::disconnect()" << std::endl;
54  the_signal.disconnect( lambda_conn );
55  the_signal.emit( "The answer:", 43 );
56 
57  std::cout << "Disconnecting the member slot using slot::disconnect_all()" << std::endl;
58  member.disconnect_all();
59  the_signal.emit( "The answer:", 44 );
60 
61  std::cout << "Disconnecting remaining member slots using signal::disconnect_all()" << std::endl;
62  the_signal.disconnect_all();
63  the_signal.emit( "The answer:", 45 );
64 
65  return 0;
66 }
67 
68 
void disconnect_all() const
Definition: signal.hh:163
void disconnect_all()
Definition: signal_slot.hh:47
void disconnect(unsigned id) const
Definition: signal.hh:156
Definition: _buffer.hh:11
int main()
Definition: test_slot.cc:30
virtual unsigned connect(slot *p_slot)
Definition: signal_slot.hh:24
void const_func(std::string arg1, int arg2)
Definition: test_slot.cc:21
void emit(x_args... args)
Definition: signal.hh:170
void func(std::string arg1, int arg2)
Definition: test_slot.cc:16