struct NullCallback {};
18
19 // 0 parameter version
20
21 template<typename R>
22 class Callback<R ()>
23 {
24 public:
25 static const int Arity = 0;
26 typedef R ReturnType;
27
28 Callback() : func(0), obj(0) {}
29 Callback(NullCallback) : func(0), obj(0) {}
30 Callback(const Callback& rhs) : func(rhs.func), obj(rhs.obj) {}
31 ~Callback() {}
32
33 Callback& operator=(NullCallback)
34 { obj = 0; func = 0; return *this; }
35 Callback& operator=(const Callback& rhs)
36 { obj = rhs.obj; func = rhs.func; return *this; }
37
38 inline R operator()() const
39 {
40 return (*func)(obj);
41 }
42
43 private:
44 typedef const void* Callback::*SafeBoolType;//这句话怎么理解啊??
45 public:
46 inline operator SafeBoolType() const
47 { return func != 0 ? &Callback::obj : 0; }
48 inline bool operator!() const
49 { return func == 0; }
50
51 private:
52 typedef R (*FuncType)(const void*);
53 Callback(FuncType f, const void* o) : func(f), obj(o) {}
54
55 private:
56 FuncType func;
57 const void* obj;
58
59 template<typename FR>
60 friend class FreeCallbackFactory0;
61 template<typename FR, class FT>
62 friend class MemberCallbackFactory0;
63 template<typename FR, class FT>
64 friend class ConstMemberCallbackFactory0;
65 }; |