Chromium Code Reviews| 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 $$ See comment for MAX_ARITY in base/bind.h.pump. | 8 $$ See comment for MAX_ARITY in base/bind.h.pump. |
| 9 $var MAX_ARITY = 7 | 9 $var MAX_ARITY = 7 |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 // | 37 // |
| 38 // MEMORY MANAGEMENT AND PASSING | 38 // MEMORY MANAGEMENT AND PASSING |
| 39 // | 39 // |
| 40 // The Callback objects themselves should be passed by const-reference, and | 40 // The Callback objects themselves should be passed by const-reference, and |
| 41 // stored by copy. They internally store their state via a refcounted class | 41 // stored by copy. They internally store their state via a refcounted class |
| 42 // and thus do not need to be deleted. | 42 // and thus do not need to be deleted. |
| 43 // | 43 // |
| 44 // The reason to pass via a const-reference is to avoid unnecessary | 44 // The reason to pass via a const-reference is to avoid unnecessary |
| 45 // AddRef/Release pairs to the internal state. | 45 // AddRef/Release pairs to the internal state. |
| 46 // | 46 // |
| 47 // If a Callback variable must be empty during the Run() of a previous value of | |
|
akalin
2012/03/19 21:53:20
I couldn't parse this comment. Maybe something li
| |
| 48 // that variable, use ResetAndRun(). E.g. if MyClass has a member variable | |
| 49 // Callback which gets set as a side-effect of Run()'ing the Callback (to | |
| 50 // something else), ResetAndRun() can be handy. | |
| 47 // | 51 // |
| 48 // EXAMPLE USAGE: | 52 // EXAMPLE USAGE: |
| 49 // | 53 // |
| 50 // /* Binding a normal function. */ | 54 // /* Binding a normal function. */ |
| 51 // int Return5() { return 5; } | 55 // int Return5() { return 5; } |
| 52 // base::Callback<int(void)> func_cb = base::Bind(&Return5); | 56 // base::Callback<int(void)> func_cb = base::Bind(&Return5); |
| 53 // LOG(INFO) << func_cb.Run(); // Prints 5. | 57 // LOG(INFO) << func_cb.Run(); // Prints 5. |
| 54 // | 58 // |
| 55 // void PrintHi() { LOG(INFO) << "hi."; } | 59 // void PrintHi() { LOG(INFO) << "hi."; } |
| 56 // base::Closure void_func_cb = base::Bind(&PrintHi); | 60 // base::Closure void_func_cb = base::Bind(&PrintHi); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 [[typename internal::CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]] ) const { | 289 [[typename internal::CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]] ) const { |
| 286 PolymorphicInvoke f = | 290 PolymorphicInvoke f = |
| 287 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); | 291 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); |
| 288 | 292 |
| 289 return f(bind_state_.get()[[]] | 293 return f(bind_state_.get()[[]] |
| 290 $if ARITY != 0 [[, ]] | 294 $if ARITY != 0 [[, ]] |
| 291 $for ARG , | 295 $for ARG , |
| 292 [[internal::CallbackForward(a$(ARG))]]); | 296 [[internal::CallbackForward(a$(ARG))]]); |
| 293 } | 297 } |
| 294 | 298 |
| 299 | |
|
akalin
2012/03/19 21:53:20
remove extra space
| |
| 300 R ResetAndRun($for ARG , | |
| 301 [[typename internal::CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]] ) { | |
| 302 Callback<RunType> tmp(*this); | |
| 303 Reset(); | |
| 304 tmp.Run( | |
| 305 $for ARG , | |
| 306 [[internal::CallbackForward(a$(ARG))]]); | |
| 307 } | |
| 308 | |
| 295 private: | 309 private: |
| 296 typedef R(*PolymorphicInvoke)( | 310 typedef R(*PolymorphicInvoke)( |
| 297 internal::BindStateBase*[[]] | 311 internal::BindStateBase*[[]] |
| 298 $if ARITY != 0 [[, ]] | 312 $if ARITY != 0 [[, ]] |
| 299 $for ARG , [[typename internal::CallbackParamTraits<A$(ARG)>::ForwardType]]); | 313 $for ARG , [[typename internal::CallbackParamTraits<A$(ARG)>::ForwardType]]); |
| 300 | 314 |
| 301 }; | 315 }; |
| 302 | 316 |
| 303 | 317 |
| 304 ]] $$ for ARITY | 318 ]] $$ for ARITY |
| 305 | 319 |
| 306 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it | 320 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it |
| 307 // will be used in a lot of APIs with delayed execution. | 321 // will be used in a lot of APIs with delayed execution. |
| 308 typedef Callback<void(void)> Closure; | 322 typedef Callback<void(void)> Closure; |
| 309 | 323 |
| 310 } // namespace base | 324 } // namespace base |
| 311 | 325 |
| 312 #endif // BASE_CALLBACK_H | 326 #endif // BASE_CALLBACK_H |
| OLD | NEW |