| 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 (c) 2012 The Chromium Authors. All rights reserved. | 6 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 7 // Use of this source code is governed by a BSD-style license that can be | 7 // Use of this source code is governed by a BSD-style license that can be |
| 8 // found in the LICENSE file. | 8 // found in the LICENSE file. |
| 9 | 9 |
| 10 #ifndef BASE_CALLBACK_H_ | 10 #ifndef BASE_CALLBACK_H_ |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 // | 207 // |
| 208 // void TakesOneRef(scoped_refptr<Foo> arg) {} | 208 // void TakesOneRef(scoped_refptr<Foo> arg) {} |
| 209 // scoped_refptr<Foo> f(new Foo) | 209 // scoped_refptr<Foo> f(new Foo) |
| 210 // base::Closure cb = base::Bind(&TakesOneRef, f); | 210 // base::Closure cb = base::Bind(&TakesOneRef, f); |
| 211 // | 211 // |
| 212 // This should "just work." The closure will take a reference as long as it | 212 // This should "just work." The closure will take a reference as long as it |
| 213 // is alive, and another reference will be taken for the called function. | 213 // is alive, and another reference will be taken for the called function. |
| 214 // | 214 // |
| 215 // PASSING PARAMETERS BY REFERENCE | 215 // PASSING PARAMETERS BY REFERENCE |
| 216 // | 216 // |
| 217 // void foo(int arg) { cout << arg << endl } | 217 // Const references are *copied* unless ConstRef is used. Example: |
| 218 // |
| 219 // void foo(const int& arg) { printf("%d %p\n", arg, &arg); } |
| 218 // int n = 1; | 220 // int n = 1; |
| 221 // base::Closure has_copy = base::Bind(&foo, n); |
| 219 // base::Closure has_ref = base::Bind(&foo, base::ConstRef(n)); | 222 // base::Closure has_ref = base::Bind(&foo, base::ConstRef(n)); |
| 220 // n = 2; | 223 // n = 2; |
| 221 // has_ref.Run(); // Prints "2" | 224 // foo(n); // Prints "2 0xaaaaaaaaaaaa" |
| 225 // has_copy.Run(); // Prints "1 0xbbbbbbbbbbbb" |
| 226 // has_ref.Run(); // Prints "2 0xaaaaaaaaaaaa" |
| 222 // | 227 // |
| 223 // Normally parameters are copied in the closure. DANGER: ConstRef stores a | 228 // Normally parameters are copied in the closure. DANGER: ConstRef stores a |
| 224 // const reference instead, referencing the original parameter. This means | 229 // const reference instead, referencing the original parameter. This means |
| 225 // that you must ensure the object outlives the callback! | 230 // that you must ensure the object outlives the callback! |
| 226 // | 231 // |
| 227 // | 232 // |
| 228 // ----------------------------------------------------------------------------- | 233 // ----------------------------------------------------------------------------- |
| 229 // Implementation notes | 234 // Implementation notes |
| 230 // ----------------------------------------------------------------------------- | 235 // ----------------------------------------------------------------------------- |
| 231 // | 236 // |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 }; | 761 }; |
| 757 | 762 |
| 758 | 763 |
| 759 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it | 764 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it |
| 760 // will be used in a lot of APIs with delayed execution. | 765 // will be used in a lot of APIs with delayed execution. |
| 761 typedef Callback<void(void)> Closure; | 766 typedef Callback<void(void)> Closure; |
| 762 | 767 |
| 763 } // namespace base | 768 } // namespace base |
| 764 | 769 |
| 765 #endif // BASE_CALLBACK_H | 770 #endif // BASE_CALLBACK_H |
| OLD | NEW |