Midge  v3.9.2
Data Processing Framework
signal_slot.hh
Go to the documentation of this file.
1 /*
2  * signal_slot_impl.hh
3  *
4  * Created on: Feb 9, 2019
5  * Author: N.S. Oblath
6  *
7  * This file includes implementation of the signal and slot member functions
8  * that depend on one another
9  */
10 
11 #ifndef MIDGE_SIGNAL_SLOT_IMPL_HH_
12 #define MIDGE_SIGNAL_SLOT_IMPL_HH_
13 
14 #include "signal.hh"
15 #include "slot.hh"
16 
17 namespace midge
18 {
19  //********************
20  // m_signal
21  //********************
22 
23  template< typename... x_args >
25  {
26  // ensure that the slot is of the correct type
27  m_slot< x_args... >* derived_slot = dynamic_cast< m_slot< x_args... >* >( p_slot );
28  if( p_slot == nullptr )
29  {
30  throw error() << "signal/slot signature mismatch: signal=" << f_name << "; slot=" << p_slot->name();
31  }
32 
33  // make the connection
34  int connection_id = connect_function( derived_slot->function() );
35 
36  // inform the slot of the signal connection so that it can disconnect
37  derived_slot->connections().insert( std::pair< int, m_signal< x_args... >* >( connection_id, this ) );
38 
39  return connection_id;
40  }
41 
42  //********************
43  // m_slot
44  //********************
45 
46  template< typename... x_args >
48  {
49  for( auto connection : f_connections )
50  {
51  connection.second->disconnect( connection.first );
52  }
53  return;
54  }
55 
56 
57 }
58 
59 #endif /* MIDGE_SIGNAL_SLOT_IMPL_HH_ */
void disconnect_all()
Definition: signal_slot.hh:47
Definition: _buffer.hh:11
virtual unsigned connect(slot *p_slot)
Definition: signal_slot.hh:24