| OLD | NEW |
| 1 #ifndef GOOGLE_PROTOBUF_STUBS_CALLBACK_H_ | 1 #ifndef GOOGLE_PROTOBUF_STUBS_CALLBACK_H_ |
| 2 #define GOOGLE_PROTOBUF_STUBS_CALLBACK_H_ | 2 #define GOOGLE_PROTOBUF_STUBS_CALLBACK_H_ |
| 3 | 3 |
| 4 #include <google/protobuf/stubs/macros.h> | 4 #include <google/protobuf/stubs/macros.h> |
| 5 #include <google/protobuf/stubs/type_traits.h> | 5 #include <google/protobuf/stubs/type_traits.h> |
| 6 | 6 |
| 7 // =================================================================== | 7 // =================================================================== |
| 8 // emulates google3/base/callback.h | 8 // emulates google3/base/callback.h |
| 9 | 9 |
| 10 namespace google { | 10 namespace google { |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 bool self_deleting_; | 339 bool self_deleting_; |
| 340 P1 p1_; | 340 P1 p1_; |
| 341 }; | 341 }; |
| 342 | 342 |
| 343 template <typename T> | 343 template <typename T> |
| 344 struct InternalConstRef { | 344 struct InternalConstRef { |
| 345 typedef typename remove_reference<T>::type base_type; | 345 typedef typename remove_reference<T>::type base_type; |
| 346 typedef const base_type& type; | 346 typedef const base_type& type; |
| 347 }; | 347 }; |
| 348 | 348 |
| 349 template<typename R, typename T> |
| 350 class MethodResultCallback_0_0 : public ResultCallback<R> { |
| 351 public: |
| 352 typedef R (T::*MethodType)(); |
| 353 MethodResultCallback_0_0(T* object, MethodType method, bool self_deleting) |
| 354 : object_(object), |
| 355 method_(method), |
| 356 self_deleting_(self_deleting) {} |
| 357 ~MethodResultCallback_0_0() {} |
| 358 |
| 359 R Run() { |
| 360 bool needs_delete = self_deleting_; |
| 361 R result = (object_->*method_)(); |
| 362 if (needs_delete) delete this; |
| 363 return result; |
| 364 } |
| 365 |
| 366 private: |
| 367 T* object_; |
| 368 MethodType method_; |
| 369 bool self_deleting_; |
| 370 }; |
| 371 |
| 349 template <typename R, typename T, typename P1, typename P2, typename P3, | 372 template <typename R, typename T, typename P1, typename P2, typename P3, |
| 350 typename P4, typename P5, typename A1, typename A2> | 373 typename P4, typename P5, typename A1, typename A2> |
| 351 class MethodResultCallback_5_2 : public ResultCallback2<R, A1, A2> { | 374 class MethodResultCallback_5_2 : public ResultCallback2<R, A1, A2> { |
| 352 public: | 375 public: |
| 353 typedef R (T::*MethodType)(P1, P2, P3, P4, P5, A1, A2); | 376 typedef R (T::*MethodType)(P1, P2, P3, P4, P5, A1, A2); |
| 354 MethodResultCallback_5_2(T* object, MethodType method, bool self_deleting, | 377 MethodResultCallback_5_2(T* object, MethodType method, bool self_deleting, |
| 355 P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) | 378 P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) |
| 356 : object_(object), | 379 : object_(object), |
| 357 method_(method), | 380 method_(method), |
| 358 self_deleting_(self_deleting), | 381 self_deleting_(self_deleting), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 374 T* object_; | 397 T* object_; |
| 375 MethodType method_; | 398 MethodType method_; |
| 376 bool self_deleting_; | 399 bool self_deleting_; |
| 377 typename remove_reference<P1>::type p1_; | 400 typename remove_reference<P1>::type p1_; |
| 378 typename remove_reference<P2>::type p2_; | 401 typename remove_reference<P2>::type p2_; |
| 379 typename remove_reference<P3>::type p3_; | 402 typename remove_reference<P3>::type p3_; |
| 380 typename remove_reference<P4>::type p4_; | 403 typename remove_reference<P4>::type p4_; |
| 381 typename remove_reference<P5>::type p5_; | 404 typename remove_reference<P5>::type p5_; |
| 382 }; | 405 }; |
| 383 | 406 |
| 407 } // namespace internal |
| 408 |
| 384 // See Closure. | 409 // See Closure. |
| 385 inline Closure* NewCallback(void (*function)()) { | 410 inline Closure* NewCallback(void (*function)()) { |
| 386 return new internal::FunctionClosure0(function, true); | 411 return new internal::FunctionClosure0(function, true); |
| 387 } | 412 } |
| 388 | 413 |
| 389 // See Closure. | 414 // See Closure. |
| 390 inline Closure* NewPermanentCallback(void (*function)()) { | 415 inline Closure* NewPermanentCallback(void (*function)()) { |
| 391 return new internal::FunctionClosure0(function, false); | 416 return new internal::FunctionClosure0(function, false); |
| 392 } | 417 } |
| 393 | 418 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 } | 536 } |
| 512 | 537 |
| 513 // See ResultCallback1 | 538 // See ResultCallback1 |
| 514 template<typename R, typename P1, typename A1> | 539 template<typename R, typename P1, typename A1> |
| 515 inline ResultCallback1<R, A1>* NewPermanentCallback( | 540 inline ResultCallback1<R, A1>* NewPermanentCallback( |
| 516 R (*function)(P1, A1), P1 p1) { | 541 R (*function)(P1, A1), P1 p1) { |
| 517 return new internal::FunctionResultCallback_1_1<R, P1, A1>( | 542 return new internal::FunctionResultCallback_1_1<R, P1, A1>( |
| 518 function, false, p1); | 543 function, false, p1); |
| 519 } | 544 } |
| 520 | 545 |
| 546 // See MethodResultCallback_0_0 |
| 547 template <typename R, typename T1, typename T2> |
| 548 inline ResultCallback<R>* NewPermanentCallback( |
| 549 T1* object, R (T2::*function)()) { |
| 550 return new internal::MethodResultCallback_0_0<R, T1>(object, function, false); |
| 551 } |
| 552 |
| 521 // See MethodResultCallback_5_2 | 553 // See MethodResultCallback_5_2 |
| 522 template <typename R, typename T, typename P1, typename P2, typename P3, | 554 template <typename R, typename T, typename P1, typename P2, typename P3, |
| 523 typename P4, typename P5, typename A1, typename A2> | 555 typename P4, typename P5, typename A1, typename A2> |
| 524 inline ResultCallback2<R, A1, A2>* NewPermanentCallback( | 556 inline ResultCallback2<R, A1, A2>* NewPermanentCallback( |
| 525 T* object, R (T::*function)(P1, P2, P3, P4, P5, A1, A2), | 557 T* object, R (T::*function)(P1, P2, P3, P4, P5, A1, A2), |
| 526 typename internal::InternalConstRef<P1>::type p1, | 558 typename internal::InternalConstRef<P1>::type p1, |
| 527 typename internal::InternalConstRef<P2>::type p2, | 559 typename internal::InternalConstRef<P2>::type p2, |
| 528 typename internal::InternalConstRef<P3>::type p3, | 560 typename internal::InternalConstRef<P3>::type p3, |
| 529 typename internal::InternalConstRef<P4>::type p4, | 561 typename internal::InternalConstRef<P4>::type p4, |
| 530 typename internal::InternalConstRef<P5>::type p5) { | 562 typename internal::InternalConstRef<P5>::type p5) { |
| 531 return new internal::MethodResultCallback_5_2<R, T, P1, P2, P3, P4, P5, A1, | 563 return new internal::MethodResultCallback_5_2<R, T, P1, P2, P3, P4, P5, A1, |
| 532 A2>(object, function, false, p1, | 564 A2>(object, function, false, p1, |
| 533 p2, p3, p4, p5); | 565 p2, p3, p4, p5); |
| 534 } | 566 } |
| 535 | 567 |
| 536 } // namespace internal | |
| 537 | |
| 538 // A function which does nothing. Useful for creating no-op callbacks, e.g.: | 568 // A function which does nothing. Useful for creating no-op callbacks, e.g.: |
| 539 // Closure* nothing = NewCallback(&DoNothing); | 569 // Closure* nothing = NewCallback(&DoNothing); |
| 540 void LIBPROTOBUF_EXPORT DoNothing(); | 570 void LIBPROTOBUF_EXPORT DoNothing(); |
| 541 | 571 |
| 542 | 572 |
| 543 } // namespace protobuf | 573 } // namespace protobuf |
| 544 } // namespace google | 574 } // namespace google |
| 545 | 575 |
| 546 #endif // GOOGLE_PROTOBUF_STUBS_CALLBACK_H_ | 576 #endif // GOOGLE_PROTOBUF_STUBS_CALLBACK_H_ |
| OLD | NEW |