-
Notifications
You must be signed in to change notification settings - Fork 5
/
MemberFxn.h.bak
79 lines (61 loc) · 1.44 KB
/
MemberFxn.h.bak
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
/*
Copyright 2006 - 2008, All Rights Reserved.
这个类用来描述一个C++类成员函数地址
作者 - 张鲁夺(zhangluduo)
MSN - [email protected]
QQ群 - 34064264
为所有爱我的人和我爱的人努力!
*/
#ifndef _MEMBERFXN_H
#define _MEMBERFXN_H
#ifndef _UNION_CAST
#define _UNION_CAST
template <class ToType, class FromType>
ToType union_cast (FromType f)
{
union
{
FromType _f;
ToType _t;
} ut;
ut._f = f;
return ut._t;
}
#endif
class MemberFxn
{
private:
void* m_This; // the this pointer of class
unsigned long m_MemberFxnAddr; // member function address of class
public:
// construction
MemberFxn( );
MemberFxn( int n /* n must be zero */ );
template<typename T>
MemberFxn( void* This, T MemberFxnName )
{
SetAddr( This, MemberFxnName );
}
// destruction
~MemberFxn( );
// over load operator
MemberFxn& operator = ( MemberFxn addr );
bool operator == ( MemberFxn addr ) ;
bool IsNull ( );
void* GetThis ( );
unsigned long GetAddr ( );
/** set member function of a class, or a global function
void* This - a pointer of a object, if you will specify a global
function, you must set this parameter zero
T MemberFxnName - member function name of a class,
for example
&Class::MemberFunctionName or &GlobalFunctionName
*/
template<typename T>
void SetAddr( void* This, T MemberFxnName )
{
m_This = This;
m_MemberFxnAddr = union_cast<unsigned long>( MemberFxnName );
}
};
#endif