-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblMemberFunctionWrapper.hpp
105 lines (60 loc) · 2.53 KB
/
blMemberFunctionWrapper.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef BL_MEMBERFUNCTIONWRAPPER_HPP
#define BL_MEMBERFUNCTIONWRAPPER_HPP
//-------------------------------------------------------------------
// FILE: blMemberFunctionWrapper.hpp
// CLASS: blMemberFunctionWrapper
// BASE CLASS: None
//
// PURPOSE: A functor that wraps an object's member function
// so that it can easily be invoked by our timer
//
// AUTHOR: Vincenzo Barbato
// http://www.barbatolabs.com
// navyenzo@gmail.com
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// NOTE: This class is defined within the blTimerAPI namespace
//-------------------------------------------------------------------
namespace blTimerAPI
{
//-------------------------------------------------------------------
//-------------------------------------------------------------------
template<typename blObjectType,
typename blReturnType,
typename...blFunctionArguments>
class blMemberFunctionWrapper
{
public: // Constructors and destructors
// Constructor
blMemberFunctionWrapper(blObjectType& object,
blReturnType (blObjectType::*method)(blFunctionArguments...))
: m_object(&object),
m_method(method)
{
}
// Copy constructor
blMemberFunctionWrapper(const blMemberFunctionWrapper<blObjectType,blReturnType,blFunctionArguments...>& event) = default;
// Destructor
~blMemberFunctionWrapper()
{
}
public: // Public functions
// Assignment operator
blMemberFunctionWrapper& operator=(const blMemberFunctionWrapper<blObjectType,blReturnType,blFunctionArguments...>& event) = default;
// operator() used to invoke the member function
// of the stored object
blReturnType operator()(const blFunctionArguments&... functionParameters)
{
return ( (m_object->*m_method)(functionParameters...) );
}
public: // Public variables
// The resource and its method
blObjectType* m_object;
blReturnType (blObjectType::*m_method)(blFunctionArguments...);
};
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// End of namespace
}
//-------------------------------------------------------------------
#endif // BL_MEMBERFUNCTIONWRAPPER_HPP