include
ecl
sigslots_lite
slot.hpp
Go to the documentation of this file.
1
8
/*****************************************************************************
9
** Ifdefs
10
*****************************************************************************/
11
12
#ifndef ECL_SIGSLOTS_LITE_SLOT_HPP_
13
#define ECL_SIGSLOTS_LITE_SLOT_HPP_
14
15
/*****************************************************************************
16
** Includes
17
*****************************************************************************/
18
19
#include <cstddef>
// defines NULL
20
21
/*****************************************************************************
22
** Namespaces
23
*****************************************************************************/
24
25
namespace
ecl
{
26
namespace
lite {
27
28
/*****************************************************************************
29
** Slots
30
*****************************************************************************/
31
32
namespace
sigslots {
40
template
<
typename
Data>
41
class
SlotBase {
42
public
:
43
virtual
void
execute
(Data data) = 0;
44
};
51
template
<
typename
Data,
typename
FunctionClass>
52
class
MemberSlot :
public
SlotBase<Data> {
53
public
:
54
MemberSlot
() {}
55
MemberSlot
(
void
(FunctionClass::*func)(Data), FunctionClass &instance) :
56
object
(&instance),
57
member_function
(func)
58
{}
59
60
void
execute
(Data data) {
61
(*
object
.*
member_function
)(data);
62
}
63
FunctionClass *
object
;
64
void (FunctionClass::*
member_function
)(Data);
65
private
:
66
};
67
68
74
template
<
typename
Data>
75
class
GlobalSlot
:
public
SlotBase
<Data> {
76
public
:
77
GlobalSlot
() :
global_function
(NULL) {}
78
GlobalSlot
(
void
(*func)(Data)) :
global_function
(func) {}
79
80
void
execute
(Data data) {
81
if
(
global_function
!= NULL ) {
82
(*global_function)(data);
83
}
84
}
85
void (*
global_function
)(Data);
86
};
87
88
/*****************************************************************************
89
** Slot Specialisations
90
*****************************************************************************/
91
97
template
<>
98
class
SlotBase
<void> {
99
public
:
100
virtual
void
execute
() = 0;
101
};
102
109
template
<
typename
FunctionClass>
110
class
MemberSlot
<void,FunctionClass> :
public
SlotBase
<void> {
111
public
:
112
MemberSlot
() {}
113
MemberSlot
(
void
(FunctionClass::*func)(
void
), FunctionClass &instance) :
114
object
(&instance),
115
member_function
(func)
116
{}
117
118
void
execute
() {
119
(*
object
.*
member_function
)();
120
}
121
FunctionClass *
object
;
122
void (FunctionClass::*
member_function
)(void);
123
private
:
124
};
125
131
template
<>
132
class
GlobalSlot
<void> :
public
SlotBase
<void> {
133
public
:
134
GlobalSlot
() :
global_function
(NULL) {}
135
GlobalSlot
(
void
(*func)(
void
)) :
global_function
(func) {}
136
137
void
execute
() {
138
if
(
global_function
!= NULL ) {
139
(*global_function)();
140
}
141
}
142
void (*
global_function
)(void);
143
};
144
145
}
// namespace sigslots
146
}
// namespace lite
147
}
// namespace ecl
148
149
#endif
/* ECL_SIGSLOTS_LITE_SLOT_HPP_ */
ecl::lite::sigslots::GlobalSlot
A slot with global/static callback function.
Definition:
slot.hpp:95
ecl::lite::sigslots::MemberSlot::execute
void execute(Data data)
Definition:
slot.hpp:80
ecl::lite::sigslots::SlotBase::execute
virtual void execute(Data data)=0
ecl::lite::sigslots::GlobalSlot::execute
void execute(Data data)
Definition:
slot.hpp:100
ecl::lite::sigslots::MemberSlot::MemberSlot
MemberSlot()
Definition:
slot.hpp:74
ecl::lite::sigslots::SlotBase
Parent slot class with the common, publicly exposed interface.
Definition:
slot.hpp:61
ecl::lite::sigslots::MemberSlot::object
FunctionClass * object
Definition:
slot.hpp:83
ecl::lite::sigslots::MemberSlot::member_function
void(FunctionClass::* member_function)(Data)
Definition:
slot.hpp:84
ecl::lite::sigslots::GlobalSlot::global_function
void(* global_function)(Data)
Slotted function.
Definition:
slot.hpp:105
ecl::lite::sigslots::GlobalSlot::GlobalSlot
GlobalSlot()
Definition:
slot.hpp:97
ecl
ecl::lite::sigslots::MemberSlot
A slot with member callback function.
Definition:
slot.hpp:72
ecl_sigslots_lite
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:13:56