henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | // This file was GENERATED by command: |
| 2 | // pump.py bind.h.pump |
| 3 | // DO NOT EDIT BY HAND!!! |
| 4 | |
| 5 | /* |
| 6 | * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
| 7 | * |
| 8 | * Use of this source code is governed by a BSD-style license |
| 9 | * that can be found in the LICENSE file in the root of the source |
| 10 | * tree. An additional intellectual property rights grant can be found |
| 11 | * in the file PATENTS. All contributing project authors may |
| 12 | * be found in the AUTHORS file in the root of the source tree. |
| 13 | */ |
| 14 | |
| 15 | // To generate bind.h from bind.h.pump, execute: |
| 16 | // /home/build/google3/third_party/gtest/scripts/pump.py bind.h.pump |
| 17 | |
| 18 | // Bind() is an overloaded function that converts method calls into function |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 19 | // objects (aka functors). The method object is captured as a scoped_refptr<> if |
| 20 | // possible, and as a raw pointer otherwise. Any arguments to the method are |
| 21 | // captured by value. The return value of Bind is a stateful, nullary function |
| 22 | // object. Care should be taken about the lifetime of objects captured by |
| 23 | // Bind(); the returned functor knows nothing about the lifetime of a non |
| 24 | // ref-counted method object or any arguments passed by pointer, and calling the |
| 25 | // functor with a destroyed object will surely do bad things. |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 26 | // |
| 27 | // Example usage: |
| 28 | // struct Foo { |
| 29 | // int Test1() { return 42; } |
| 30 | // int Test2() const { return 52; } |
| 31 | // int Test3(int x) { return x*x; } |
| 32 | // float Test4(int x, float y) { return x + y; } |
| 33 | // }; |
| 34 | // |
| 35 | // int main() { |
| 36 | // Foo foo; |
| 37 | // cout << rtc::Bind(&Foo::Test1, &foo)() << endl; |
| 38 | // cout << rtc::Bind(&Foo::Test2, &foo)() << endl; |
| 39 | // cout << rtc::Bind(&Foo::Test3, &foo, 3)() << endl; |
| 40 | // cout << rtc::Bind(&Foo::Test4, &foo, 7, 8.5f)() << endl; |
| 41 | // } |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 42 | // |
| 43 | // Example usage of ref counted objects: |
| 44 | // struct Bar { |
| 45 | // int AddRef(); |
| 46 | // int Release(); |
| 47 | // |
| 48 | // void Test() {} |
| 49 | // void BindThis() { |
| 50 | // // The functor passed to AsyncInvoke() will keep this object alive. |
| 51 | // invoker.AsyncInvoke(rtc::Bind(&Bar::Test, this)); |
| 52 | // } |
| 53 | // }; |
| 54 | // |
| 55 | // int main() { |
| 56 | // rtc::scoped_refptr<Bar> bar = new rtc::RefCountedObject<Bar>(); |
| 57 | // auto functor = rtc::Bind(&Bar::Test, bar); |
| 58 | // bar = nullptr; |
| 59 | // // The functor stores an internal scoped_refptr<Bar>, so this is safe. |
| 60 | // functor(); |
| 61 | // } |
| 62 | // |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 63 | |
| 64 | #ifndef WEBRTC_BASE_BIND_H_ |
| 65 | #define WEBRTC_BASE_BIND_H_ |
| 66 | |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 67 | #include "webrtc/base/scoped_ref_ptr.h" |
| 68 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 69 | #define NONAME |
| 70 | |
| 71 | namespace rtc { |
| 72 | namespace detail { |
| 73 | // This is needed because the template parameters in Bind can't be resolved |
| 74 | // if they're used both as parameters of the function pointer type and as |
| 75 | // parameters to Bind itself: the function pointer parameters are exact |
| 76 | // matches to the function prototype, but the parameters to bind have |
| 77 | // references stripped. This trick allows the compiler to dictate the Bind |
| 78 | // parameter types rather than deduce them. |
| 79 | template <class T> struct identity { typedef T type; }; |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 80 | |
| 81 | // IsRefCounted<T>::value will be true for types that can be used in |
| 82 | // rtc::scoped_refptr<T>, i.e. types that implements nullary functions AddRef() |
| 83 | // and Release(), regardless of their return types. AddRef() and Release() can |
| 84 | // be defined in T or any superclass of T. |
| 85 | template <typename T> |
| 86 | class IsRefCounted { |
| 87 | // This is a complex implementation detail done with SFINAE. |
| 88 | |
| 89 | // Define types such that sizeof(Yes) != sizeof(No). |
| 90 | struct Yes { char dummy[1]; }; |
| 91 | struct No { char dummy[2]; }; |
| 92 | // Define two overloaded template functions with return types of different |
| 93 | // size. This way, we can use sizeof() on the return type to determine which |
| 94 | // function the compiler would have chosen. One function will be preferred |
| 95 | // over the other if it is possible to create it without compiler errors, |
| 96 | // otherwise the compiler will simply remove it, and default to the less |
| 97 | // preferred function. |
| 98 | template <typename R> |
| 99 | static Yes test(R* r, decltype(r->AddRef(), r->Release(), 42)); |
| 100 | template <typename C> static No test(...); |
| 101 | |
| 102 | public: |
| 103 | // Trick the compiler to tell if it's possible to call AddRef() and Release(). |
| 104 | static const bool value = sizeof(test<T>((T*)nullptr, 42)) == sizeof(Yes); |
| 105 | }; |
| 106 | |
| 107 | // TernaryTypeOperator is a helper class to select a type based on a static bool |
| 108 | // value. |
| 109 | template <bool condition, typename IfTrueT, typename IfFalseT> |
| 110 | struct TernaryTypeOperator {}; |
| 111 | |
| 112 | template <typename IfTrueT, typename IfFalseT> |
| 113 | struct TernaryTypeOperator<true, IfTrueT, IfFalseT> { |
| 114 | typedef IfTrueT type; |
| 115 | }; |
| 116 | |
| 117 | template <typename IfTrueT, typename IfFalseT> |
| 118 | struct TernaryTypeOperator<false, IfTrueT, IfFalseT> { |
| 119 | typedef IfFalseT type; |
| 120 | }; |
| 121 | |
| 122 | // PointerType<T>::type will be scoped_refptr<T> for ref counted types, and T* |
| 123 | // otherwise. |
| 124 | template <class T> |
| 125 | struct PointerType { |
| 126 | typedef typename TernaryTypeOperator<IsRefCounted<T>::value, |
| 127 | scoped_refptr<T>, |
| 128 | T*>::type type; |
| 129 | }; |
| 130 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 131 | } // namespace detail |
| 132 | |
| 133 | template <class ObjectT, class MethodT, class R> |
| 134 | class MethodFunctor0 { |
| 135 | public: |
| 136 | MethodFunctor0(MethodT method, ObjectT* object) |
| 137 | : method_(method), object_(object) {} |
| 138 | R operator()() const { |
| 139 | return (object_->*method_)(); } |
| 140 | private: |
| 141 | MethodT method_; |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 142 | typename detail::PointerType<ObjectT>::type object_; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | template <class FunctorT, class R> |
| 146 | class Functor0 { |
| 147 | public: |
| 148 | explicit Functor0(const FunctorT& functor) |
| 149 | : functor_(functor) {} |
| 150 | R operator()() const { |
| 151 | return functor_(); } |
| 152 | private: |
| 153 | FunctorT functor_; |
| 154 | }; |
| 155 | |
| 156 | |
| 157 | #define FP_T(x) R (ObjectT::*x)() |
| 158 | |
| 159 | template <class ObjectT, class R> |
| 160 | MethodFunctor0<ObjectT, FP_T(NONAME), R> |
| 161 | Bind(FP_T(method), ObjectT* object) { |
| 162 | return MethodFunctor0<ObjectT, FP_T(NONAME), R>( |
| 163 | method, object); |
| 164 | } |
| 165 | |
| 166 | #undef FP_T |
| 167 | #define FP_T(x) R (ObjectT::*x)() const |
| 168 | |
| 169 | template <class ObjectT, class R> |
| 170 | MethodFunctor0<const ObjectT, FP_T(NONAME), R> |
| 171 | Bind(FP_T(method), const ObjectT* object) { |
| 172 | return MethodFunctor0<const ObjectT, FP_T(NONAME), R>( |
| 173 | method, object); |
| 174 | } |
| 175 | |
| 176 | #undef FP_T |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 177 | #define FP_T(x) R (ObjectT::*x)() |
| 178 | |
| 179 | template <class ObjectT, class R> |
| 180 | MethodFunctor0<ObjectT, FP_T(NONAME), R> |
| 181 | Bind(FP_T(method), const scoped_refptr<ObjectT>& object) { |
| 182 | return MethodFunctor0<ObjectT, FP_T(NONAME), R>( |
| 183 | method, object.get()); |
| 184 | } |
| 185 | |
| 186 | #undef FP_T |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 187 | #define FP_T(x) R (*x)() |
| 188 | |
| 189 | template <class R> |
| 190 | Functor0<FP_T(NONAME), R> |
| 191 | Bind(FP_T(function)) { |
| 192 | return Functor0<FP_T(NONAME), R>( |
| 193 | function); |
| 194 | } |
| 195 | |
| 196 | #undef FP_T |
| 197 | |
| 198 | template <class ObjectT, class MethodT, class R, |
| 199 | class P1> |
| 200 | class MethodFunctor1 { |
| 201 | public: |
| 202 | MethodFunctor1(MethodT method, ObjectT* object, |
| 203 | P1 p1) |
| 204 | : method_(method), object_(object), |
| 205 | p1_(p1) {} |
| 206 | R operator()() const { |
| 207 | return (object_->*method_)(p1_); } |
| 208 | private: |
| 209 | MethodT method_; |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 210 | typename detail::PointerType<ObjectT>::type object_; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 211 | P1 p1_; |
| 212 | }; |
| 213 | |
| 214 | template <class FunctorT, class R, |
| 215 | class P1> |
| 216 | class Functor1 { |
| 217 | public: |
| 218 | Functor1(const FunctorT& functor, P1 p1) |
| 219 | : functor_(functor), |
| 220 | p1_(p1) {} |
| 221 | R operator()() const { |
| 222 | return functor_(p1_); } |
| 223 | private: |
| 224 | FunctorT functor_; |
| 225 | P1 p1_; |
| 226 | }; |
| 227 | |
| 228 | |
| 229 | #define FP_T(x) R (ObjectT::*x)(P1) |
| 230 | |
| 231 | template <class ObjectT, class R, |
| 232 | class P1> |
| 233 | MethodFunctor1<ObjectT, FP_T(NONAME), R, P1> |
| 234 | Bind(FP_T(method), ObjectT* object, |
| 235 | typename detail::identity<P1>::type p1) { |
| 236 | return MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>( |
| 237 | method, object, p1); |
| 238 | } |
| 239 | |
| 240 | #undef FP_T |
| 241 | #define FP_T(x) R (ObjectT::*x)(P1) const |
| 242 | |
| 243 | template <class ObjectT, class R, |
| 244 | class P1> |
| 245 | MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1> |
| 246 | Bind(FP_T(method), const ObjectT* object, |
| 247 | typename detail::identity<P1>::type p1) { |
| 248 | return MethodFunctor1<const ObjectT, FP_T(NONAME), R, P1>( |
| 249 | method, object, p1); |
| 250 | } |
| 251 | |
| 252 | #undef FP_T |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 253 | #define FP_T(x) R (ObjectT::*x)(P1) |
| 254 | |
| 255 | template <class ObjectT, class R, |
| 256 | class P1> |
| 257 | MethodFunctor1<ObjectT, FP_T(NONAME), R, P1> |
| 258 | Bind(FP_T(method), const scoped_refptr<ObjectT>& object, |
| 259 | typename detail::identity<P1>::type p1) { |
| 260 | return MethodFunctor1<ObjectT, FP_T(NONAME), R, P1>( |
| 261 | method, object.get(), p1); |
| 262 | } |
| 263 | |
| 264 | #undef FP_T |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 265 | #define FP_T(x) R (*x)(P1) |
| 266 | |
| 267 | template <class R, |
| 268 | class P1> |
| 269 | Functor1<FP_T(NONAME), R, P1> |
| 270 | Bind(FP_T(function), |
| 271 | typename detail::identity<P1>::type p1) { |
| 272 | return Functor1<FP_T(NONAME), R, P1>( |
| 273 | function, p1); |
| 274 | } |
| 275 | |
| 276 | #undef FP_T |
| 277 | |
| 278 | template <class ObjectT, class MethodT, class R, |
| 279 | class P1, |
| 280 | class P2> |
| 281 | class MethodFunctor2 { |
| 282 | public: |
| 283 | MethodFunctor2(MethodT method, ObjectT* object, |
| 284 | P1 p1, |
| 285 | P2 p2) |
| 286 | : method_(method), object_(object), |
| 287 | p1_(p1), |
| 288 | p2_(p2) {} |
| 289 | R operator()() const { |
| 290 | return (object_->*method_)(p1_, p2_); } |
| 291 | private: |
| 292 | MethodT method_; |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 293 | typename detail::PointerType<ObjectT>::type object_; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 294 | P1 p1_; |
| 295 | P2 p2_; |
| 296 | }; |
| 297 | |
| 298 | template <class FunctorT, class R, |
| 299 | class P1, |
| 300 | class P2> |
| 301 | class Functor2 { |
| 302 | public: |
| 303 | Functor2(const FunctorT& functor, P1 p1, P2 p2) |
| 304 | : functor_(functor), |
| 305 | p1_(p1), |
| 306 | p2_(p2) {} |
| 307 | R operator()() const { |
| 308 | return functor_(p1_, p2_); } |
| 309 | private: |
| 310 | FunctorT functor_; |
| 311 | P1 p1_; |
| 312 | P2 p2_; |
| 313 | }; |
| 314 | |
| 315 | |
| 316 | #define FP_T(x) R (ObjectT::*x)(P1, P2) |
| 317 | |
| 318 | template <class ObjectT, class R, |
| 319 | class P1, |
| 320 | class P2> |
| 321 | MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2> |
| 322 | Bind(FP_T(method), ObjectT* object, |
| 323 | typename detail::identity<P1>::type p1, |
| 324 | typename detail::identity<P2>::type p2) { |
| 325 | return MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>( |
| 326 | method, object, p1, p2); |
| 327 | } |
| 328 | |
| 329 | #undef FP_T |
| 330 | #define FP_T(x) R (ObjectT::*x)(P1, P2) const |
| 331 | |
| 332 | template <class ObjectT, class R, |
| 333 | class P1, |
| 334 | class P2> |
| 335 | MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2> |
| 336 | Bind(FP_T(method), const ObjectT* object, |
| 337 | typename detail::identity<P1>::type p1, |
| 338 | typename detail::identity<P2>::type p2) { |
| 339 | return MethodFunctor2<const ObjectT, FP_T(NONAME), R, P1, P2>( |
| 340 | method, object, p1, p2); |
| 341 | } |
| 342 | |
| 343 | #undef FP_T |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 344 | #define FP_T(x) R (ObjectT::*x)(P1, P2) |
| 345 | |
| 346 | template <class ObjectT, class R, |
| 347 | class P1, |
| 348 | class P2> |
| 349 | MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2> |
| 350 | Bind(FP_T(method), const scoped_refptr<ObjectT>& object, |
| 351 | typename detail::identity<P1>::type p1, |
| 352 | typename detail::identity<P2>::type p2) { |
| 353 | return MethodFunctor2<ObjectT, FP_T(NONAME), R, P1, P2>( |
| 354 | method, object.get(), p1, p2); |
| 355 | } |
| 356 | |
| 357 | #undef FP_T |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 358 | #define FP_T(x) R (*x)(P1, P2) |
| 359 | |
| 360 | template <class R, |
| 361 | class P1, |
| 362 | class P2> |
| 363 | Functor2<FP_T(NONAME), R, P1, P2> |
| 364 | Bind(FP_T(function), |
| 365 | typename detail::identity<P1>::type p1, |
| 366 | typename detail::identity<P2>::type p2) { |
| 367 | return Functor2<FP_T(NONAME), R, P1, P2>( |
| 368 | function, p1, p2); |
| 369 | } |
| 370 | |
| 371 | #undef FP_T |
| 372 | |
| 373 | template <class ObjectT, class MethodT, class R, |
| 374 | class P1, |
| 375 | class P2, |
| 376 | class P3> |
| 377 | class MethodFunctor3 { |
| 378 | public: |
| 379 | MethodFunctor3(MethodT method, ObjectT* object, |
| 380 | P1 p1, |
| 381 | P2 p2, |
| 382 | P3 p3) |
| 383 | : method_(method), object_(object), |
| 384 | p1_(p1), |
| 385 | p2_(p2), |
| 386 | p3_(p3) {} |
| 387 | R operator()() const { |
| 388 | return (object_->*method_)(p1_, p2_, p3_); } |
| 389 | private: |
| 390 | MethodT method_; |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 391 | typename detail::PointerType<ObjectT>::type object_; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 392 | P1 p1_; |
| 393 | P2 p2_; |
| 394 | P3 p3_; |
| 395 | }; |
| 396 | |
| 397 | template <class FunctorT, class R, |
| 398 | class P1, |
| 399 | class P2, |
| 400 | class P3> |
| 401 | class Functor3 { |
| 402 | public: |
| 403 | Functor3(const FunctorT& functor, P1 p1, P2 p2, P3 p3) |
| 404 | : functor_(functor), |
| 405 | p1_(p1), |
| 406 | p2_(p2), |
| 407 | p3_(p3) {} |
| 408 | R operator()() const { |
| 409 | return functor_(p1_, p2_, p3_); } |
| 410 | private: |
| 411 | FunctorT functor_; |
| 412 | P1 p1_; |
| 413 | P2 p2_; |
| 414 | P3 p3_; |
| 415 | }; |
| 416 | |
| 417 | |
| 418 | #define FP_T(x) R (ObjectT::*x)(P1, P2, P3) |
| 419 | |
| 420 | template <class ObjectT, class R, |
| 421 | class P1, |
| 422 | class P2, |
| 423 | class P3> |
| 424 | MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3> |
| 425 | Bind(FP_T(method), ObjectT* object, |
| 426 | typename detail::identity<P1>::type p1, |
| 427 | typename detail::identity<P2>::type p2, |
| 428 | typename detail::identity<P3>::type p3) { |
| 429 | return MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>( |
| 430 | method, object, p1, p2, p3); |
| 431 | } |
| 432 | |
| 433 | #undef FP_T |
| 434 | #define FP_T(x) R (ObjectT::*x)(P1, P2, P3) const |
| 435 | |
| 436 | template <class ObjectT, class R, |
| 437 | class P1, |
| 438 | class P2, |
| 439 | class P3> |
| 440 | MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3> |
| 441 | Bind(FP_T(method), const ObjectT* object, |
| 442 | typename detail::identity<P1>::type p1, |
| 443 | typename detail::identity<P2>::type p2, |
| 444 | typename detail::identity<P3>::type p3) { |
| 445 | return MethodFunctor3<const ObjectT, FP_T(NONAME), R, P1, P2, P3>( |
| 446 | method, object, p1, p2, p3); |
| 447 | } |
| 448 | |
| 449 | #undef FP_T |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 450 | #define FP_T(x) R (ObjectT::*x)(P1, P2, P3) |
| 451 | |
| 452 | template <class ObjectT, class R, |
| 453 | class P1, |
| 454 | class P2, |
| 455 | class P3> |
| 456 | MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3> |
| 457 | Bind(FP_T(method), const scoped_refptr<ObjectT>& object, |
| 458 | typename detail::identity<P1>::type p1, |
| 459 | typename detail::identity<P2>::type p2, |
| 460 | typename detail::identity<P3>::type p3) { |
| 461 | return MethodFunctor3<ObjectT, FP_T(NONAME), R, P1, P2, P3>( |
| 462 | method, object.get(), p1, p2, p3); |
| 463 | } |
| 464 | |
| 465 | #undef FP_T |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 466 | #define FP_T(x) R (*x)(P1, P2, P3) |
| 467 | |
| 468 | template <class R, |
| 469 | class P1, |
| 470 | class P2, |
| 471 | class P3> |
| 472 | Functor3<FP_T(NONAME), R, P1, P2, P3> |
| 473 | Bind(FP_T(function), |
| 474 | typename detail::identity<P1>::type p1, |
| 475 | typename detail::identity<P2>::type p2, |
| 476 | typename detail::identity<P3>::type p3) { |
| 477 | return Functor3<FP_T(NONAME), R, P1, P2, P3>( |
| 478 | function, p1, p2, p3); |
| 479 | } |
| 480 | |
| 481 | #undef FP_T |
| 482 | |
| 483 | template <class ObjectT, class MethodT, class R, |
| 484 | class P1, |
| 485 | class P2, |
| 486 | class P3, |
| 487 | class P4> |
| 488 | class MethodFunctor4 { |
| 489 | public: |
| 490 | MethodFunctor4(MethodT method, ObjectT* object, |
| 491 | P1 p1, |
| 492 | P2 p2, |
| 493 | P3 p3, |
| 494 | P4 p4) |
| 495 | : method_(method), object_(object), |
| 496 | p1_(p1), |
| 497 | p2_(p2), |
| 498 | p3_(p3), |
| 499 | p4_(p4) {} |
| 500 | R operator()() const { |
| 501 | return (object_->*method_)(p1_, p2_, p3_, p4_); } |
| 502 | private: |
| 503 | MethodT method_; |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 504 | typename detail::PointerType<ObjectT>::type object_; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 505 | P1 p1_; |
| 506 | P2 p2_; |
| 507 | P3 p3_; |
| 508 | P4 p4_; |
| 509 | }; |
| 510 | |
| 511 | template <class FunctorT, class R, |
| 512 | class P1, |
| 513 | class P2, |
| 514 | class P3, |
| 515 | class P4> |
| 516 | class Functor4 { |
| 517 | public: |
| 518 | Functor4(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4) |
| 519 | : functor_(functor), |
| 520 | p1_(p1), |
| 521 | p2_(p2), |
| 522 | p3_(p3), |
| 523 | p4_(p4) {} |
| 524 | R operator()() const { |
| 525 | return functor_(p1_, p2_, p3_, p4_); } |
| 526 | private: |
| 527 | FunctorT functor_; |
| 528 | P1 p1_; |
| 529 | P2 p2_; |
| 530 | P3 p3_; |
| 531 | P4 p4_; |
| 532 | }; |
| 533 | |
| 534 | |
| 535 | #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4) |
| 536 | |
| 537 | template <class ObjectT, class R, |
| 538 | class P1, |
| 539 | class P2, |
| 540 | class P3, |
| 541 | class P4> |
| 542 | MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4> |
| 543 | Bind(FP_T(method), ObjectT* object, |
| 544 | typename detail::identity<P1>::type p1, |
| 545 | typename detail::identity<P2>::type p2, |
| 546 | typename detail::identity<P3>::type p3, |
| 547 | typename detail::identity<P4>::type p4) { |
| 548 | return MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>( |
| 549 | method, object, p1, p2, p3, p4); |
| 550 | } |
| 551 | |
| 552 | #undef FP_T |
| 553 | #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4) const |
| 554 | |
| 555 | template <class ObjectT, class R, |
| 556 | class P1, |
| 557 | class P2, |
| 558 | class P3, |
| 559 | class P4> |
| 560 | MethodFunctor4<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4> |
| 561 | Bind(FP_T(method), const ObjectT* object, |
| 562 | typename detail::identity<P1>::type p1, |
| 563 | typename detail::identity<P2>::type p2, |
| 564 | typename detail::identity<P3>::type p3, |
| 565 | typename detail::identity<P4>::type p4) { |
| 566 | return MethodFunctor4<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>( |
| 567 | method, object, p1, p2, p3, p4); |
| 568 | } |
| 569 | |
| 570 | #undef FP_T |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 571 | #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4) |
| 572 | |
| 573 | template <class ObjectT, class R, |
| 574 | class P1, |
| 575 | class P2, |
| 576 | class P3, |
| 577 | class P4> |
| 578 | MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4> |
| 579 | Bind(FP_T(method), const scoped_refptr<ObjectT>& object, |
| 580 | typename detail::identity<P1>::type p1, |
| 581 | typename detail::identity<P2>::type p2, |
| 582 | typename detail::identity<P3>::type p3, |
| 583 | typename detail::identity<P4>::type p4) { |
| 584 | return MethodFunctor4<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4>( |
| 585 | method, object.get(), p1, p2, p3, p4); |
| 586 | } |
| 587 | |
| 588 | #undef FP_T |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 589 | #define FP_T(x) R (*x)(P1, P2, P3, P4) |
| 590 | |
| 591 | template <class R, |
| 592 | class P1, |
| 593 | class P2, |
| 594 | class P3, |
| 595 | class P4> |
| 596 | Functor4<FP_T(NONAME), R, P1, P2, P3, P4> |
| 597 | Bind(FP_T(function), |
| 598 | typename detail::identity<P1>::type p1, |
| 599 | typename detail::identity<P2>::type p2, |
| 600 | typename detail::identity<P3>::type p3, |
| 601 | typename detail::identity<P4>::type p4) { |
| 602 | return Functor4<FP_T(NONAME), R, P1, P2, P3, P4>( |
| 603 | function, p1, p2, p3, p4); |
| 604 | } |
| 605 | |
| 606 | #undef FP_T |
| 607 | |
| 608 | template <class ObjectT, class MethodT, class R, |
| 609 | class P1, |
| 610 | class P2, |
| 611 | class P3, |
| 612 | class P4, |
| 613 | class P5> |
| 614 | class MethodFunctor5 { |
| 615 | public: |
| 616 | MethodFunctor5(MethodT method, ObjectT* object, |
| 617 | P1 p1, |
| 618 | P2 p2, |
| 619 | P3 p3, |
| 620 | P4 p4, |
| 621 | P5 p5) |
| 622 | : method_(method), object_(object), |
| 623 | p1_(p1), |
| 624 | p2_(p2), |
| 625 | p3_(p3), |
| 626 | p4_(p4), |
| 627 | p5_(p5) {} |
| 628 | R operator()() const { |
| 629 | return (object_->*method_)(p1_, p2_, p3_, p4_, p5_); } |
| 630 | private: |
| 631 | MethodT method_; |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 632 | typename detail::PointerType<ObjectT>::type object_; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 633 | P1 p1_; |
| 634 | P2 p2_; |
| 635 | P3 p3_; |
| 636 | P4 p4_; |
| 637 | P5 p5_; |
| 638 | }; |
| 639 | |
| 640 | template <class FunctorT, class R, |
| 641 | class P1, |
| 642 | class P2, |
| 643 | class P3, |
| 644 | class P4, |
| 645 | class P5> |
| 646 | class Functor5 { |
| 647 | public: |
| 648 | Functor5(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) |
| 649 | : functor_(functor), |
| 650 | p1_(p1), |
| 651 | p2_(p2), |
| 652 | p3_(p3), |
| 653 | p4_(p4), |
| 654 | p5_(p5) {} |
| 655 | R operator()() const { |
| 656 | return functor_(p1_, p2_, p3_, p4_, p5_); } |
| 657 | private: |
| 658 | FunctorT functor_; |
| 659 | P1 p1_; |
| 660 | P2 p2_; |
| 661 | P3 p3_; |
| 662 | P4 p4_; |
| 663 | P5 p5_; |
| 664 | }; |
| 665 | |
| 666 | |
| 667 | #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5) |
| 668 | |
| 669 | template <class ObjectT, class R, |
| 670 | class P1, |
| 671 | class P2, |
| 672 | class P3, |
| 673 | class P4, |
| 674 | class P5> |
| 675 | MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5> |
| 676 | Bind(FP_T(method), ObjectT* object, |
| 677 | typename detail::identity<P1>::type p1, |
| 678 | typename detail::identity<P2>::type p2, |
| 679 | typename detail::identity<P3>::type p3, |
| 680 | typename detail::identity<P4>::type p4, |
| 681 | typename detail::identity<P5>::type p5) { |
| 682 | return MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>( |
| 683 | method, object, p1, p2, p3, p4, p5); |
| 684 | } |
| 685 | |
| 686 | #undef FP_T |
| 687 | #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5) const |
| 688 | |
| 689 | template <class ObjectT, class R, |
| 690 | class P1, |
| 691 | class P2, |
| 692 | class P3, |
| 693 | class P4, |
| 694 | class P5> |
| 695 | MethodFunctor5<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5> |
| 696 | Bind(FP_T(method), const ObjectT* object, |
| 697 | typename detail::identity<P1>::type p1, |
| 698 | typename detail::identity<P2>::type p2, |
| 699 | typename detail::identity<P3>::type p3, |
| 700 | typename detail::identity<P4>::type p4, |
| 701 | typename detail::identity<P5>::type p5) { |
| 702 | return MethodFunctor5<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>( |
| 703 | method, object, p1, p2, p3, p4, p5); |
| 704 | } |
| 705 | |
| 706 | #undef FP_T |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 707 | #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5) |
| 708 | |
| 709 | template <class ObjectT, class R, |
| 710 | class P1, |
| 711 | class P2, |
| 712 | class P3, |
| 713 | class P4, |
| 714 | class P5> |
| 715 | MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5> |
| 716 | Bind(FP_T(method), const scoped_refptr<ObjectT>& object, |
| 717 | typename detail::identity<P1>::type p1, |
| 718 | typename detail::identity<P2>::type p2, |
| 719 | typename detail::identity<P3>::type p3, |
| 720 | typename detail::identity<P4>::type p4, |
| 721 | typename detail::identity<P5>::type p5) { |
| 722 | return MethodFunctor5<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5>( |
| 723 | method, object.get(), p1, p2, p3, p4, p5); |
| 724 | } |
| 725 | |
| 726 | #undef FP_T |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 727 | #define FP_T(x) R (*x)(P1, P2, P3, P4, P5) |
| 728 | |
| 729 | template <class R, |
| 730 | class P1, |
| 731 | class P2, |
| 732 | class P3, |
| 733 | class P4, |
| 734 | class P5> |
| 735 | Functor5<FP_T(NONAME), R, P1, P2, P3, P4, P5> |
| 736 | Bind(FP_T(function), |
| 737 | typename detail::identity<P1>::type p1, |
| 738 | typename detail::identity<P2>::type p2, |
| 739 | typename detail::identity<P3>::type p3, |
| 740 | typename detail::identity<P4>::type p4, |
| 741 | typename detail::identity<P5>::type p5) { |
| 742 | return Functor5<FP_T(NONAME), R, P1, P2, P3, P4, P5>( |
| 743 | function, p1, p2, p3, p4, p5); |
| 744 | } |
| 745 | |
| 746 | #undef FP_T |
Fredrik Solenberg | c937139 | 2015-08-06 12:40:53 +0200 | [diff] [blame] | 747 | |
| 748 | template <class ObjectT, class MethodT, class R, |
Jelena Marusic | 5d6e58e | 2015-07-13 11:16:39 +0200 | [diff] [blame] | 749 | class P1, |
| 750 | class P2, |
| 751 | class P3, |
| 752 | class P4, |
| 753 | class P5, |
| 754 | class P6> |
| 755 | class MethodFunctor6 { |
| 756 | public: |
Fredrik Solenberg | c937139 | 2015-08-06 12:40:53 +0200 | [diff] [blame] | 757 | MethodFunctor6(MethodT method, ObjectT* object, |
Jelena Marusic | 5d6e58e | 2015-07-13 11:16:39 +0200 | [diff] [blame] | 758 | P1 p1, |
| 759 | P2 p2, |
| 760 | P3 p3, |
| 761 | P4 p4, |
| 762 | P5 p5, |
| 763 | P6 p6) |
Fredrik Solenberg | c937139 | 2015-08-06 12:40:53 +0200 | [diff] [blame] | 764 | : method_(method), object_(object), |
| 765 | p1_(p1), |
| 766 | p2_(p2), |
| 767 | p3_(p3), |
| 768 | p4_(p4), |
| 769 | p5_(p5), |
| 770 | p6_(p6) {} |
Jelena Marusic | 5d6e58e | 2015-07-13 11:16:39 +0200 | [diff] [blame] | 771 | R operator()() const { |
Fredrik Solenberg | c937139 | 2015-08-06 12:40:53 +0200 | [diff] [blame] | 772 | return (object_->*method_)(p1_, p2_, p3_, p4_, p5_, p6_); } |
Jelena Marusic | 5d6e58e | 2015-07-13 11:16:39 +0200 | [diff] [blame] | 773 | private: |
| 774 | MethodT method_; |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 775 | typename detail::PointerType<ObjectT>::type object_; |
Jelena Marusic | 5d6e58e | 2015-07-13 11:16:39 +0200 | [diff] [blame] | 776 | P1 p1_; |
| 777 | P2 p2_; |
| 778 | P3 p3_; |
| 779 | P4 p4_; |
| 780 | P5 p5_; |
| 781 | P6 p6_; |
| 782 | }; |
| 783 | |
Fredrik Solenberg | c937139 | 2015-08-06 12:40:53 +0200 | [diff] [blame] | 784 | template <class FunctorT, class R, |
Jelena Marusic | 5d6e58e | 2015-07-13 11:16:39 +0200 | [diff] [blame] | 785 | class P1, |
| 786 | class P2, |
| 787 | class P3, |
| 788 | class P4, |
| 789 | class P5, |
| 790 | class P6> |
| 791 | class Functor6 { |
| 792 | public: |
| 793 | Functor6(const FunctorT& functor, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) |
| 794 | : functor_(functor), |
Fredrik Solenberg | c937139 | 2015-08-06 12:40:53 +0200 | [diff] [blame] | 795 | p1_(p1), |
| 796 | p2_(p2), |
| 797 | p3_(p3), |
| 798 | p4_(p4), |
| 799 | p5_(p5), |
| 800 | p6_(p6) {} |
| 801 | R operator()() const { |
| 802 | return functor_(p1_, p2_, p3_, p4_, p5_, p6_); } |
Jelena Marusic | 5d6e58e | 2015-07-13 11:16:39 +0200 | [diff] [blame] | 803 | private: |
| 804 | FunctorT functor_; |
| 805 | P1 p1_; |
| 806 | P2 p2_; |
| 807 | P3 p3_; |
| 808 | P4 p4_; |
| 809 | P5 p5_; |
| 810 | P6 p6_; |
| 811 | }; |
| 812 | |
Fredrik Solenberg | c937139 | 2015-08-06 12:40:53 +0200 | [diff] [blame] | 813 | |
Jelena Marusic | 5d6e58e | 2015-07-13 11:16:39 +0200 | [diff] [blame] | 814 | #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6) |
| 815 | |
Fredrik Solenberg | c937139 | 2015-08-06 12:40:53 +0200 | [diff] [blame] | 816 | template <class ObjectT, class R, |
Jelena Marusic | 5d6e58e | 2015-07-13 11:16:39 +0200 | [diff] [blame] | 817 | class P1, |
| 818 | class P2, |
| 819 | class P3, |
| 820 | class P4, |
| 821 | class P5, |
| 822 | class P6> |
Fredrik Solenberg | c937139 | 2015-08-06 12:40:53 +0200 | [diff] [blame] | 823 | MethodFunctor6<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6> |
| 824 | Bind(FP_T(method), ObjectT* object, |
| 825 | typename detail::identity<P1>::type p1, |
| 826 | typename detail::identity<P2>::type p2, |
| 827 | typename detail::identity<P3>::type p3, |
| 828 | typename detail::identity<P4>::type p4, |
| 829 | typename detail::identity<P5>::type p5, |
| 830 | typename detail::identity<P6>::type p6) { |
Jelena Marusic | 5d6e58e | 2015-07-13 11:16:39 +0200 | [diff] [blame] | 831 | return MethodFunctor6<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>( |
| 832 | method, object, p1, p2, p3, p4, p5, p6); |
| 833 | } |
| 834 | |
| 835 | #undef FP_T |
| 836 | #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6) const |
| 837 | |
Fredrik Solenberg | c937139 | 2015-08-06 12:40:53 +0200 | [diff] [blame] | 838 | template <class ObjectT, class R, |
Jelena Marusic | 5d6e58e | 2015-07-13 11:16:39 +0200 | [diff] [blame] | 839 | class P1, |
| 840 | class P2, |
| 841 | class P3, |
| 842 | class P4, |
| 843 | class P5, |
| 844 | class P6> |
Fredrik Solenberg | c937139 | 2015-08-06 12:40:53 +0200 | [diff] [blame] | 845 | MethodFunctor6<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6> |
| 846 | Bind(FP_T(method), const ObjectT* object, |
| 847 | typename detail::identity<P1>::type p1, |
| 848 | typename detail::identity<P2>::type p2, |
| 849 | typename detail::identity<P3>::type p3, |
| 850 | typename detail::identity<P4>::type p4, |
| 851 | typename detail::identity<P5>::type p5, |
| 852 | typename detail::identity<P6>::type p6) { |
Jelena Marusic | 5d6e58e | 2015-07-13 11:16:39 +0200 | [diff] [blame] | 853 | return MethodFunctor6<const ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>( |
| 854 | method, object, p1, p2, p3, p4, p5, p6); |
| 855 | } |
| 856 | |
| 857 | #undef FP_T |
Magnus Jedvert | d3de9c5 | 2015-08-20 16:03:52 +0200 | [diff] [blame] | 858 | #define FP_T(x) R (ObjectT::*x)(P1, P2, P3, P4, P5, P6) |
| 859 | |
| 860 | template <class ObjectT, class R, |
| 861 | class P1, |
| 862 | class P2, |
| 863 | class P3, |
| 864 | class P4, |
| 865 | class P5, |
| 866 | class P6> |
| 867 | MethodFunctor6<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6> |
| 868 | Bind(FP_T(method), const scoped_refptr<ObjectT>& object, |
| 869 | typename detail::identity<P1>::type p1, |
| 870 | typename detail::identity<P2>::type p2, |
| 871 | typename detail::identity<P3>::type p3, |
| 872 | typename detail::identity<P4>::type p4, |
| 873 | typename detail::identity<P5>::type p5, |
| 874 | typename detail::identity<P6>::type p6) { |
| 875 | return MethodFunctor6<ObjectT, FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>( |
| 876 | method, object.get(), p1, p2, p3, p4, p5, p6); |
| 877 | } |
| 878 | |
| 879 | #undef FP_T |
Jelena Marusic | 5d6e58e | 2015-07-13 11:16:39 +0200 | [diff] [blame] | 880 | #define FP_T(x) R (*x)(P1, P2, P3, P4, P5, P6) |
| 881 | |
Fredrik Solenberg | c937139 | 2015-08-06 12:40:53 +0200 | [diff] [blame] | 882 | template <class R, |
| 883 | class P1, |
| 884 | class P2, |
| 885 | class P3, |
| 886 | class P4, |
| 887 | class P5, |
| 888 | class P6> |
| 889 | Functor6<FP_T(NONAME), R, P1, P2, P3, P4, P5, P6> |
| 890 | Bind(FP_T(function), |
| 891 | typename detail::identity<P1>::type p1, |
| 892 | typename detail::identity<P2>::type p2, |
| 893 | typename detail::identity<P3>::type p3, |
| 894 | typename detail::identity<P4>::type p4, |
| 895 | typename detail::identity<P5>::type p5, |
| 896 | typename detail::identity<P6>::type p6) { |
| 897 | return Functor6<FP_T(NONAME), R, P1, P2, P3, P4, P5, P6>( |
| 898 | function, p1, p2, p3, p4, p5, p6); |
Jelena Marusic | 5d6e58e | 2015-07-13 11:16:39 +0200 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | #undef FP_T |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 902 | |
| 903 | } // namespace rtc |
| 904 | |
| 905 | #undef NONAME |
| 906 | |
| 907 | #endif // WEBRTC_BASE_BIND_H_ |