-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweenCallback.h
More file actions
executable file
·66 lines (50 loc) · 1.63 KB
/
TweenCallback.h
File metadata and controls
executable file
·66 lines (50 loc) · 1.63 KB
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
// Copyright 2006-12 HumaNature Studios Inc.
#ifndef __TWEENCALLBACK_H__
#define __TWEENCALLBACK_H__
namespace core {
// template-less base class, so different types can be stored/called
class TweenCallback
{
public:
TweenCallback();
virtual ~TweenCallback() = 0;
virtual void operator()() = 0;
protected:
void* mObjectAddress;
friend class Tween;
};
// template version of callback class, allows for quick binding of member functions
template <class CallbackClass>
class TweenCallbackTemplate
: public TweenCallback
{
public:
TweenCallbackTemplate()
: mObject(nullptr)
, mMemberFunction(nullptr)
{
}
// set the callback to a member function of a supplied object
void set(CallbackClass *object, void (CallbackClass::*memberFunction)())
{
mObjectAddress = object;
mObject = object;
mMemberFunction = memberFunction;
}
// call the function
virtual void operator()()
{
if(mMemberFunction) {
(*mObject.*mMemberFunction)();
}
}
protected:
// pointer to the object on which to call the member function
CallbackClass* mObject;
// pointer to the member function
void (CallbackClass::*mMemberFunction)();
// hide assignment
TweenCallbackTemplate& operator=(TweenCallbackTemplate&);
};
} // namespace core
#endif // __TWEENCALLBACK_H__