Midge  v3.9.2
Data Processing Framework
slot.hh
Go to the documentation of this file.
1 /*
2  * slot.hh
3  *
4  * Created on: Feb 6, 2019
5  * Author: N.S. Oblath
6  */
7 
8 #ifndef MIDGE_UTILITY_SLOT_HH_
9 #define MIDGE_UTILITY_SLOT_HH_
10 
11 #include "types.hh"
12 
13 #include "member_variables.hh"
14 
15 #include <functional>
16 #include <set>
17 
18 namespace midge
19 {
20  template< typename... x_args >
21  class m_signal;
22 
23  class slot
24  {
25  public:
26  slot( const string_t& p_name );
27  template< typename x_owner >
28  slot( const string_t& p_name, x_owner* p_owner );
29  virtual ~slot();
30 
31  mv_referrable( string_t, name );
32  };
33 
34 
35  template< typename... x_args >
36  class m_slot : public slot
37  {
38  public:
39  using signature = void( x_args... );
40 
41  public:
42  m_slot( const string_t& name, const std::function< signature >& sig );
43  template< typename T >
44  m_slot( const string_t& name, T *inst, void (T::*func)( x_args... ) );
45  template< typename T >
46  m_slot( const string_t& name, T *inst, void (T::*func)( x_args... ) const );
47  template< typename x_owner >
48  m_slot( const string_t& name, const std::function< signature >& sig, x_owner* owner );
49  template< typename T, typename x_owner >
50  m_slot( const string_t& name, T *inst, void (T::*func)( x_args... ), x_owner* owner );
51  template< typename T, typename x_owner >
52  m_slot( const string_t& name, T *inst, void (T::*func)( x_args... ) const, x_owner* owner );
53  m_slot( const m_slot& ) = delete;
54  m_slot( m_slot&& ) = delete;
55  virtual ~m_slot();
56 
57  void disconnect_all();
58 
59  mv_referrable( std::function< signature >, function );
60 
61  typedef std::set< std::pair< unsigned, m_signal< x_args... >* > > signal_connections; // to get around the problem of having a comma inside a macro function argument
62  mv_referrable( signal_connections, connections );
63 
64  };
65 
66 
67  template< typename x_owner >
68  slot::slot( const string_t& p_name, x_owner* p_owner ) :
69  f_name( p_name )
70  {
71  if( p_owner ) p_owner->slot_ptr( this, p_name );
72  }
73 
74 
75  template< typename... x_args >
76  m_slot< x_args... >::m_slot( const string_t& name, const std::function< signature >& sig ) :
77  slot( name ),
78  f_function( sig )
79  {}
80 
81  template< typename... x_args >
82  template< typename T >
83  m_slot< x_args... >::m_slot( const string_t& name, T *inst, void (T::*func)( x_args... ) ) :
84  slot( name ),
85  f_function( [func, inst]( x_args... args ){ return (inst->*func)(args...);} )
86  {}
87 
88  template< typename... x_args >
89  template< typename T >
90  m_slot< x_args... >::m_slot( const string_t& name, T *inst, void (T::*func)( x_args... ) const ) :
91  slot( name ),
92  f_function( [func, inst]( x_args... args ){ return (inst->*func)(args...);} )
93  {}
94 
95  template< typename... x_args >
96  template< typename x_owner >
97  m_slot< x_args... >::m_slot( const string_t& name, const std::function< signature >& sig, x_owner* owner ) :
98  slot( name, owner ),
99  f_function( sig )
100  {}
101 
102  template< typename... x_args >
103  template< typename T, typename x_owner >
104  m_slot< x_args... >::m_slot( const string_t& name, T *inst, void (T::*func)( x_args... ), x_owner* owner ) :
105  slot( name, owner ),
106  f_function( [func, inst]( x_args... args ){ return (inst->*func)(args...);} )
107  {}
108 
109  template< typename... x_args >
110  template< typename T, typename x_owner >
111  m_slot< x_args... >::m_slot( const string_t& name, T *inst, void (T::*func)( x_args... ) const, x_owner* owner ) :
112  slot( name, owner ),
113  f_function( [func, inst]( x_args... args ){ return (inst->*func)(args...);} )
114  {}
115 
116  template< typename... x_args >
117  m_slot< x_args... >::~m_slot< x_args... >()
118  {
119  disconnect_all();
120  }
121 
122 } /* namespace midge */
123 
124 #endif /* MIDGE_UTILITY_SLOT_HH_ */
void disconnect_all()
Definition: signal_slot.hh:47
Definition: _buffer.hh:11
virtual ~m_slot()
Definition: slot.hh:117
std::string string_t
Definition: types.hh:21
void(x_args...) signature
Definition: slot.hh:39
std::set< std::pair< unsigned, m_signal< x_args... > *> > signal_connections
Definition: slot.hh:61
m_slot(const string_t &name, const std::function< signature > &sig)
Definition: slot.hh:76
virtual ~slot()
Definition: slot.cc:16
slot(const string_t &p_name)
Definition: slot.cc:12