-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelegate.cpp
More file actions
116 lines (104 loc) · 2.58 KB
/
Copy pathdelegate.cpp
File metadata and controls
116 lines (104 loc) · 2.58 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
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
106
107
108
109
110
111
112
113
114
115
116
#include <cstdio>
#include <typeinfo>
#include <iostream>
#include <cxxabi.h>
struct A
{
int a;
};
struct B
{
B(): a(123){}
int a;
void f(int i, double d)
{
std::cout<<"B::f() "<<i<<" "<<a<<" "<<d<<std::endl;
}
void f1(){}
};
struct C : A, B
{
int d;
};
void demangle(const char *name)
{
char buf[256];
size_t len = sizeof(buf);
abi::__cxa_demangle(name, buf, &len, 0);
std::cout<<buf<<std::endl;
}
// c++11
//
//template <typename... P>
//struct ObjPtr
//{
// template <typename T, typename M>
// void bind(T *obj, void (M::*m)(P...))
// {
// this->obj = reinterpret_cast<ObjPtr*>(static_cast<M*>(obj));
// meth = reinterpret_cast<void (ObjPtr::*)(P...)>(m);
// }
// void operator()(P... p)
// {
// (obj->*meth)(p...);
// }
// ObjPtr *obj;
// void (ObjPtr::*meth)(P...);
//};
template <typename P1 = char, typename P2 = char, typename P3 = char, typename P4 = char >
struct ObjPtr
{
template <typename T, typename M>
void bind(T *obj, void (M::*m)())
{
this->obj = reinterpret_cast<ObjPtr*>(static_cast<M*>(obj));
meth = reinterpret_cast<void (ObjPtr::*)(P1,P2,P3,P4)>(m);
}
template <typename T, typename M>
void bind(T *obj, void (M::*m)(P1))
{
this->obj = reinterpret_cast<ObjPtr*>(static_cast<M*>(obj));
meth = reinterpret_cast<void (ObjPtr::*)(P1,P2,P3,P4)>(m);
}
template <typename T, typename M>
void bind(T *obj, void (M::*m)(P1,P2))
{
this->obj = reinterpret_cast<ObjPtr*>(static_cast<M*>(obj));
meth = reinterpret_cast<void (ObjPtr::*)(P1,P2,P3,P4)>(m);
}
template <typename T, typename M>
void bind(T *obj, void (M::*m)(P1,P2,P3))
{
this->obj = reinterpret_cast<ObjPtr*>(static_cast<M*>(obj));
meth = reinterpret_cast<void (ObjPtr::*)(P1,P2,P3,P4)>(m);
}
template <typename T, typename M>
void bind(T *obj, void (M::*m)(P1,P2,P3,P4))
{
this->obj = reinterpret_cast<ObjPtr*>(static_cast<M*>(obj));
meth = reinterpret_cast<void (ObjPtr::*)(P1,P2,P3,P4)>(m);
}
void operator()(P1 p1 = 0, P2 p2 = 0, P3 p3 = 0, P4 p4 = 0)
{
(obj->*meth)(p1, p2, p3, p4);
}
ObjPtr *obj;
void (ObjPtr::*meth)(P1,P2,P3,P4);
};
// method qualifier syntax
// address of methods can be obtained only &T::method
//
// method syntax, method pointer syntax T::method T::*method
// void T::(), void (T::*)()
// Test:
//{
// C c;
// ObjPtr<int, double> p, d;
// p.bind(&c, &C::f);
// p(5);
//
// d = p;
//
// d(8, 2.3);
// return 0;
//}