| 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_ |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // HOW THE IMPLEMENTATION WORKS: | 122 // HOW THE IMPLEMENTATION WORKS: |
| 123 // | 123 // |
| 124 // There are three main components to the system: | 124 // There are three main components to the system: |
| 125 // 1) The Callback classes. | 125 // 1) The Callback classes. |
| 126 // 2) The Bind() functions. | 126 // 2) The Bind() functions. |
| 127 // 3) The arguments wrappers (e.g., Unretained() and ConstRef()). | 127 // 3) The arguments wrappers (e.g., Unretained() and ConstRef()). |
| 128 // | 128 // |
| 129 // The Callback classes represent a generic function pointer. Internally, | 129 // The Callback classes represent a generic function pointer. Internally, |
| 130 // it stores a refcounted piece of state that represents the target function | 130 // it stores a refcounted piece of state that represents the target function |
| 131 // and all its bound parameters. Each Callback specialization has a templated | 131 // and all its bound parameters. Each Callback specialization has a templated |
| 132 // constructor that takes an BindState<>*. In the context of the constructor, | 132 // constructor that takes an BindStateHolder<> object. In the context of |
| 133 // the static type of this BindState<> pointer uniquely identifies the | 133 // the constructor, the static type of this BindStateHolder<> object |
| 134 // function it is representing, all its bound parameters, and a Run() method | 134 // uniquely identifies the function it is representing, all its bound |
| 135 // that is capable of invoking the target. | 135 // parameters, and a DoInvoke() that is capable of invoking the target. |
| 136 // | 136 // |
| 137 // Callback's constructor takes the BindState<>* that has the full static type | 137 // Callback's constructor is takes the BindStateHolder<> that has the |
| 138 // and erases the target function type as well as the types of the bound | 138 // full static type and erases the target function type, and the bound |
| 139 // parameters. It does this by storing a pointer to the specific Run() | 139 // parameters. It does this by storing a pointer to the specific DoInvoke() |
| 140 // function, and upcasting the state of BindState<>* to a | 140 // function, and upcasting the state of BindStateHolder<> to a |
| 141 // BindStateBase*. This is safe as long as this BindStateBase pointer | 141 // BindStateBase. This is safe as long as this BindStateBase pointer |
| 142 // is only used with the stored Run() pointer. | 142 // is only used with the stored DoInvoke() pointer. |
| 143 // | 143 // |
| 144 // To BindState<> objects are created inside the Bind() functions. | 144 // To create BindStateHolder<> objects, we use the Bind() functions. |
| 145 // These functions, along with a set of internal templates, are responsible for | 145 // These functions, along with a set of internal templates, are reponsible for |
| 146 // | 146 // |
| 147 // - Unwrapping the function signature into return type, and parameters | 147 // - Unwrapping the function signature into return type, and parameters |
| 148 // - Determining the number of parameters that are bound | 148 // - Determining the number of parameters that are bound |
| 149 // - Creating the BindState storing the bound parameters | 149 // - Creating the storage for the bound parameters |
| 150 // - Performing compile-time asserts to avoid error-prone behavior | 150 // - Performing compile-time asserts to avoid error-prone behavior |
| 151 // - Returning an Callback<> with an arity matching the number of unbound | 151 // - Returning an BindStateHolder<> with an DoInvoke() that has an arity |
| 152 // parameters and that knows the correct refcounting semantics for the | 152 // matching the number of unbound parameters, and knows the correct |
| 153 // target object if we are binding a method. | 153 // refcounting semantics for the target object if we are binding a class |
| 154 // method. |
| 154 // | 155 // |
| 155 // The Bind functions do the above using type-inference, and template | 156 // The Bind functions do the above using type-inference, and template |
| 156 // specializations. | 157 // specializations. |
| 157 // | 158 // |
| 158 // By default Bind() will store copies of all bound parameters, and attempt | 159 // By default Bind() will store copies of all bound parameters, and attempt |
| 159 // to refcount a target object if the function being bound is a class method. | 160 // to refcount a target object if the function being bound is a class method. |
| 160 // | 161 // |
| 161 // To change this behavior, we introduce a set of argument wrappers | 162 // To change this behavior, we introduce a set of argument wrappers |
| 162 // (e.g., Unretained(), and ConstRef()). These are simple container templates | 163 // (e.g., Unretained(), and ConstRef()). These are simple container templates |
| 163 // that are passed by value, and wrap a pointer to argument. See the | 164 // that are passed by value, and wrap a pointer to argument. See the |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // | 232 // |
| 232 // After this, create template specializations for 0-7 parameters. Note that | 233 // After this, create template specializations for 0-7 parameters. Note that |
| 233 // even though the template typelist grows, the specialization still | 234 // even though the template typelist grows, the specialization still |
| 234 // only has one type: the function signature. | 235 // only has one type: the function signature. |
| 235 // | 236 // |
| 236 // If you are thinking of forward declaring Callback in your own header file, | 237 // If you are thinking of forward declaring Callback in your own header file, |
| 237 // please include "base/callback_forward.h" instead. | 238 // please include "base/callback_forward.h" instead. |
| 238 template <typename Sig> | 239 template <typename Sig> |
| 239 class Callback; | 240 class Callback; |
| 240 | 241 |
| 241 namespace internal { | |
| 242 template <typename Runnable, typename RunType, typename BoundArgsType> | |
| 243 struct BindState; | |
| 244 } // namespace internal | |
| 245 | |
| 246 template <typename R> | 242 template <typename R> |
| 247 class Callback<R(void)> : public internal::CallbackBase { | 243 class Callback<R(void)> : public internal::CallbackBase { |
| 248 public: | 244 public: |
| 249 typedef R(RunType)(); | 245 typedef R(RunType)(); |
| 250 | 246 |
| 251 Callback() : CallbackBase(NULL) { } | 247 Callback() : CallbackBase(NULL, NULL) { } |
| 252 | 248 |
| 249 // We pass BindStateHolder by const ref to avoid incurring an |
| 250 // unnecessary AddRef/Unref pair even though we will modify the object. |
| 251 // We cannot use a normal reference because the compiler will warn |
| 252 // since this is often used on a return value, which is a temporary. |
| 253 // |
| 253 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 254 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
| 254 // return the exact Callback<> type. See base/bind.h for details. | 255 // return the exact Callback<> type. See base/bind.h for details. |
| 255 template <typename Runnable, typename RunType, typename BoundArgsType> | 256 template <typename T> |
| 256 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) | 257 Callback(const internal::BindStateHolder<T>& bind_state_holder) |
| 257 : CallbackBase(bind_state) { | 258 : CallbackBase(NULL, &bind_state_holder.bind_state_) { |
| 258 | 259 // Force the assignment to a location variable of PolymorphicInvoke |
| 259 // Force the assignment to a local variable of PolymorphicInvoke | |
| 260 // so the compiler will typecheck that the passed in Run() method has | 260 // so the compiler will typecheck that the passed in Run() method has |
| 261 // the correct type. | 261 // the correct type. |
| 262 PolymorphicInvoke invoke_func = | 262 PolymorphicInvoke invoke_func = &T::InvokerType::Run; |
| 263 &internal::BindState<Runnable, RunType, BoundArgsType> | |
| 264 ::InvokerType::Run; | |
| 265 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 263 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
| 266 } | 264 } |
| 267 | 265 |
| 268 bool Equals(const Callback& other) const { | 266 bool Equals(const Callback& other) const { |
| 269 return CallbackBase::Equals(other); | 267 return CallbackBase::Equals(other); |
| 270 } | 268 } |
| 271 | 269 |
| 272 R Run() const { | 270 R Run() const { |
| 273 PolymorphicInvoke f = | 271 PolymorphicInvoke f = |
| 274 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); | 272 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); |
| 275 | 273 |
| 276 return f(bind_state_.get()); | 274 return f(bind_state_.get()); |
| 277 } | 275 } |
| 278 | 276 |
| 279 private: | 277 private: |
| 280 typedef R(*PolymorphicInvoke)( | 278 typedef R(*PolymorphicInvoke)( |
| 281 internal::BindStateBase*); | 279 internal::BindStateBase*); |
| 282 | 280 |
| 283 }; | 281 }; |
| 284 | 282 |
| 285 template <typename R, typename A1> | 283 template <typename R, typename A1> |
| 286 class Callback<R(A1)> : public internal::CallbackBase { | 284 class Callback<R(A1)> : public internal::CallbackBase { |
| 287 public: | 285 public: |
| 288 typedef R(RunType)(A1); | 286 typedef R(RunType)(A1); |
| 289 | 287 |
| 290 Callback() : CallbackBase(NULL) { } | 288 Callback() : CallbackBase(NULL, NULL) { } |
| 291 | 289 |
| 290 // We pass BindStateHolder by const ref to avoid incurring an |
| 291 // unnecessary AddRef/Unref pair even though we will modify the object. |
| 292 // We cannot use a normal reference because the compiler will warn |
| 293 // since this is often used on a return value, which is a temporary. |
| 294 // |
| 292 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 295 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
| 293 // return the exact Callback<> type. See base/bind.h for details. | 296 // return the exact Callback<> type. See base/bind.h for details. |
| 294 template <typename Runnable, typename RunType, typename BoundArgsType> | 297 template <typename T> |
| 295 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) | 298 Callback(const internal::BindStateHolder<T>& bind_state_holder) |
| 296 : CallbackBase(bind_state) { | 299 : CallbackBase(NULL, &bind_state_holder.bind_state_) { |
| 297 | 300 // Force the assignment to a location variable of PolymorphicInvoke |
| 298 // Force the assignment to a local variable of PolymorphicInvoke | |
| 299 // so the compiler will typecheck that the passed in Run() method has | 301 // so the compiler will typecheck that the passed in Run() method has |
| 300 // the correct type. | 302 // the correct type. |
| 301 PolymorphicInvoke invoke_func = | 303 PolymorphicInvoke invoke_func = &T::InvokerType::Run; |
| 302 &internal::BindState<Runnable, RunType, BoundArgsType> | |
| 303 ::InvokerType::Run; | |
| 304 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 304 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
| 305 } | 305 } |
| 306 | 306 |
| 307 bool Equals(const Callback& other) const { | 307 bool Equals(const Callback& other) const { |
| 308 return CallbackBase::Equals(other); | 308 return CallbackBase::Equals(other); |
| 309 } | 309 } |
| 310 | 310 |
| 311 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1) const { | 311 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1) const { |
| 312 PolymorphicInvoke f = | 312 PolymorphicInvoke f = |
| 313 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); | 313 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); |
| 314 | 314 |
| 315 return f(bind_state_.get(), a1); | 315 return f(bind_state_.get(), a1); |
| 316 } | 316 } |
| 317 | 317 |
| 318 private: | 318 private: |
| 319 typedef R(*PolymorphicInvoke)( | 319 typedef R(*PolymorphicInvoke)( |
| 320 internal::BindStateBase*, | 320 internal::BindStateBase*, |
| 321 typename internal::CallbackParamTraits<A1>::ForwardType); | 321 typename internal::CallbackParamTraits<A1>::ForwardType); |
| 322 | 322 |
| 323 }; | 323 }; |
| 324 | 324 |
| 325 template <typename R, typename A1, typename A2> | 325 template <typename R, typename A1, typename A2> |
| 326 class Callback<R(A1, A2)> : public internal::CallbackBase { | 326 class Callback<R(A1, A2)> : public internal::CallbackBase { |
| 327 public: | 327 public: |
| 328 typedef R(RunType)(A1, A2); | 328 typedef R(RunType)(A1, A2); |
| 329 | 329 |
| 330 Callback() : CallbackBase(NULL) { } | 330 Callback() : CallbackBase(NULL, NULL) { } |
| 331 | 331 |
| 332 // We pass BindStateHolder by const ref to avoid incurring an |
| 333 // unnecessary AddRef/Unref pair even though we will modify the object. |
| 334 // We cannot use a normal reference because the compiler will warn |
| 335 // since this is often used on a return value, which is a temporary. |
| 336 // |
| 332 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 337 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
| 333 // return the exact Callback<> type. See base/bind.h for details. | 338 // return the exact Callback<> type. See base/bind.h for details. |
| 334 template <typename Runnable, typename RunType, typename BoundArgsType> | 339 template <typename T> |
| 335 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) | 340 Callback(const internal::BindStateHolder<T>& bind_state_holder) |
| 336 : CallbackBase(bind_state) { | 341 : CallbackBase(NULL, &bind_state_holder.bind_state_) { |
| 337 | 342 // Force the assignment to a location variable of PolymorphicInvoke |
| 338 // Force the assignment to a local variable of PolymorphicInvoke | |
| 339 // so the compiler will typecheck that the passed in Run() method has | 343 // so the compiler will typecheck that the passed in Run() method has |
| 340 // the correct type. | 344 // the correct type. |
| 341 PolymorphicInvoke invoke_func = | 345 PolymorphicInvoke invoke_func = &T::InvokerType::Run; |
| 342 &internal::BindState<Runnable, RunType, BoundArgsType> | |
| 343 ::InvokerType::Run; | |
| 344 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 346 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
| 345 } | 347 } |
| 346 | 348 |
| 347 bool Equals(const Callback& other) const { | 349 bool Equals(const Callback& other) const { |
| 348 return CallbackBase::Equals(other); | 350 return CallbackBase::Equals(other); |
| 349 } | 351 } |
| 350 | 352 |
| 351 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, | 353 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, |
| 352 typename internal::CallbackParamTraits<A2>::ForwardType a2) const { | 354 typename internal::CallbackParamTraits<A2>::ForwardType a2) const { |
| 353 PolymorphicInvoke f = | 355 PolymorphicInvoke f = |
| 354 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); | 356 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); |
| 355 | 357 |
| 356 return f(bind_state_.get(), a1, | 358 return f(bind_state_.get(), a1, |
| 357 a2); | 359 a2); |
| 358 } | 360 } |
| 359 | 361 |
| 360 private: | 362 private: |
| 361 typedef R(*PolymorphicInvoke)( | 363 typedef R(*PolymorphicInvoke)( |
| 362 internal::BindStateBase*, | 364 internal::BindStateBase*, |
| 363 typename internal::CallbackParamTraits<A1>::ForwardType, | 365 typename internal::CallbackParamTraits<A1>::ForwardType, |
| 364 typename internal::CallbackParamTraits<A2>::ForwardType); | 366 typename internal::CallbackParamTraits<A2>::ForwardType); |
| 365 | 367 |
| 366 }; | 368 }; |
| 367 | 369 |
| 368 template <typename R, typename A1, typename A2, typename A3> | 370 template <typename R, typename A1, typename A2, typename A3> |
| 369 class Callback<R(A1, A2, A3)> : public internal::CallbackBase { | 371 class Callback<R(A1, A2, A3)> : public internal::CallbackBase { |
| 370 public: | 372 public: |
| 371 typedef R(RunType)(A1, A2, A3); | 373 typedef R(RunType)(A1, A2, A3); |
| 372 | 374 |
| 373 Callback() : CallbackBase(NULL) { } | 375 Callback() : CallbackBase(NULL, NULL) { } |
| 374 | 376 |
| 377 // We pass BindStateHolder by const ref to avoid incurring an |
| 378 // unnecessary AddRef/Unref pair even though we will modify the object. |
| 379 // We cannot use a normal reference because the compiler will warn |
| 380 // since this is often used on a return value, which is a temporary. |
| 381 // |
| 375 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 382 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
| 376 // return the exact Callback<> type. See base/bind.h for details. | 383 // return the exact Callback<> type. See base/bind.h for details. |
| 377 template <typename Runnable, typename RunType, typename BoundArgsType> | 384 template <typename T> |
| 378 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) | 385 Callback(const internal::BindStateHolder<T>& bind_state_holder) |
| 379 : CallbackBase(bind_state) { | 386 : CallbackBase(NULL, &bind_state_holder.bind_state_) { |
| 380 | 387 // Force the assignment to a location variable of PolymorphicInvoke |
| 381 // Force the assignment to a local variable of PolymorphicInvoke | |
| 382 // so the compiler will typecheck that the passed in Run() method has | 388 // so the compiler will typecheck that the passed in Run() method has |
| 383 // the correct type. | 389 // the correct type. |
| 384 PolymorphicInvoke invoke_func = | 390 PolymorphicInvoke invoke_func = &T::InvokerType::Run; |
| 385 &internal::BindState<Runnable, RunType, BoundArgsType> | |
| 386 ::InvokerType::Run; | |
| 387 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 391 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
| 388 } | 392 } |
| 389 | 393 |
| 390 bool Equals(const Callback& other) const { | 394 bool Equals(const Callback& other) const { |
| 391 return CallbackBase::Equals(other); | 395 return CallbackBase::Equals(other); |
| 392 } | 396 } |
| 393 | 397 |
| 394 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, | 398 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, |
| 395 typename internal::CallbackParamTraits<A2>::ForwardType a2, | 399 typename internal::CallbackParamTraits<A2>::ForwardType a2, |
| 396 typename internal::CallbackParamTraits<A3>::ForwardType a3) const { | 400 typename internal::CallbackParamTraits<A3>::ForwardType a3) const { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 409 typename internal::CallbackParamTraits<A2>::ForwardType, | 413 typename internal::CallbackParamTraits<A2>::ForwardType, |
| 410 typename internal::CallbackParamTraits<A3>::ForwardType); | 414 typename internal::CallbackParamTraits<A3>::ForwardType); |
| 411 | 415 |
| 412 }; | 416 }; |
| 413 | 417 |
| 414 template <typename R, typename A1, typename A2, typename A3, typename A4> | 418 template <typename R, typename A1, typename A2, typename A3, typename A4> |
| 415 class Callback<R(A1, A2, A3, A4)> : public internal::CallbackBase { | 419 class Callback<R(A1, A2, A3, A4)> : public internal::CallbackBase { |
| 416 public: | 420 public: |
| 417 typedef R(RunType)(A1, A2, A3, A4); | 421 typedef R(RunType)(A1, A2, A3, A4); |
| 418 | 422 |
| 419 Callback() : CallbackBase(NULL) { } | 423 Callback() : CallbackBase(NULL, NULL) { } |
| 420 | 424 |
| 425 // We pass BindStateHolder by const ref to avoid incurring an |
| 426 // unnecessary AddRef/Unref pair even though we will modify the object. |
| 427 // We cannot use a normal reference because the compiler will warn |
| 428 // since this is often used on a return value, which is a temporary. |
| 429 // |
| 421 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 430 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
| 422 // return the exact Callback<> type. See base/bind.h for details. | 431 // return the exact Callback<> type. See base/bind.h for details. |
| 423 template <typename Runnable, typename RunType, typename BoundArgsType> | 432 template <typename T> |
| 424 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) | 433 Callback(const internal::BindStateHolder<T>& bind_state_holder) |
| 425 : CallbackBase(bind_state) { | 434 : CallbackBase(NULL, &bind_state_holder.bind_state_) { |
| 426 | 435 // Force the assignment to a location variable of PolymorphicInvoke |
| 427 // Force the assignment to a local variable of PolymorphicInvoke | |
| 428 // so the compiler will typecheck that the passed in Run() method has | 436 // so the compiler will typecheck that the passed in Run() method has |
| 429 // the correct type. | 437 // the correct type. |
| 430 PolymorphicInvoke invoke_func = | 438 PolymorphicInvoke invoke_func = &T::InvokerType::Run; |
| 431 &internal::BindState<Runnable, RunType, BoundArgsType> | |
| 432 ::InvokerType::Run; | |
| 433 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 439 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
| 434 } | 440 } |
| 435 | 441 |
| 436 bool Equals(const Callback& other) const { | 442 bool Equals(const Callback& other) const { |
| 437 return CallbackBase::Equals(other); | 443 return CallbackBase::Equals(other); |
| 438 } | 444 } |
| 439 | 445 |
| 440 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, | 446 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, |
| 441 typename internal::CallbackParamTraits<A2>::ForwardType a2, | 447 typename internal::CallbackParamTraits<A2>::ForwardType a2, |
| 442 typename internal::CallbackParamTraits<A3>::ForwardType a3, | 448 typename internal::CallbackParamTraits<A3>::ForwardType a3, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 459 typename internal::CallbackParamTraits<A4>::ForwardType); | 465 typename internal::CallbackParamTraits<A4>::ForwardType); |
| 460 | 466 |
| 461 }; | 467 }; |
| 462 | 468 |
| 463 template <typename R, typename A1, typename A2, typename A3, typename A4, | 469 template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 464 typename A5> | 470 typename A5> |
| 465 class Callback<R(A1, A2, A3, A4, A5)> : public internal::CallbackBase { | 471 class Callback<R(A1, A2, A3, A4, A5)> : public internal::CallbackBase { |
| 466 public: | 472 public: |
| 467 typedef R(RunType)(A1, A2, A3, A4, A5); | 473 typedef R(RunType)(A1, A2, A3, A4, A5); |
| 468 | 474 |
| 469 Callback() : CallbackBase(NULL) { } | 475 Callback() : CallbackBase(NULL, NULL) { } |
| 470 | 476 |
| 477 // We pass BindStateHolder by const ref to avoid incurring an |
| 478 // unnecessary AddRef/Unref pair even though we will modify the object. |
| 479 // We cannot use a normal reference because the compiler will warn |
| 480 // since this is often used on a return value, which is a temporary. |
| 481 // |
| 471 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 482 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
| 472 // return the exact Callback<> type. See base/bind.h for details. | 483 // return the exact Callback<> type. See base/bind.h for details. |
| 473 template <typename Runnable, typename RunType, typename BoundArgsType> | 484 template <typename T> |
| 474 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) | 485 Callback(const internal::BindStateHolder<T>& bind_state_holder) |
| 475 : CallbackBase(bind_state) { | 486 : CallbackBase(NULL, &bind_state_holder.bind_state_) { |
| 476 | 487 // Force the assignment to a location variable of PolymorphicInvoke |
| 477 // Force the assignment to a local variable of PolymorphicInvoke | |
| 478 // so the compiler will typecheck that the passed in Run() method has | 488 // so the compiler will typecheck that the passed in Run() method has |
| 479 // the correct type. | 489 // the correct type. |
| 480 PolymorphicInvoke invoke_func = | 490 PolymorphicInvoke invoke_func = &T::InvokerType::Run; |
| 481 &internal::BindState<Runnable, RunType, BoundArgsType> | |
| 482 ::InvokerType::Run; | |
| 483 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 491 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
| 484 } | 492 } |
| 485 | 493 |
| 486 bool Equals(const Callback& other) const { | 494 bool Equals(const Callback& other) const { |
| 487 return CallbackBase::Equals(other); | 495 return CallbackBase::Equals(other); |
| 488 } | 496 } |
| 489 | 497 |
| 490 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, | 498 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, |
| 491 typename internal::CallbackParamTraits<A2>::ForwardType a2, | 499 typename internal::CallbackParamTraits<A2>::ForwardType a2, |
| 492 typename internal::CallbackParamTraits<A3>::ForwardType a3, | 500 typename internal::CallbackParamTraits<A3>::ForwardType a3, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 512 typename internal::CallbackParamTraits<A5>::ForwardType); | 520 typename internal::CallbackParamTraits<A5>::ForwardType); |
| 513 | 521 |
| 514 }; | 522 }; |
| 515 | 523 |
| 516 template <typename R, typename A1, typename A2, typename A3, typename A4, | 524 template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 517 typename A5, typename A6> | 525 typename A5, typename A6> |
| 518 class Callback<R(A1, A2, A3, A4, A5, A6)> : public internal::CallbackBase { | 526 class Callback<R(A1, A2, A3, A4, A5, A6)> : public internal::CallbackBase { |
| 519 public: | 527 public: |
| 520 typedef R(RunType)(A1, A2, A3, A4, A5, A6); | 528 typedef R(RunType)(A1, A2, A3, A4, A5, A6); |
| 521 | 529 |
| 522 Callback() : CallbackBase(NULL) { } | 530 Callback() : CallbackBase(NULL, NULL) { } |
| 523 | 531 |
| 532 // We pass BindStateHolder by const ref to avoid incurring an |
| 533 // unnecessary AddRef/Unref pair even though we will modify the object. |
| 534 // We cannot use a normal reference because the compiler will warn |
| 535 // since this is often used on a return value, which is a temporary. |
| 536 // |
| 524 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 537 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
| 525 // return the exact Callback<> type. See base/bind.h for details. | 538 // return the exact Callback<> type. See base/bind.h for details. |
| 526 template <typename Runnable, typename RunType, typename BoundArgsType> | 539 template <typename T> |
| 527 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) | 540 Callback(const internal::BindStateHolder<T>& bind_state_holder) |
| 528 : CallbackBase(bind_state) { | 541 : CallbackBase(NULL, &bind_state_holder.bind_state_) { |
| 529 | 542 // Force the assignment to a location variable of PolymorphicInvoke |
| 530 // Force the assignment to a local variable of PolymorphicInvoke | |
| 531 // so the compiler will typecheck that the passed in Run() method has | 543 // so the compiler will typecheck that the passed in Run() method has |
| 532 // the correct type. | 544 // the correct type. |
| 533 PolymorphicInvoke invoke_func = | 545 PolymorphicInvoke invoke_func = &T::InvokerType::Run; |
| 534 &internal::BindState<Runnable, RunType, BoundArgsType> | |
| 535 ::InvokerType::Run; | |
| 536 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 546 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
| 537 } | 547 } |
| 538 | 548 |
| 539 bool Equals(const Callback& other) const { | 549 bool Equals(const Callback& other) const { |
| 540 return CallbackBase::Equals(other); | 550 return CallbackBase::Equals(other); |
| 541 } | 551 } |
| 542 | 552 |
| 543 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, | 553 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, |
| 544 typename internal::CallbackParamTraits<A2>::ForwardType a2, | 554 typename internal::CallbackParamTraits<A2>::ForwardType a2, |
| 545 typename internal::CallbackParamTraits<A3>::ForwardType a3, | 555 typename internal::CallbackParamTraits<A3>::ForwardType a3, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 568 typename internal::CallbackParamTraits<A6>::ForwardType); | 578 typename internal::CallbackParamTraits<A6>::ForwardType); |
| 569 | 579 |
| 570 }; | 580 }; |
| 571 | 581 |
| 572 template <typename R, typename A1, typename A2, typename A3, typename A4, | 582 template <typename R, typename A1, typename A2, typename A3, typename A4, |
| 573 typename A5, typename A6, typename A7> | 583 typename A5, typename A6, typename A7> |
| 574 class Callback<R(A1, A2, A3, A4, A5, A6, A7)> : public internal::CallbackBase { | 584 class Callback<R(A1, A2, A3, A4, A5, A6, A7)> : public internal::CallbackBase { |
| 575 public: | 585 public: |
| 576 typedef R(RunType)(A1, A2, A3, A4, A5, A6, A7); | 586 typedef R(RunType)(A1, A2, A3, A4, A5, A6, A7); |
| 577 | 587 |
| 578 Callback() : CallbackBase(NULL) { } | 588 Callback() : CallbackBase(NULL, NULL) { } |
| 579 | 589 |
| 590 // We pass BindStateHolder by const ref to avoid incurring an |
| 591 // unnecessary AddRef/Unref pair even though we will modify the object. |
| 592 // We cannot use a normal reference because the compiler will warn |
| 593 // since this is often used on a return value, which is a temporary. |
| 594 // |
| 580 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT | 595 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
| 581 // return the exact Callback<> type. See base/bind.h for details. | 596 // return the exact Callback<> type. See base/bind.h for details. |
| 582 template <typename Runnable, typename RunType, typename BoundArgsType> | 597 template <typename T> |
| 583 Callback(internal::BindState<Runnable, RunType, BoundArgsType>* bind_state) | 598 Callback(const internal::BindStateHolder<T>& bind_state_holder) |
| 584 : CallbackBase(bind_state) { | 599 : CallbackBase(NULL, &bind_state_holder.bind_state_) { |
| 585 | 600 // Force the assignment to a location variable of PolymorphicInvoke |
| 586 // Force the assignment to a local variable of PolymorphicInvoke | |
| 587 // so the compiler will typecheck that the passed in Run() method has | 601 // so the compiler will typecheck that the passed in Run() method has |
| 588 // the correct type. | 602 // the correct type. |
| 589 PolymorphicInvoke invoke_func = | 603 PolymorphicInvoke invoke_func = &T::InvokerType::Run; |
| 590 &internal::BindState<Runnable, RunType, BoundArgsType> | |
| 591 ::InvokerType::Run; | |
| 592 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); | 604 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
| 593 } | 605 } |
| 594 | 606 |
| 595 bool Equals(const Callback& other) const { | 607 bool Equals(const Callback& other) const { |
| 596 return CallbackBase::Equals(other); | 608 return CallbackBase::Equals(other); |
| 597 } | 609 } |
| 598 | 610 |
| 599 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, | 611 R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1, |
| 600 typename internal::CallbackParamTraits<A2>::ForwardType a2, | 612 typename internal::CallbackParamTraits<A2>::ForwardType a2, |
| 601 typename internal::CallbackParamTraits<A3>::ForwardType a3, | 613 typename internal::CallbackParamTraits<A3>::ForwardType a3, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 629 }; | 641 }; |
| 630 | 642 |
| 631 | 643 |
| 632 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it | 644 // Syntactic sugar to make Callbacks<void(void)> easier to declare since it |
| 633 // will be used in a lot of APIs with delayed execution. | 645 // will be used in a lot of APIs with delayed execution. |
| 634 typedef Callback<void(void)> Closure; | 646 typedef Callback<void(void)> Closure; |
| 635 | 647 |
| 636 } // namespace base | 648 } // namespace base |
| 637 | 649 |
| 638 #endif // BASE_CALLBACK_H | 650 #endif // BASE_CALLBACK_H |
| OLD | NEW |