| 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 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 // NOTE: Header files that do not require the full definition of Callback or | 22 // NOTE: Header files that do not require the full definition of Callback or |
| 23 // Closure should #include "base/callback_forward.h" instead of this file. | 23 // Closure should #include "base/callback_forward.h" instead of this file. |
| 24 | 24 |
| 25 // ----------------------------------------------------------------------------- | 25 // ----------------------------------------------------------------------------- |
| 26 // Introduction | 26 // Introduction |
| 27 // ----------------------------------------------------------------------------- | 27 // ----------------------------------------------------------------------------- |
| 28 // | 28 // |
| 29 // The templated Callback class is a generalized function object. Together | 29 // The templated Callback class is a generalized function object. Together |
| 30 // with the Bind() function in bind.h, they provide a type-safe method for | 30 // with the Bind() function in bind.h, they provide a type-safe method for |
| 31 // performing currying of arguments, and creating a "closure." | 31 // performing partial application of functions. |
| 32 // | 32 // |
| 33 // In programming languages, a closure is a first-class function where all its | 33 // Partial application (or "currying") is the process of binding a subset of |
| 34 // parameters have been bound (usually via currying). Closures are well | 34 // a function's arguments to produce another function that takes fewer |
| 35 // suited for representing, and passing around a unit of delayed execution. | 35 // arguments. This can be used to pass around a unit of delayed execution, |
| 36 // They are used in Chromium code to schedule tasks on different MessageLoops. | 36 // much like lexical closures are used in other languages. For example, it |
| 37 // is used in Chromium code to schedule tasks on different MessageLoops. |
| 37 // | 38 // |
| 39 // A callback with no unbound input parameters (base::Callback<void(void)>) |
| 40 // is called a base::Closure. Note that this is NOT the same as what other |
| 41 // languages refer to as a closure -- it does not retain a reference to its |
| 42 // enclosing environment. |
| 38 // | 43 // |
| 39 // MEMORY MANAGEMENT AND PASSING | 44 // MEMORY MANAGEMENT AND PASSING |
| 40 // | 45 // |
| 41 // The Callback objects themselves should be passed by const-reference, and | 46 // The Callback objects themselves should be passed by const-reference, and |
| 42 // stored by copy. They internally store their state via a refcounted class | 47 // stored by copy. They internally store their state via a refcounted class |
| 43 // and thus do not need to be deleted. | 48 // and thus do not need to be deleted. |
| 44 // | 49 // |
| 45 // The reason to pass via a const-reference is to avoid unnecessary | 50 // The reason to pass via a const-reference is to avoid unnecessary |
| 46 // AddRef/Release pairs to the internal state. | 51 // AddRef/Release pairs to the internal state. |
| 47 // | 52 // |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // - Performing compile-time asserts to avoid error-prone behavior | 272 // - Performing compile-time asserts to avoid error-prone behavior |
| 268 // - Returning an Callback<> with an arity matching the number of unbound | 273 // - Returning an Callback<> with an arity matching the number of unbound |
| 269 // parameters and that knows the correct refcounting semantics for the | 274 // parameters and that knows the correct refcounting semantics for the |
| 270 // target object if we are binding a method. | 275 // target object if we are binding a method. |
| 271 // | 276 // |
| 272 // The Bind functions do the above using type-inference, and template | 277 // The Bind functions do the above using type-inference, and template |
| 273 // specializations. | 278 // specializations. |
| 274 // | 279 // |
| 275 // By default Bind() will store copies of all bound parameters, and attempt | 280 // By default Bind() will store copies of all bound parameters, and attempt |
| 276 // to refcount a target object if the function being bound is a class method. | 281 // to refcount a target object if the function being bound is a class method. |
| 282 // These copies are created even if the function takes parameters as const |
| 283 // references. (Binding to non-const references is forbidden, see bind.h.) |
| 277 // | 284 // |
| 278 // To change this behavior, we introduce a set of argument wrappers | 285 // To change this behavior, we introduce a set of argument wrappers |
| 279 // (e.g., Unretained(), and ConstRef()). These are simple container templates | 286 // (e.g., Unretained(), and ConstRef()). These are simple container templates |
| 280 // that are passed by value, and wrap a pointer to argument. See the | 287 // that are passed by value, and wrap a pointer to argument. See the |
| 281 // file-level comment in base/bind_helpers.h for more info. | 288 // file-level comment in base/bind_helpers.h for more info. |
| 282 // | 289 // |
| 283 // These types are passed to the Unwrap() functions, and the MaybeRefcount() | 290 // These types are passed to the Unwrap() functions, and the MaybeRefcount() |
| 284 // functions respectively to modify the behavior of Bind(). The Unwrap() | 291 // functions respectively to modify the behavior of Bind(). The Unwrap() |
| 285 // and MaybeRefcount() functions change behavior by doing partial | 292 // and MaybeRefcount() functions change behavior by doing partial |
| 286 // specialization based on whether or not a parameter is a wrapper type. | 293 // specialization based on whether or not a parameter is a wrapper type. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 | 427 |
| 421 ]] $$ for ARITY | 428 ]] $$ for ARITY |
| 422 | 429 |
| 423 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it | 430 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it |
| 424 // will be used in a lot of APIs with delayed execution. | 431 // will be used in a lot of APIs with delayed execution. |
| 425 typedef Callback<void(void)> Closure; | 432 typedef Callback<void(void)> Closure; |
| 426 | 433 |
| 427 } // namespace base | 434 } // namespace base |
| 428 | 435 |
| 429 #endif // BASE_CALLBACK_H | 436 #endif // BASE_CALLBACK_H |
| OLD | NEW |