OLD | NEW |
1 // This file was GENERATED by command: | 1 // This file was GENERATED by command: |
2 // pump.py callback.h.pump | 2 // pump.py callback.h.pump |
3 // DO NOT EDIT BY HAND!!! | 3 // DO NOT EDIT BY HAND!!! |
4 | 4 |
5 /* | 5 /* |
6 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 6 * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
7 * | 7 * |
8 * Use of this source code is governed by a BSD-style license | 8 * Use of this source code is governed by a BSD-style license |
9 * that can be found in the LICENSE file in the root of the source | 9 * that can be found in the LICENSE file in the root of the source |
10 * tree. An additional intellectual property rights grant can be found | 10 * tree. An additional intellectual property rights grant can be found |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // | 55 // |
56 // my_callback = Callback1<int, int>(add_k); | 56 // my_callback = Callback1<int, int>(add_k); |
57 // cout << my_callback(10) << endl; // 15 | 57 // cout << my_callback(10) << endl; // 15 |
58 // | 58 // |
59 // my_callback = Callback1<int, int>(); | 59 // my_callback = Callback1<int, int>(); |
60 // cout << my_callback.empty() << endl; // true | 60 // cout << my_callback.empty() << endl; // true |
61 | 61 |
62 #ifndef WEBRTC_BASE_CALLBACK_H_ | 62 #ifndef WEBRTC_BASE_CALLBACK_H_ |
63 #define WEBRTC_BASE_CALLBACK_H_ | 63 #define WEBRTC_BASE_CALLBACK_H_ |
64 | 64 |
65 #include "webrtc/base/refcount.h" | |
66 #include "webrtc/base/scoped_ref_ptr.h" | |
67 | 65 |
68 namespace rtc { | 66 // This header is deprecated and is just left here temporarily during |
69 | 67 // refactoring. See https://bugs.webrtc.org/7634 for more details. |
70 template <class R> | 68 #include "webrtc/rtc_base/callback.h" |
71 class Callback0 { | |
72 public: | |
73 // Default copy operations are appropriate for this class. | |
74 Callback0() {} | |
75 template <class T> Callback0(const T& functor) | |
76 : helper_(new RefCountedObject< HelperImpl<T> >(functor)) {} | |
77 R operator()() { | |
78 if (empty()) | |
79 return R(); | |
80 return helper_->Run(); | |
81 } | |
82 bool empty() const { return !helper_; } | |
83 | |
84 private: | |
85 struct Helper : RefCountInterface { | |
86 virtual ~Helper() {} | |
87 virtual R Run() = 0; | |
88 }; | |
89 template <class T> struct HelperImpl : Helper { | |
90 explicit HelperImpl(const T& functor) : functor_(functor) {} | |
91 virtual R Run() { | |
92 return functor_(); | |
93 } | |
94 T functor_; | |
95 }; | |
96 scoped_refptr<Helper> helper_; | |
97 }; | |
98 | |
99 template <class R, | |
100 class P1> | |
101 class Callback1 { | |
102 public: | |
103 // Default copy operations are appropriate for this class. | |
104 Callback1() {} | |
105 template <class T> Callback1(const T& functor) | |
106 : helper_(new RefCountedObject< HelperImpl<T> >(functor)) {} | |
107 R operator()(P1 p1) { | |
108 if (empty()) | |
109 return R(); | |
110 return helper_->Run(p1); | |
111 } | |
112 bool empty() const { return !helper_; } | |
113 | |
114 private: | |
115 struct Helper : RefCountInterface { | |
116 virtual ~Helper() {} | |
117 virtual R Run(P1 p1) = 0; | |
118 }; | |
119 template <class T> struct HelperImpl : Helper { | |
120 explicit HelperImpl(const T& functor) : functor_(functor) {} | |
121 virtual R Run(P1 p1) { | |
122 return functor_(p1); | |
123 } | |
124 T functor_; | |
125 }; | |
126 scoped_refptr<Helper> helper_; | |
127 }; | |
128 | |
129 template <class R, | |
130 class P1, | |
131 class P2> | |
132 class Callback2 { | |
133 public: | |
134 // Default copy operations are appropriate for this class. | |
135 Callback2() {} | |
136 template <class T> Callback2(const T& functor) | |
137 : helper_(new RefCountedObject< HelperImpl<T> >(functor)) {} | |
138 R operator()(P1 p1, P2 p2) { | |
139 if (empty()) | |
140 return R(); | |
141 return helper_->Run(p1, p2); | |
142 } | |
143 bool empty() const { return !helper_; } | |
144 | |
145 private: | |
146 struct Helper : RefCountInterface { | |
147 virtual ~Helper() {} | |
148 virtual R Run(P1 p1, P2 p2) = 0; | |
149 }; | |
150 template <class T> struct HelperImpl : Helper { | |
151 explicit HelperImpl(const T& functor) : functor_(functor) {} | |
152 virtual R Run(P1 p1, P2 p2) { | |
153 return functor_(p1, p2); | |
154 } | |
155 T functor_; | |
156 }; | |
157 scoped_refptr<Helper> helper_; | |
158 }; | |
159 | |
160 template <class R, | |
161 class P1, | |
162 class P2, | |
163 class P3> | |
164 class Callback3 { | |
165 public: | |
166 // Default copy operations are appropriate for this class. | |
167 Callback3() {} | |
168 template <class T> Callback3(const T& functor) | |
169 : helper_(new RefCountedObject< HelperImpl<T> >(functor)) {} | |
170 R operator()(P1 p1, P2 p2, P3 p3) { | |
171 if (empty()) | |
172 return R(); | |
173 return helper_->Run(p1, p2, p3); | |
174 } | |
175 bool empty() const { return !helper_; } | |
176 | |
177 private: | |
178 struct Helper : RefCountInterface { | |
179 virtual ~Helper() {} | |
180 virtual R Run(P1 p1, P2 p2, P3 p3) = 0; | |
181 }; | |
182 template <class T> struct HelperImpl : Helper { | |
183 explicit HelperImpl(const T& functor) : functor_(functor) {} | |
184 virtual R Run(P1 p1, P2 p2, P3 p3) { | |
185 return functor_(p1, p2, p3); | |
186 } | |
187 T functor_; | |
188 }; | |
189 scoped_refptr<Helper> helper_; | |
190 }; | |
191 | |
192 template <class R, | |
193 class P1, | |
194 class P2, | |
195 class P3, | |
196 class P4> | |
197 class Callback4 { | |
198 public: | |
199 // Default copy operations are appropriate for this class. | |
200 Callback4() {} | |
201 template <class T> Callback4(const T& functor) | |
202 : helper_(new RefCountedObject< HelperImpl<T> >(functor)) {} | |
203 R operator()(P1 p1, P2 p2, P3 p3, P4 p4) { | |
204 if (empty()) | |
205 return R(); | |
206 return helper_->Run(p1, p2, p3, p4); | |
207 } | |
208 bool empty() const { return !helper_; } | |
209 | |
210 private: | |
211 struct Helper : RefCountInterface { | |
212 virtual ~Helper() {} | |
213 virtual R Run(P1 p1, P2 p2, P3 p3, P4 p4) = 0; | |
214 }; | |
215 template <class T> struct HelperImpl : Helper { | |
216 explicit HelperImpl(const T& functor) : functor_(functor) {} | |
217 virtual R Run(P1 p1, P2 p2, P3 p3, P4 p4) { | |
218 return functor_(p1, p2, p3, p4); | |
219 } | |
220 T functor_; | |
221 }; | |
222 scoped_refptr<Helper> helper_; | |
223 }; | |
224 | |
225 template <class R, | |
226 class P1, | |
227 class P2, | |
228 class P3, | |
229 class P4, | |
230 class P5> | |
231 class Callback5 { | |
232 public: | |
233 // Default copy operations are appropriate for this class. | |
234 Callback5() {} | |
235 template <class T> Callback5(const T& functor) | |
236 : helper_(new RefCountedObject< HelperImpl<T> >(functor)) {} | |
237 R operator()(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { | |
238 if (empty()) | |
239 return R(); | |
240 return helper_->Run(p1, p2, p3, p4, p5); | |
241 } | |
242 bool empty() const { return !helper_; } | |
243 | |
244 private: | |
245 struct Helper : RefCountInterface { | |
246 virtual ~Helper() {} | |
247 virtual R Run(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) = 0; | |
248 }; | |
249 template <class T> struct HelperImpl : Helper { | |
250 explicit HelperImpl(const T& functor) : functor_(functor) {} | |
251 virtual R Run(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) { | |
252 return functor_(p1, p2, p3, p4, p5); | |
253 } | |
254 T functor_; | |
255 }; | |
256 scoped_refptr<Helper> helper_; | |
257 }; | |
258 } // namespace rtc | |
259 | 69 |
260 #endif // WEBRTC_BASE_CALLBACK_H_ | 70 #endif // WEBRTC_BASE_CALLBACK_H_ |
OLD | NEW |