diff --git a/webrtc/base/bind.h b/webrtc/base/bind.h index e8c1ab5e91..397a4d5c87 100644 --- a/webrtc/base/bind.h +++ b/webrtc/base/bind.h @@ -1,7 +1,3 @@ -// This file was GENERATED by command: -// pump.py bind.h.pump -// DO NOT EDIT BY HAND!!! - /* * Copyright 2012 The WebRTC Project Authors. All rights reserved. * @@ -12,9 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ -// To generate bind.h from bind.h.pump, execute: -// /home/build/google3/third_party/gtest/scripts/pump.py bind.h.pump - // Bind() is an overloaded function that converts method calls into function // objects (aka functors). The method object is captured as a scoped_refptr<> if // possible, and as a raw pointer otherwise. Any arguments to the method are @@ -64,6 +57,9 @@ #ifndef WEBRTC_BASE_BIND_H_ #define WEBRTC_BASE_BIND_H_ +#include +#include + #include "webrtc/base/scoped_ref_ptr.h" #include "webrtc/base/template_util.h" @@ -131,1406 +127,94 @@ struct PointerType { } // namespace detail -template -class MethodFunctor0 { +template +class MethodFunctor { public: - MethodFunctor0(MethodT method, ObjectT* object) - : method_(method), object_(object) {} + MethodFunctor(MethodT method, ObjectT* object, Args... args) + : method_(method), object_(object), args_(args...) {} R operator()() const { - return (object_->*method_)(); } - private: - MethodT method_; - typename detail::PointerType::type object_; -}; - -template -class Functor0 { - public: - explicit Functor0(const FunctorT& functor) - : functor_(functor) {} - R operator()() const { - return functor_(); } - private: - FunctorT functor_; -}; - - -#define FP_T(x) R (ObjectT::*x)() - -template -MethodFunctor0 -Bind(FP_T(method), ObjectT* object) { - return MethodFunctor0( - method, object); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)() const - -template -MethodFunctor0 -Bind(FP_T(method), const ObjectT* object) { - return MethodFunctor0( - method, object); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)() - -template -MethodFunctor0 -Bind(FP_T(method), const scoped_refptr& object) { - return MethodFunctor0( - method, object.get()); -} - -#undef FP_T -#define FP_T(x) R (*x)() - -template -Functor0 -Bind(FP_T(function)) { - return Functor0( - function); -} - -#undef FP_T - -template -class MethodFunctor1 { - public: - MethodFunctor1(MethodT method, ObjectT* object, - P1 p1) - : method_(method), object_(object), - p1_(p1) {} - R operator()() const { - return (object_->*method_)(p1_); } - private: - MethodT method_; - typename detail::PointerType::type object_; - typename rtc::remove_reference::type p1_; -}; - -template -class Functor1 { - public: - Functor1(const FunctorT& functor, P1 p1) - : functor_(functor), - p1_(p1) {} - R operator()() const { - return functor_(p1_); } - private: - FunctorT functor_; - typename rtc::remove_reference::type p1_; -}; - - -#define FP_T(x) R (ObjectT::*x)(P1) - -template -MethodFunctor1 -Bind(FP_T(method), ObjectT* object, - typename detail::identity::type p1) { - return MethodFunctor1( - method, object, p1); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1) const - -template -MethodFunctor1 -Bind(FP_T(method), const ObjectT* object, - typename detail::identity::type p1) { - return MethodFunctor1( - method, object, p1); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1) - -template -MethodFunctor1 -Bind(FP_T(method), const scoped_refptr& object, - typename detail::identity::type p1) { - return MethodFunctor1( - method, object.get(), p1); -} - -#undef FP_T -#define FP_T(x) R (*x)(P1) - -template -Functor1 -Bind(FP_T(function), - typename detail::identity::type p1) { - return Functor1( - function, p1); -} - -#undef FP_T - -template -class MethodFunctor2 { - public: - MethodFunctor2(MethodT method, ObjectT* object, - P1 p1, - P2 p2) - : method_(method), object_(object), - p1_(p1), - p2_(p2) {} - R operator()() const { - return (object_->*method_)(p1_, p2_); } - private: - MethodT method_; - typename detail::PointerType::type object_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; -}; - -template -class Functor2 { - public: - Functor2(const FunctorT& functor, P1 p1, P2 p2) - : functor_(functor), - p1_(p1), - p2_(p2) {} - R operator()() const { - return functor_(p1_, p2_); } - private: - FunctorT functor_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; -}; - - -#define FP_T(x) R (ObjectT::*x)(P1, P2) - -template -MethodFunctor2 -Bind(FP_T(method), ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2) { - return MethodFunctor2( - method, object, p1, p2); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2) const - -template -MethodFunctor2 -Bind(FP_T(method), const ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2) { - return MethodFunctor2( - method, object, p1, p2); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2) - -template -MethodFunctor2 -Bind(FP_T(method), const scoped_refptr& object, - typename detail::identity::type p1, - typename detail::identity::type p2) { - return MethodFunctor2( - method, object.get(), p1, p2); -} - -#undef FP_T -#define FP_T(x) R (*x)(P1, P2) - -template -Functor2 -Bind(FP_T(function), - typename detail::identity::type p1, - typename detail::identity::type p2) { - return Functor2( - function, p1, p2); -} - -#undef FP_T - -template -class MethodFunctor3 { - public: - MethodFunctor3(MethodT method, ObjectT* object, - P1 p1, - P2 p2, - P3 p3) - : method_(method), object_(object), - p1_(p1), - p2_(p2), - p3_(p3) {} - R operator()() const { - return (object_->*method_)(p1_, p2_, p3_); } - private: - MethodT method_; - typename detail::PointerType::type object_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; - typename rtc::remove_reference::type p3_; -}; - -template -class Functor3 { - public: - Functor3(const FunctorT& functor, P1 p1, P2 p2, P3 p3) - : functor_(functor), - p1_(p1), - p2_(p2), - p3_(p3) {} - R operator()() const { - return functor_(p1_, p2_, p3_); } - private: - FunctorT functor_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; - typename rtc::remove_reference::type p3_; -}; - - -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3) - -template -MethodFunctor3 -Bind(FP_T(method), ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3) { - return MethodFunctor3( - method, object, p1, p2, p3); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3) const - -template -MethodFunctor3 -Bind(FP_T(method), const ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3) { - return MethodFunctor3( - method, object, p1, p2, p3); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3) - -template -MethodFunctor3 -Bind(FP_T(method), const scoped_refptr& object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3) { - return MethodFunctor3( - method, object.get(), p1, p2, p3); -} - -#undef FP_T -#define FP_T(x) R (*x)(P1, P2, P3) - -template -Functor3 -Bind(FP_T(function), - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3) { - return Functor3( - function, p1, p2, p3); -} - -#undef FP_T - -template -class MethodFunctor4 { - public: - MethodFunctor4(MethodT method, ObjectT* object, - P1 p1, - P2 p2, - P3 p3, - P4 p4) - : method_(method), object_(object), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4) {} - R operator()() const { - return (object_->*method_)(p1_, p2_, p3_, p4_); } - private: - MethodT method_; - typename detail::PointerType::type object_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; - typename rtc::remove_reference::type p3_; - typename rtc::remove_reference::type p4_; -}; - -template -class Functor4 { - public: - Functor4(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4) - : functor_(functor), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4) {} - R operator()() const { - return functor_(p1_, p2_, p3_, p4_); } - private: - FunctorT functor_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; - typename rtc::remove_reference::type p3_; - typename rtc::remove_reference::type p4_; -}; - - -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4) - -template -MethodFunctor4 -Bind(FP_T(method), ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4) { - return MethodFunctor4( - method, object, p1, p2, p3, p4); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4) const - -template -MethodFunctor4 -Bind(FP_T(method), const ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4) { - return MethodFunctor4( - method, object, p1, p2, p3, p4); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4) - -template -MethodFunctor4 -Bind(FP_T(method), const scoped_refptr& object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4) { - return MethodFunctor4( - method, object.get(), p1, p2, p3, p4); -} - -#undef FP_T -#define FP_T(x) R (*x)(P1, P2, P3, P4) - -template -Functor4 -Bind(FP_T(function), - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4) { - return Functor4( - function, p1, p2, p3, p4); -} - -#undef FP_T - -template -class MethodFunctor5 { - public: - MethodFunctor5(MethodT method, ObjectT* object, - P1 p1, - P2 p2, - P3 p3, - P4 p4, - P5 p5) - : method_(method), object_(object), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5) {} - R operator()() const { - return (object_->*method_)(p1_, p2_, p3_, p4_, p5_); } - private: - MethodT method_; - typename detail::PointerType::type object_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; - typename rtc::remove_reference::type p3_; - typename rtc::remove_reference::type p4_; - typename rtc::remove_reference::type p5_; -}; - -template -class Functor5 { - public: - Functor5(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) - : functor_(functor), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5) {} - R operator()() const { - return functor_(p1_, p2_, p3_, p4_, p5_); } - private: - FunctorT functor_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; - typename rtc::remove_reference::type p3_; - typename rtc::remove_reference::type p4_; - typename rtc::remove_reference::type p5_; -}; - - -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5) - -template -MethodFunctor5 -Bind(FP_T(method), ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5) { - return MethodFunctor5( - method, object, p1, p2, p3, p4, p5); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5) const - -template -MethodFunctor5 -Bind(FP_T(method), const ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5) { - return MethodFunctor5( - method, object, p1, p2, p3, p4, p5); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5) - -template -MethodFunctor5 -Bind(FP_T(method), const scoped_refptr& object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5) { - return MethodFunctor5( - method, object.get(), p1, p2, p3, p4, p5); -} - -#undef FP_T -#define FP_T(x) R (*x)(P1, P2, P3, P4, P5) - -template -Functor5 -Bind(FP_T(function), - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5) { - return Functor5( - function, p1, p2, p3, p4, p5); -} - -#undef FP_T - -template -class MethodFunctor6 { - public: - MethodFunctor6(MethodT method, ObjectT* object, - P1 p1, - P2 p2, - P3 p3, - P4 p4, - P5 p5, - P6 p6) - : method_(method), object_(object), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5), - p6_(p6) {} - R operator()() const { - return (object_->*method_)(p1_, p2_, p3_, p4_, p5_, p6_); } - private: - MethodT method_; - typename detail::PointerType::type object_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; - typename rtc::remove_reference::type p3_; - typename rtc::remove_reference::type p4_; - typename rtc::remove_reference::type p5_; - typename rtc::remove_reference::type p6_; -}; - -template -class Functor6 { - public: - Functor6(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) - : functor_(functor), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5), - p6_(p6) {} - R operator()() const { - return functor_(p1_, p2_, p3_, p4_, p5_, p6_); } - private: - FunctorT functor_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; - typename rtc::remove_reference::type p3_; - typename rtc::remove_reference::type p4_; - typename rtc::remove_reference::type p5_; - typename rtc::remove_reference::type p6_; -}; - - -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6) - -template -MethodFunctor6 -Bind(FP_T(method), ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6) { - return MethodFunctor6( - method, object, p1, p2, p3, p4, p5, p6); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6) const - -template -MethodFunctor6 -Bind(FP_T(method), const ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6) { - return MethodFunctor6( - method, object, p1, p2, p3, p4, p5, p6); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6) - -template -MethodFunctor6 -Bind(FP_T(method), const scoped_refptr& object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6) { - return MethodFunctor6( - method, object.get(), p1, p2, p3, p4, p5, p6); -} - -#undef FP_T -#define FP_T(x) R (*x)(P1, P2, P3, P4, P5, P6) - -template -Functor6 -Bind(FP_T(function), - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6) { - return Functor6( - function, p1, p2, p3, p4, p5, p6); -} - -#undef FP_T - -template -class MethodFunctor7 { - public: - MethodFunctor7(MethodT method, - ObjectT* object, - P1 p1, - P2 p2, - P3 p3, - P4 p4, - P5 p5, - P6 p6, - P7 p7) - : method_(method), - object_(object), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5), - p6_(p6), - p7_(p7) {} - R operator()() const { - return (object_->*method_)(p1_, p2_, p3_, p4_, p5_, p6_, p7_); + return CallMethod(typename sequence_generator::type()); } private: + // Use sequence_generator (see template_util.h) to expand a MethodFunctor + // with 2 arguments to (std::get<0>(args_), std::get<1>(args_)), for + // instance. + template + R CallMethod(sequence) const { + return (object_->*method_)(std::get(args_)...); + } + MethodT method_; typename detail::PointerType::type object_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; - typename rtc::remove_reference::type p3_; - typename rtc::remove_reference::type p4_; - typename rtc::remove_reference::type p5_; - typename rtc::remove_reference::type p6_; - typename rtc::remove_reference::type p7_; + typename std::tuple::type...> args_; }; -template -class Functor7 { +template +class Functor { public: - Functor7(const FunctorT& functor, - P1 p1, - P2 p2, - P3 p3, - P4 p4, - P5 p5, - P6 p6, - P7 p7) - : functor_(functor), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5), - p6_(p6), - p7_(p7) {} - R operator()() const { return functor_(p1_, p2_, p3_, p4_, p5_, p6_, p7_); } + Functor(const FunctorT& functor, Args... args) + : functor_(functor), args_(args...) {} + R operator()() const { + return CallFunction(typename sequence_generator::type()); + } private: + // Use sequence_generator (see template_util.h) to expand a Functor + // with 2 arguments to (std::get<0>(args_), std::get<1>(args_)), for + // instance. + template + R CallFunction(sequence) const { + return functor_(std::get(args_)...); + } + FunctorT functor_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; - typename rtc::remove_reference::type p3_; - typename rtc::remove_reference::type p4_; - typename rtc::remove_reference::type p5_; - typename rtc::remove_reference::type p6_; - typename rtc::remove_reference::type p7_; + typename std::tuple::type...> args_; }; -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6, P7) +#define FP_T(x) R (ObjectT::*x)(Args...) -template -MethodFunctor7 Bind( +template +MethodFunctor Bind( FP_T(method), ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6, - typename detail::identity::type p7) { - return MethodFunctor7( - method, object, p1, p2, p3, p4, p5, p6, p7); + typename detail::identity::type... args) { + return MethodFunctor(method, object, + args...); } #undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6, P7) const +#define FP_T(x) R (ObjectT::*x)(Args...) const -template -MethodFunctor7 Bind( +template +MethodFunctor Bind( FP_T(method), const ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6, - typename detail::identity::type p7) { - return MethodFunctor7(method, object, p1, p2, p3, p4, p5, p6, p7); + typename detail::identity::type... args) { + return MethodFunctor(method, object, + args...); } #undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6, P7) +#define FP_T(x) R (ObjectT::*x)(Args...) -template -MethodFunctor7 Bind( +template +MethodFunctor Bind( FP_T(method), const scoped_refptr& object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6, - typename detail::identity::type p7) { - return MethodFunctor7( - method, object.get(), p1, p2, p3, p4, p5, p6, p7); + typename detail::identity::type... args) { + return MethodFunctor(method, object.get(), + args...); } #undef FP_T -#define FP_T(x) R (*x)(P1, P2, P3, P4, P5, P6, P7) +#define FP_T(x) R (*x)(Args...) -template -Functor7 Bind( +template +Functor Bind( FP_T(function), - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6, - typename detail::identity::type p7) { - return Functor7( - function, p1, p2, p3, p4, p5, p6, p7); -} - -#undef FP_T - -template -class MethodFunctor8 { - public: - MethodFunctor8(MethodT method, - ObjectT* object, - P1 p1, - P2 p2, - P3 p3, - P4 p4, - P5 p5, - P6 p6, - P7 p7, - P8 p8) - : method_(method), - object_(object), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5), - p6_(p6), - p7_(p7), - p8_(p8) {} - R operator()() const { - return (object_->*method_)(p1_, p2_, p3_, p4_, p5_, p6_, p7_, p8_); - } - - private: - MethodT method_; - typename detail::PointerType::type object_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; - typename rtc::remove_reference::type p3_; - typename rtc::remove_reference::type p4_; - typename rtc::remove_reference::type p5_; - typename rtc::remove_reference::type p6_; - typename rtc::remove_reference::type p7_; - typename rtc::remove_reference::type p8_; -}; - -template -class Functor8 { - public: - Functor8(const FunctorT& functor, - P1 p1, - P2 p2, - P3 p3, - P4 p4, - P5 p5, - P6 p6, - P7 p7, - P8 p8) - : functor_(functor), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5), - p6_(p6), - p7_(p7), - p8_(p8) {} - R operator()() const { - return functor_(p1_, p2_, p3_, p4_, p5_, p6_, p7_, p8_); - } - - private: - FunctorT functor_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; - typename rtc::remove_reference::type p3_; - typename rtc::remove_reference::type p4_; - typename rtc::remove_reference::type p5_; - typename rtc::remove_reference::type p6_; - typename rtc::remove_reference::type p7_; - typename rtc::remove_reference::type p8_; -}; - -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6, P7, P8) - -template -MethodFunctor8 Bind( - FP_T(method), - ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6, - typename detail::identity::type p7, - typename detail::identity::type p8) { - return MethodFunctor8(method, object, p1, p2, p3, p4, p5, p6, p7, p8); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6, P7, P8) const - -template -MethodFunctor8 -Bind(FP_T(method), - const ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6, - typename detail::identity::type p7, - typename detail::identity::type p8) { - return MethodFunctor8(method, object, p1, p2, p3, p4, p5, p6, p7, p8); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6, P7, P8) - -template -MethodFunctor8 Bind( - FP_T(method), - const scoped_refptr& object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6, - typename detail::identity::type p7, - typename detail::identity::type p8) { - return MethodFunctor8(method, object.get(), p1, p2, p3, p4, p5, p6, p7, - p8); -} - -#undef FP_T -#define FP_T(x) R (*x)(P1, P2, P3, P4, P5, P6, P7, P8) - -template -Functor8 Bind( - FP_T(function), - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6, - typename detail::identity::type p7, - typename detail::identity::type p8) { - return Functor8( - function, p1, p2, p3, p4, p5, p6, p7, p8); -} - -#undef FP_T - -template -class MethodFunctor9 { - public: - MethodFunctor9(MethodT method, - ObjectT* object, - P1 p1, - P2 p2, - P3 p3, - P4 p4, - P5 p5, - P6 p6, - P7 p7, - P8 p8, - P9 p9) - : method_(method), - object_(object), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5), - p6_(p6), - p7_(p7), - p8_(p8), - p9_(p9) {} - R operator()() const { - return (object_->*method_)(p1_, p2_, p3_, p4_, p5_, p6_, p7_, p8_, p9_); - } - - private: - MethodT method_; - typename detail::PointerType::type object_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; - typename rtc::remove_reference::type p3_; - typename rtc::remove_reference::type p4_; - typename rtc::remove_reference::type p5_; - typename rtc::remove_reference::type p6_; - typename rtc::remove_reference::type p7_; - typename rtc::remove_reference::type p8_; - typename rtc::remove_reference::type p9_; -}; - -template -class Functor9 { - public: - Functor9(const FunctorT& functor, - P1 p1, - P2 p2, - P3 p3, - P4 p4, - P5 p5, - P6 p6, - P7 p7, - P8 p8, - P9 p9) - : functor_(functor), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5), - p6_(p6), - p7_(p7), - p8_(p8), - p9_(p9) {} - R operator()() const { - return functor_(p1_, p2_, p3_, p4_, p5_, p6_, p7_, p8_, p9_); - } - - private: - FunctorT functor_; - typename rtc::remove_reference::type p1_; - typename rtc::remove_reference::type p2_; - typename rtc::remove_reference::type p3_; - typename rtc::remove_reference::type p4_; - typename rtc::remove_reference::type p5_; - typename rtc::remove_reference::type p6_; - typename rtc::remove_reference::type p7_; - typename rtc::remove_reference::type p8_; - typename rtc::remove_reference::type p9_; -}; - -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6, P7, P8, P9) - -template -MethodFunctor9 -Bind(FP_T(method), - ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6, - typename detail::identity::type p7, - typename detail::identity::type p8, - typename detail::identity::type p9) { - return MethodFunctor9(method, object, p1, p2, p3, p4, p5, p6, p7, p8, - p9); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6, P7, P8, P9) const - -template -MethodFunctor9 -Bind(FP_T(method), - const ObjectT* object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6, - typename detail::identity::type p7, - typename detail::identity::type p8, - typename detail::identity::type p9) { - return MethodFunctor9(method, object, p1, p2, p3, p4, p5, p6, p7, - p8, p9); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6, P7, P8, P9) - -template -MethodFunctor9 -Bind(FP_T(method), - const scoped_refptr& object, - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6, - typename detail::identity::type p7, - typename detail::identity::type p8, - typename detail::identity::type p9) { - return MethodFunctor9(method, object.get(), p1, p2, p3, p4, p5, p6, - p7, p8, p9); -} - -#undef FP_T -#define FP_T(x) R (*x)(P1, P2, P3, P4, P5, P6, P7, P8, P9) - -template -Functor9 Bind( - FP_T(function), - typename detail::identity::type p1, - typename detail::identity::type p2, - typename detail::identity::type p3, - typename detail::identity::type p4, - typename detail::identity::type p5, - typename detail::identity::type p6, - typename detail::identity::type p7, - typename detail::identity::type p8, - typename detail::identity::type p9) { - return Functor9( - function, p1, p2, p3, p4, p5, p6, p7, p8, p9); + typename detail::identity::type... args) { + return Functor(function, args...); } #undef FP_T diff --git a/webrtc/base/bind.h.pump b/webrtc/base/bind.h.pump deleted file mode 100644 index 2a1a55c0e5..0000000000 --- a/webrtc/base/bind.h.pump +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright 2012 The WebRTC Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -// To generate bind.h from bind.h.pump, execute: -// /home/build/google3/third_party/gtest/scripts/pump.py bind.h.pump - -// Bind() is an overloaded function that converts method calls into function -// objects (aka functors). The method object is captured as a scoped_refptr<> if -// possible, and as a raw pointer otherwise. Any arguments to the method are -// captured by value. The return value of Bind is a stateful, nullary function -// object. Care should be taken about the lifetime of objects captured by -// Bind(); the returned functor knows nothing about the lifetime of a non -// ref-counted method object or any arguments passed by pointer, and calling the -// functor with a destroyed object will surely do bad things. -// -// Example usage: -// struct Foo { -// int Test1() { return 42; } -// int Test2() const { return 52; } -// int Test3(int x) { return x*x; } -// float Test4(int x, float y) { return x + y; } -// }; -// -// int main() { -// Foo foo; -// cout << rtc::Bind(&Foo::Test1, &foo)() << endl; -// cout << rtc::Bind(&Foo::Test2, &foo)() << endl; -// cout << rtc::Bind(&Foo::Test3, &foo, 3)() << endl; -// cout << rtc::Bind(&Foo::Test4, &foo, 7, 8.5f)() << endl; -// } -// -// Example usage of ref counted objects: -// struct Bar { -// int AddRef(); -// int Release(); -// -// void Test() {} -// void BindThis() { -// // The functor passed to AsyncInvoke() will keep this object alive. -// invoker.AsyncInvoke(RTC_FROM_HERE,rtc::Bind(&Bar::Test, this)); -// } -// }; -// -// int main() { -// rtc::scoped_refptr bar = new rtc::RefCountedObject(); -// auto functor = rtc::Bind(&Bar::Test, bar); -// bar = nullptr; -// // The functor stores an internal scoped_refptr, so this is safe. -// functor(); -// } -// - -#ifndef WEBRTC_BASE_BIND_H_ -#define WEBRTC_BASE_BIND_H_ - -#include "webrtc/base/scoped_ref_ptr.h" -#include "webrtc/base/template_util.h" - -#define NONAME - -namespace rtc { -namespace detail { -// This is needed because the template parameters in Bind can't be resolved -// if they're used both as parameters of the function pointer type and as -// parameters to Bind itself: the function pointer parameters are exact -// matches to the function prototype, but the parameters to bind have -// references stripped. This trick allows the compiler to dictate the Bind -// parameter types rather than deduce them. -template struct identity { typedef T type; }; - -// IsRefCounted::value will be true for types that can be used in -// rtc::scoped_refptr, i.e. types that implements nullary functions AddRef() -// and Release(), regardless of their return types. AddRef() and Release() can -// be defined in T or any superclass of T. -template -class IsRefCounted { - // This is a complex implementation detail done with SFINAE. - - // Define types such that sizeof(Yes) != sizeof(No). - struct Yes { char dummy[1]; }; - struct No { char dummy[2]; }; - // Define two overloaded template functions with return types of different - // size. This way, we can use sizeof() on the return type to determine which - // function the compiler would have chosen. One function will be preferred - // over the other if it is possible to create it without compiler errors, - // otherwise the compiler will simply remove it, and default to the less - // preferred function. - template - static Yes test(R* r, decltype(r->AddRef(), r->Release(), 42)); - template static No test(...); - -public: - // Trick the compiler to tell if it's possible to call AddRef() and Release(). - static const bool value = sizeof(test((T*)nullptr, 42)) == sizeof(Yes); -}; - -// TernaryTypeOperator is a helper class to select a type based on a static bool -// value. -template -struct TernaryTypeOperator {}; - -template -struct TernaryTypeOperator { - typedef IfTrueT type; -}; - -template -struct TernaryTypeOperator { - typedef IfFalseT type; -}; - -// PointerType::type will be scoped_refptr for ref counted types, and T* -// otherwise. -template -struct PointerType { - typedef typename TernaryTypeOperator::value, - scoped_refptr, - T*>::type type; -}; - -} // namespace detail - -$var n = 9 -$range i 0..n -$for i [[ -$range j 1..i - -template -class MethodFunctor$i { - public: - MethodFunctor$i(MethodT method, ObjectT* object$for j [[, - P$j p$j]]) - : method_(method), object_(object)$for j [[, - p$(j)_(p$j)]] {} - R operator()() const { - return (object_->*method_)($for j , [[p$(j)_]]); } - private: - MethodT method_; - typename detail::PointerType::type object_;$for j [[ - - typename rtc::remove_reference::type p$(j)_;]] - -}; - -template -class Functor$i { - public: - $if i == 0 [[explicit ]] -Functor$i(const FunctorT& functor$for j [[, P$j p$j]]) - : functor_(functor)$for j [[, - p$(j)_(p$j)]] {} - R operator()() const { - return functor_($for j , [[p$(j)_]]); } - private: - FunctorT functor_;$for j [[ - - typename rtc::remove_reference::type p$(j)_;]] - -}; - - -#define FP_T(x) R (ObjectT::*x)($for j , [[P$j]]) - -template -MethodFunctor$i -Bind(FP_T(method), ObjectT* object$for j [[, - typename detail::identity::type p$j]]) { - return MethodFunctor$i( - method, object$for j [[, p$j]]); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)($for j , [[P$j]]) const - -template -MethodFunctor$i -Bind(FP_T(method), const ObjectT* object$for j [[, - typename detail::identity::type p$j]]) { - return MethodFunctor$i( - method, object$for j [[, p$j]]); -} - -#undef FP_T -#define FP_T(x) R (ObjectT::*x)($for j , [[P$j]]) - -template -MethodFunctor$i -Bind(FP_T(method), const scoped_refptr& object$for j [[, - typename detail::identity::type p$j]]) { - return MethodFunctor$i( - method, object.get()$for j [[, p$j]]); -} - -#undef FP_T -#define FP_T(x) R (*x)($for j , [[P$j]]) - -template -Functor$i -Bind(FP_T(function)$for j [[, - typename detail::identity::type p$j]]) { - return Functor$i( - function$for j [[, p$j]]); -} - -#undef FP_T - -]] - -} // namespace rtc - -#undef NONAME - -#endif // WEBRTC_BASE_BIND_H_ diff --git a/webrtc/base/bind_unittest.cc b/webrtc/base/bind_unittest.cc index be8d79cb6a..33315912bf 100644 --- a/webrtc/base/bind_unittest.cc +++ b/webrtc/base/bind_unittest.cc @@ -8,6 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include + #include "webrtc/base/bind.h" #include "webrtc/base/gunit.h" @@ -71,26 +73,6 @@ int Multiply(int a, int b) { return a * b; } // Try to catch any problem with scoped_refptr type deduction in rtc::Bind at // compile time. -static_assert( - is_same< - rtc::remove_reference&>::type, - const scoped_refptr>::value, - "const scoped_refptr& should be captured by value"); - -static_assert(is_same&>::type, - const scoped_refptr>::value, - "const scoped_refptr& should be captured by value"); - -static_assert( - is_same::type, const int>::value, - "const int& should be captured as const int"); - -static_assert(is_same::type, const F>::value, - "const F& should be captured as const F"); - -static_assert(is_same::type, F>::value, - "F& should be captured as F"); - #define EXPECT_IS_CAPTURED_AS_PTR(T) \ static_assert(is_same::type, T*>::value, \ "PointerType") diff --git a/webrtc/base/template_util.h b/webrtc/base/template_util.h index 31464cf35d..f3565a4c91 100644 --- a/webrtc/base/template_util.h +++ b/webrtc/base/template_util.h @@ -48,17 +48,17 @@ template struct is_non_const_reference : false_type {}; template struct is_void : false_type {}; template <> struct is_void : true_type {}; -template -struct remove_reference { - typedef T type; -}; -template -struct remove_reference { - typedef T type; -}; -template -struct remove_reference { - typedef T type; +// Helper useful for converting a tuple to variadic template function +// arguments. +// +// sequence_generator<3>::type will be sequence<0, 1, 2>. +template +struct sequence {}; +template +struct sequence_generator : sequence_generator {}; +template +struct sequence_generator<0, S...> { + typedef sequence type; }; namespace internal { diff --git a/webrtc/pc/ortcfactory.cc b/webrtc/pc/ortcfactory.cc index 47d39b7cb0..aa5e1819fb 100644 --- a/webrtc/pc/ortcfactory.cc +++ b/webrtc/pc/ortcfactory.cc @@ -28,10 +28,16 @@ std::unique_ptr OrtcFactoryInterface::Create( rtc::PacketSocketFactory* socket_factory) { // Hop to signaling thread if needed. if (signaling_thread && !signaling_thread->IsCurrent()) { + // The template parameters are necessary because there are two + // OrtcFactoryInterface::Create methods, so the types can't be derived from + // just the function pointer. return signaling_thread->Invoke>( RTC_FROM_HERE, - rtc::Bind(&OrtcFactoryInterface::Create, network_thread, - signaling_thread, network_manager, socket_factory)); + rtc::Bind, rtc::Thread*, + rtc::Thread*, rtc::NetworkManager*, + rtc::PacketSocketFactory*>(&OrtcFactoryInterface::Create, + network_thread, signaling_thread, + network_manager, socket_factory)); } OrtcFactory* new_factory = new OrtcFactory(network_thread, signaling_thread,