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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 233 |
234 $if ARITY == 0 [[ | 234 $if ARITY == 0 [[ |
235 template <typename R> | 235 template <typename R> |
236 class Callback<R(void)> : public internal::CallbackBase { | 236 class Callback<R(void)> : public internal::CallbackBase { |
237 ]] $else [[ | 237 ]] $else [[ |
238 template <typename R, $for ARG , [[typename A$(ARG)]]> | 238 template <typename R, $for ARG , [[typename A$(ARG)]]> |
239 class Callback<R($for ARG , [[A$(ARG)]])> : public internal::CallbackBase { | 239 class Callback<R($for ARG , [[A$(ARG)]])> : public internal::CallbackBase { |
240 ]] | 240 ]] |
241 | 241 |
242 public: | 242 public: |
243 typedef R(*PolymorphicInvoke)(internal::InvokerStorageBase*[[]] | 243 typedef R(*PolymorphicInvoke)( |
| 244 internal::InvokerStorageBase*[[]] |
244 $if ARITY != 0 [[, ]] | 245 $if ARITY != 0 [[, ]] |
245 $for ARG , | 246 $for ARG , [[typename internal::ParamTraits<A$(ARG)>::ForwardType]]); |
246 [[const A$(ARG)&]]); | |
247 | 247 |
248 Callback() : CallbackBase(NULL, NULL) { } | 248 Callback() : CallbackBase(NULL, NULL) { } |
249 | 249 |
250 // We pass InvokerStorageHolder by const ref to avoid incurring an | 250 // We pass InvokerStorageHolder by const ref to avoid incurring an |
251 // unnecessary AddRef/Unref pair even though we will modify the object. | 251 // unnecessary AddRef/Unref pair even though we will modify the object. |
252 // We cannot use a normal reference because the compiler will warn | 252 // We cannot use a normal reference because the compiler will warn |
253 // 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. |
254 // | 254 // |
255 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 255 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
256 // return the exact Callback<> type. See base/bind.h for details. | 256 // return the exact Callback<> type. See base/bind.h for details. |
257 template <typename T> | 257 template <typename T> |
258 Callback(const internal::InvokerStorageHolder<T>& invoker_holder) | 258 Callback(const internal::InvokerStorageHolder<T>& invoker_holder) |
259 : CallbackBase( | 259 : CallbackBase( |
260 reinterpret_cast<InvokeFuncStorage>(&T::Invoker::DoInvoke), | 260 reinterpret_cast<InvokeFuncStorage>(&T::Invoker::DoInvoke), |
261 &invoker_holder.invoker_storage_) { | 261 &invoker_holder.invoker_storage_) { |
262 } | 262 } |
263 | 263 |
264 R Run($for ARG , | 264 R Run($for ARG , |
265 [[const A$(ARG)& a$(ARG)]]) const { | 265 [[typename internal::ParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) const
{ |
266 PolymorphicInvoke f = | 266 PolymorphicInvoke f = |
267 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); | 267 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); |
268 | 268 |
269 return f(invoker_storage_.get()[[]] | 269 return f(invoker_storage_.get()[[]] |
270 $if ARITY != 0 [[, ]] | 270 $if ARITY != 0 [[, ]] |
271 $for ARG , | 271 $for ARG , |
272 [[a$(ARG)]]); | 272 [[a$(ARG)]]); |
273 } | 273 } |
274 }; | 274 }; |
275 | 275 |
276 | 276 |
277 ]] $$ for ARITY | 277 ]] $$ for ARITY |
278 | 278 |
279 // 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 |
280 // will be used in a lot of APIs with delayed execution. | 280 // will be used in a lot of APIs with delayed execution. |
281 typedef Callback<void(void)> Closure; | 281 typedef Callback<void(void)> Closure; |
282 | 282 |
283 } // namespace base | 283 } // namespace base |
284 | 284 |
285 #endif // BASE_CALLBACK_H | 285 #endif // BASE_CALLBACK_H |
OLD | NEW |