-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallback.h
More file actions
75 lines (64 loc) · 2.32 KB
/
Callback.h
File metadata and controls
75 lines (64 loc) · 2.32 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
// * ************************************************************************ //
// * * Callback header * * //
// * * : defines template functor and adaptor for producing callback * * //
// * * objects * * //
// * * * * //
// * * Disclaimer: This document represents no significant intellectual * * //
// * * property and my be used freely. The author(s) takes no * * //
// * * responsibility for any loss or damage arising from the use of * * //
// * * the computer code contained herein. Where this document is * * //
// * * submitted as part of an assessment task this header must remain * * //
// * * intact and the student must make clear indication which parts * * //
// * * have been added by themselves. * * //
// * * * * //
// * ********************************************************************** * //
// * ********************************************************************** * //
// * * Callback.h * * //
// * * Author: Tim Wilkin * * //
// * * Created: 26/03/11 Last Modified: 14/07/11 * * //
// * ********************************************************************** * //
#ifndef CALLBACK_H
#define CALLBACK_H
template <
typename A,
typename R
>
class BFunctor1
{
public:
virtual R operator()(A) = 0;
};
template <
typename A,
typename R
>
class Functor1 : public BFunctor1<A, R>
{
public:
typedef R(*_func)(A);
Functor1(_func _f) : fpFunc(_f) {}
R operator()(A a) { return (*fpFunc)(a); }
private:
_func fpFunc;
};
template <
typename T,
typename A,
typename R
>
class Adaptor1 : public BFunctor1<A, R>
{
public:
#ifdef _WIN32
typedef typename T _type;
#else
typedef T _type;
#endif
typedef R(_type::*_memfunc)(A);
Adaptor1(_type * _obj, _memfunc _fnc) : pObj(_obj), fpFunc(_fnc) {}
R operator()(A a) { return (pObj->*fpFunc)(a); }
private:
_type *pObj;
_memfunc fpFunc;
};
#endif // CALLBACK_H