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) 2011 The Chromium Authors. All rights reserved. | 6 // Copyright (c) 2011 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_ |
11 #define BASE_CALLBACK_H_ | 11 #define BASE_CALLBACK_H_ |
12 #pragma once | 12 #pragma once |
13 | 13 |
14 #include "base/callback_helpers.h" | 14 #include "base/callback_internal.h" |
15 #include "base/callback_old.h" | 15 #include "base/callback_old.h" |
16 | 16 |
17 // New, super-duper, unified Callback system. This will eventually replace | 17 // New, super-duper, unified Callback system. This will eventually replace |
18 // NewRunnableMethod, NewRunnableFunction, CreateFunctor, and CreateCallback | 18 // NewRunnableMethod, NewRunnableFunction, CreateFunctor, and CreateCallback |
19 // systems currently in the Chromium code base. | 19 // systems currently in the Chromium code base. |
20 // | 20 // |
21 // WHAT IS THIS: | 21 // WHAT IS THIS: |
22 // | 22 // |
23 // The templated Callback class is a generalized function object. Together | 23 // The templated Callback class is a generalized function object. Together |
24 // with the Bind() function in bind.h, they provide a type-safe method for | 24 // with the Bind() function in bind.h, they provide a type-safe method for |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // - Invoking the return of Bind. Bind(&foo).Run() does not work; | 205 // - Invoking the return of Bind. Bind(&foo).Run() does not work; |
206 // - Binding arrays to functions that take a non-const pointer. | 206 // - Binding arrays to functions that take a non-const pointer. |
207 // Example: | 207 // Example: |
208 // void Foo(const char* ptr); | 208 // void Foo(const char* ptr); |
209 // void Bar(char* ptr); | 209 // void Bar(char* ptr); |
210 // Bind(&Foo, "test"); | 210 // Bind(&Foo, "test"); |
211 // Bind(&Bar, "test"); // This fails because ptr is not const. | 211 // Bind(&Bar, "test"); // This fails because ptr is not const. |
212 | 212 |
213 namespace base { | 213 namespace base { |
214 | 214 |
215 namespace internal { | |
216 | |
217 // Holds the methods that don't require specialization to reduce template bloat. | |
218 class CallbackBase { | |
219 public: | |
220 // Returns true if Callback is null (doesn't refer to anything). | |
221 bool is_null() const { | |
222 return invoker_storage_.get() == NULL; | |
223 } | |
224 | |
225 // Returns the Callback into an uninitalized state. | |
226 void Reset() { | |
227 invoker_storage_ = NULL; | |
228 polymorphic_invoke_ = NULL; | |
229 } | |
230 | |
231 bool Equals(const CallbackBase& other) const { | |
232 return invoker_storage_.get() == other.invoker_storage_.get() && | |
233 polymorphic_invoke_ == other.polymorphic_invoke_; | |
234 } | |
235 | |
236 protected: | |
237 // In C++, it is safe to cast function pointers to function pointers of | |
238 // another type. It is not okay to use void*. We create a InvokeFuncStorage | |
239 // that that can store our function pointer, and then cast it back to | |
240 // the original type on usage. | |
241 typedef void(*InvokeFuncStorage)(void); | |
242 | |
243 CallbackBase(InvokeFuncStorage polymorphic_invoke, | |
244 scoped_refptr<InvokerStorageBase>* invoker_storage) | |
245 : polymorphic_invoke_(polymorphic_invoke) { | |
246 if (invoker_storage) { | |
247 invoker_storage_.swap(*invoker_storage); | |
248 } | |
249 } | |
250 | |
251 scoped_refptr<InvokerStorageBase> invoker_storage_; | |
252 InvokeFuncStorage polymorphic_invoke_; | |
253 }; | |
254 | |
255 } // namespace internal | |
256 | |
257 | |
258 // First, we forward declare the Callback class template. This informs the | 215 // First, we forward declare the Callback class template. This informs the |
259 // compiler that the template only has 1 type parameter which is the function | 216 // compiler that the template only has 1 type parameter which is the function |
260 // signature that the Callback is representing. | 217 // signature that the Callback is representing. |
261 // | 218 // |
262 // After this, create template specializations for 0-6 parameters. Note that | 219 // After this, create template specializations for 0-6 parameters. Note that |
263 // even though the template typelist grows, the specialization still | 220 // even though the template typelist grows, the specialization still |
264 // only has one type: the function signature. | 221 // only has one type: the function signature. |
265 template <typename Sig> | 222 template <typename Sig> |
266 class Callback; | 223 class Callback; |
267 template <typename R> | 224 template <typename R> |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 }; | 472 }; |
516 | 473 |
517 | 474 |
518 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it | 475 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it |
519 // will be used in a lot of APIs with delayed execution. | 476 // will be used in a lot of APIs with delayed execution. |
520 typedef Callback<void(void)> Closure; | 477 typedef Callback<void(void)> Closure; |
521 | 478 |
522 } // namespace base | 479 } // namespace base |
523 | 480 |
524 #endif // BASE_CALLBACK_H | 481 #endif // BASE_CALLBACK_H |
OLD | NEW |