OLD | NEW |
1 $$ This is a pump file for generating file templates. Pump is a python | 1 $$ This is a pump file for generating file templates. Pump is a python |
2 $$ script that is part of the Google Test suite of utilities. Description | 2 $$ script that is part of the Google Test suite of utilities. Description |
3 $$ can be found here: | 3 $$ can be found here: |
4 $$ | 4 $$ |
5 $$ http://code.google.com/p/googletest/wiki/PumpManual | 5 $$ http://code.google.com/p/googletest/wiki/PumpManual |
6 $$ | 6 $$ |
7 | 7 |
8 $var MAX_ARITY = 6 | 8 $var MAX_ARITY = 6 |
9 | 9 |
10 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 10 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 // First, we forward declare the Callback class template. This informs the | 219 // First, we forward declare the Callback class template. This informs the |
220 // compiler that the template only has 1 type parameter which is the function | 220 // compiler that the template only has 1 type parameter which is the function |
221 // signature that the Callback is representing. | 221 // signature that the Callback is representing. |
222 // | 222 // |
223 // After this, create template specializations for 0-$(MAX_ARITY) parameters. No
te that | 223 // After this, create template specializations for 0-$(MAX_ARITY) parameters. No
te that |
224 // even though the template typelist grows, the specialization still | 224 // even though the template typelist grows, the specialization still |
225 // only has one type: the function signature. | 225 // only has one type: the function signature. |
226 template <typename Sig> | 226 template <typename Sig> |
227 class Callback; | 227 class Callback; |
228 | 228 |
| 229 |
229 $range ARITY 0..MAX_ARITY | 230 $range ARITY 0..MAX_ARITY |
230 $for ARITY [[ | 231 $for ARITY [[ |
231 $range ARG 1..ARITY | 232 $range ARG 1..ARITY |
232 | 233 |
233 $if ARITY == 0 [[ | 234 $if ARITY == 0 [[ |
234 template <typename R> | 235 template <typename R> |
235 class Callback<R(void)> : public internal::CallbackBase { | 236 class Callback<R(void)> : public internal::CallbackBase { |
236 ]] $else [[ | 237 ]] $else [[ |
237 template <typename R, $for ARG , [[typename A$(ARG)]]> | 238 template <typename R, $for ARG , [[typename A$(ARG)]]> |
238 class Callback<R($for ARG , [[A$(ARG)]])> : public internal::CallbackBase { | 239 class Callback<R($for ARG , [[A$(ARG)]])> : public internal::CallbackBase { |
(...skipping 10 matching lines...) Expand all Loading... |
249 // We pass InvokerStorageHolder by const ref to avoid incurring an | 250 // We pass InvokerStorageHolder by const ref to avoid incurring an |
250 // unnecessary AddRef/Unref pair even though we will modify the object. | 251 // unnecessary AddRef/Unref pair even though we will modify the object. |
251 // We cannot use a normal reference because the compiler will warn | 252 // We cannot use a normal reference because the compiler will warn |
252 // since this is often used on a return value, which is a temporary. | 253 // since this is often used on a return value, which is a temporary. |
253 // | 254 // |
254 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 255 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
255 // return the exact Callback<> type. See base/bind.h for details. | 256 // return the exact Callback<> type. See base/bind.h for details. |
256 template <typename T> | 257 template <typename T> |
257 Callback(const internal::InvokerStorageHolder<T>& invoker_holder) | 258 Callback(const internal::InvokerStorageHolder<T>& invoker_holder) |
258 : CallbackBase( | 259 : CallbackBase( |
259 reinterpret_cast<InvokeFuncStorage>(&T::FunctionTraits::DoInvoke), | 260 reinterpret_cast<InvokeFuncStorage>(&T::Invoker::DoInvoke), |
260 &invoker_holder.invoker_storage_) { | 261 &invoker_holder.invoker_storage_) { |
261 } | 262 } |
262 | 263 |
263 R Run($for ARG , | 264 R Run($for ARG , |
264 [[const A$(ARG)& a$(ARG)]]) const { | 265 [[const A$(ARG)& a$(ARG)]]) const { |
265 PolymorphicInvoke f = | 266 PolymorphicInvoke f = |
266 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); | 267 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); |
267 | 268 |
268 return f(invoker_storage_.get()[[]] | 269 return f(invoker_storage_.get()[[]] |
269 $if ARITY != 0 [[, ]] | 270 $if ARITY != 0 [[, ]] |
270 $for ARG , | 271 $for ARG , |
271 [[a$(ARG)]]); | 272 [[a$(ARG)]]); |
272 } | 273 } |
273 }; | 274 }; |
274 | 275 |
275 | 276 |
276 ]] $$ for ARITY | 277 ]] $$ for ARITY |
277 | 278 |
278 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it | 279 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it |
279 // will be used in a lot of APIs with delayed execution. | 280 // will be used in a lot of APIs with delayed execution. |
280 typedef Callback<void(void)> Closure; | 281 typedef Callback<void(void)> Closure; |
281 | 282 |
282 } // namespace base | 283 } // namespace base |
283 | 284 |
284 #endif // BASE_CALLBACK_H | 285 #endif // BASE_CALLBACK_H |
OLD | NEW |