1 /* 2 * Copyright (C) 2011 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef WTF_Functional_h 27 #define WTF_Functional_h 28 29 #include "wtf/Assertions.h" 30 #include "wtf/PassRefPtr.h" 31 #include "wtf/RefPtr.h" 32 #include "wtf/ThreadSafeRefCounted.h" 33 #include "wtf/WeakPtr.h" 34 35 namespace WTF { 36 37 // Functional.h provides a very simple way to bind a function pointer and arguments together into a function object 38 // that can be stored, copied and invoked, similar to how boost::bind and std::bind in C++11. 39 40 // A FunctionWrapper is a class template that can wrap a function pointer or a member function pointer and 41 // provide a unified interface for calling that function. 42 template<typename> 43 class FunctionWrapper; 44 45 // Bound static functions: 46 47 template<typename R> 48 class FunctionWrapper<R(*)()> { 49 public: 50 typedef R ResultType; 51 FunctionWrapper(R (* function)())52 explicit FunctionWrapper(R(*function)()) 53 : m_function(function) 54 { 55 } 56 operator()57 R operator()() 58 { 59 return m_function(); 60 } 61 62 private: 63 R(*m_function)(); 64 }; 65 66 template<typename R, typename P1> 67 class FunctionWrapper<R(*)(P1)> { 68 public: 69 typedef R ResultType; 70 FunctionWrapper(R (* function)(P1))71 explicit FunctionWrapper(R(*function)(P1)) 72 : m_function(function) 73 { 74 } 75 operator()76 R operator()(P1 p1) 77 { 78 return m_function(p1); 79 } 80 81 private: 82 R(*m_function)(P1); 83 }; 84 85 template<typename R, typename P1, typename P2> 86 class FunctionWrapper<R(*)(P1, P2)> { 87 public: 88 typedef R ResultType; 89 FunctionWrapper(R (* function)(P1,P2))90 explicit FunctionWrapper(R(*function)(P1, P2)) 91 : m_function(function) 92 { 93 } 94 operator()95 R operator()(P1 p1, P2 p2) 96 { 97 return m_function(p1, p2); 98 } 99 100 private: 101 R(*m_function)(P1, P2); 102 }; 103 104 template<typename R, typename P1, typename P2, typename P3> 105 class FunctionWrapper<R(*)(P1, P2, P3)> { 106 public: 107 typedef R ResultType; 108 FunctionWrapper(R (* function)(P1,P2,P3))109 explicit FunctionWrapper(R(*function)(P1, P2, P3)) 110 : m_function(function) 111 { 112 } 113 operator()114 R operator()(P1 p1, P2 p2, P3 p3) 115 { 116 return m_function(p1, p2, p3); 117 } 118 119 private: 120 R(*m_function)(P1, P2, P3); 121 }; 122 123 template<typename R, typename P1, typename P2, typename P3, typename P4> 124 class FunctionWrapper<R(*)(P1, P2, P3, P4)> { 125 public: 126 typedef R ResultType; 127 FunctionWrapper(R (* function)(P1,P2,P3,P4))128 explicit FunctionWrapper(R(*function)(P1, P2, P3, P4)) 129 : m_function(function) 130 { 131 } 132 operator()133 R operator()(P1 p1, P2 p2, P3 p3, P4 p4) 134 { 135 return m_function(p1, p2, p3, p4); 136 } 137 138 private: 139 R(*m_function)(P1, P2, P3, P4); 140 }; 141 142 template<typename R, typename P1, typename P2, typename P3, typename P4, typename P5> 143 class FunctionWrapper<R(*)(P1, P2, P3, P4, P5)> { 144 public: 145 typedef R ResultType; 146 FunctionWrapper(R (* function)(P1,P2,P3,P4,P5))147 explicit FunctionWrapper(R(*function)(P1, P2, P3, P4, P5)) 148 : m_function(function) 149 { 150 } 151 operator()152 R operator()(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) 153 { 154 return m_function(p1, p2, p3, p4, p5); 155 } 156 157 private: 158 R(*m_function)(P1, P2, P3, P4, P5); 159 }; 160 161 template<typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> 162 class FunctionWrapper<R(*)(P1, P2, P3, P4, P5, P6)> { 163 public: 164 typedef R ResultType; 165 FunctionWrapper(R (* function)(P1,P2,P3,P4,P5,P6))166 explicit FunctionWrapper(R(*function)(P1, P2, P3, P4, P5, P6)) 167 : m_function(function) 168 { 169 } 170 operator()171 R operator()(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) 172 { 173 return m_function(p1, p2, p3, p4, p5, p6); 174 } 175 176 private: 177 R(*m_function)(P1, P2, P3, P4, P5, P6); 178 }; 179 180 // Bound member functions: 181 182 template<typename R, typename C> 183 class FunctionWrapper<R(C::*)()> { 184 public: 185 typedef R ResultType; 186 FunctionWrapper(R (C::* function)())187 explicit FunctionWrapper(R(C::*function)()) 188 : m_function(function) 189 { 190 } 191 operator()192 R operator()(C* c) 193 { 194 return (c->*m_function)(); 195 } 196 operator()197 R operator()(const WeakPtr<C>& c) 198 { 199 C* obj = c.get(); 200 if (!obj) 201 return R(); 202 return (obj->*m_function)(); 203 } 204 205 private: 206 R(C::*m_function)(); 207 }; 208 209 template<typename R, typename C, typename P1> 210 class FunctionWrapper<R(C::*)(P1)> { 211 public: 212 typedef R ResultType; 213 FunctionWrapper(R (C::* function)(P1))214 explicit FunctionWrapper(R(C::*function)(P1)) 215 : m_function(function) 216 { 217 } 218 operator()219 R operator()(C* c, P1 p1) 220 { 221 return (c->*m_function)(p1); 222 } 223 operator()224 R operator()(const WeakPtr<C>& c, P1 p1) 225 { 226 C* obj = c.get(); 227 if (!obj) 228 return R(); 229 return (obj->*m_function)(p1); 230 } 231 232 private: 233 R(C::*m_function)(P1); 234 }; 235 236 template<typename R, typename C, typename P1, typename P2> 237 class FunctionWrapper<R(C::*)(P1, P2)> { 238 public: 239 typedef R ResultType; 240 FunctionWrapper(R (C::* function)(P1,P2))241 explicit FunctionWrapper(R(C::*function)(P1, P2)) 242 : m_function(function) 243 { 244 } 245 operator()246 R operator()(C* c, P1 p1, P2 p2) 247 { 248 return (c->*m_function)(p1, p2); 249 } 250 operator()251 R operator()(const WeakPtr<C>& c, P1 p1, P2 p2) 252 { 253 C* obj = c.get(); 254 if (!obj) 255 return R(); 256 return (obj->*m_function)(p1, p2); 257 } 258 259 private: 260 R(C::*m_function)(P1, P2); 261 }; 262 263 template<typename R, typename C, typename P1, typename P2, typename P3> 264 class FunctionWrapper<R(C::*)(P1, P2, P3)> { 265 public: 266 typedef R ResultType; 267 FunctionWrapper(R (C::* function)(P1,P2,P3))268 explicit FunctionWrapper(R(C::*function)(P1, P2, P3)) 269 : m_function(function) 270 { 271 } 272 operator()273 R operator()(C* c, P1 p1, P2 p2, P3 p3) 274 { 275 return (c->*m_function)(p1, p2, p3); 276 } 277 operator()278 R operator()(const WeakPtr<C>& c, P1 p1, P2 p2, P3 p3) 279 { 280 C* obj = c.get(); 281 if (!obj) 282 return R(); 283 return (obj->*m_function)(p1, p2, p3); 284 } 285 286 private: 287 R(C::*m_function)(P1, P2, P3); 288 }; 289 290 template<typename R, typename C, typename P1, typename P2, typename P3, typename P4> 291 class FunctionWrapper<R(C::*)(P1, P2, P3, P4)> { 292 public: 293 typedef R ResultType; 294 FunctionWrapper(R (C::* function)(P1,P2,P3,P4))295 explicit FunctionWrapper(R(C::*function)(P1, P2, P3, P4)) 296 : m_function(function) 297 { 298 } 299 operator()300 R operator()(C* c, P1 p1, P2 p2, P3 p3, P4 p4) 301 { 302 return (c->*m_function)(p1, p2, p3, p4); 303 } 304 operator()305 R operator()(const WeakPtr<C>& c, P1 p1, P2 p2, P3 p3, P4 p4) 306 { 307 C* obj = c.get(); 308 if (!obj) 309 return R(); 310 return (obj->*m_function)(p1, p2, p3, p4); 311 } 312 313 private: 314 R(C::*m_function)(P1, P2, P3, P4); 315 }; 316 317 template<typename R, typename C, typename P1, typename P2, typename P3, typename P4, typename P5> 318 class FunctionWrapper<R(C::*)(P1, P2, P3, P4, P5)> { 319 public: 320 typedef R ResultType; 321 FunctionWrapper(R (C::* function)(P1,P2,P3,P4,P5))322 explicit FunctionWrapper(R(C::*function)(P1, P2, P3, P4, P5)) 323 : m_function(function) 324 { 325 } 326 operator()327 R operator()(C* c, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) 328 { 329 return (c->*m_function)(p1, p2, p3, p4, p5); 330 } 331 operator()332 R operator()(const WeakPtr<C>& c, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) 333 { 334 C* obj = c.get(); 335 if (!obj) 336 return R(); 337 return (obj->*m_function)(p1, p2, p3, p4, p5); 338 } 339 340 private: 341 R(C::*m_function)(P1, P2, P3, P4, P5); 342 }; 343 344 template<typename T> struct ParamStorageTraits { 345 typedef T StorageType; 346 wrapParamStorageTraits347 static StorageType wrap(const T& value) { return value; } unwrapParamStorageTraits348 static const T& unwrap(const StorageType& value) { return value; } 349 }; 350 351 template<typename T> struct ParamStorageTraits<PassRefPtr<T> > { 352 typedef RefPtr<T> StorageType; 353 354 static StorageType wrap(PassRefPtr<T> value) { return value; } 355 static T* unwrap(const StorageType& value) { return value.get(); } 356 }; 357 358 template<typename T> struct ParamStorageTraits<RefPtr<T> > { 359 typedef RefPtr<T> StorageType; 360 361 static StorageType wrap(RefPtr<T> value) { return value.release(); } 362 static T* unwrap(const StorageType& value) { return value.get(); } 363 }; 364 365 template<typename> class RetainPtr; 366 367 template<typename T> struct ParamStorageTraits<RetainPtr<T> > { 368 typedef RetainPtr<T> StorageType; 369 370 static StorageType wrap(const RetainPtr<T>& value) { return value; } 371 static typename RetainPtr<T>::PtrType unwrap(const StorageType& value) { return value.get(); } 372 }; 373 374 class FunctionImplBase : public ThreadSafeRefCounted<FunctionImplBase> { 375 public: 376 virtual ~FunctionImplBase() { } 377 }; 378 379 template<typename> 380 class FunctionImpl; 381 382 template<typename R> 383 class FunctionImpl<R()> : public FunctionImplBase { 384 public: 385 virtual R operator()() = 0; 386 }; 387 388 template<typename R, typename A1> 389 class FunctionImpl<R(A1)> : public FunctionImplBase { 390 public: 391 virtual R operator()(A1 a1) = 0; 392 }; 393 394 template<typename R, typename A1, typename A2> 395 class FunctionImpl<R(A1, A2)> : public FunctionImplBase { 396 public: 397 virtual R operator()(A1 a1, A2 a2) = 0; 398 }; 399 400 template<typename R, typename A1, typename A2, typename A3> 401 class FunctionImpl<R(A1, A2, A3)> : public FunctionImplBase { 402 public: 403 virtual R operator()(A1 a1, A2 a2, A3 a3) = 0; 404 }; 405 406 template<typename R, typename A1, typename A2, typename A3, typename A4> 407 class FunctionImpl<R(A1, A2, A3, A4)> : public FunctionImplBase { 408 public: 409 virtual R operator()(A1 a1, A2 a2, A3 a3, A4 a4) = 0; 410 }; 411 412 template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5> 413 class FunctionImpl<R(A1, A2, A3, A4, A5)> : public FunctionImplBase { 414 public: 415 virtual R operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) = 0; 416 }; 417 418 template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> 419 class FunctionImpl<R(A1, A2, A3, A4, A5, A6)> : public FunctionImplBase { 420 public: 421 virtual R operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) = 0; 422 }; 423 424 template<typename FunctionWrapper, typename FunctionType> 425 class UnboundFunctionImpl; 426 427 template<typename FunctionWrapper, typename R, typename P1> 428 class UnboundFunctionImpl<FunctionWrapper, R(P1)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P1)> { 429 public: 430 UnboundFunctionImpl(FunctionWrapper functionWrapper) 431 : m_functionWrapper(functionWrapper) 432 { 433 } 434 435 virtual typename FunctionWrapper::ResultType operator()(P1 p1) override 436 { 437 return m_functionWrapper(p1); 438 } 439 440 private: 441 FunctionWrapper m_functionWrapper; 442 }; 443 444 template<typename FunctionWrapper, typename R, typename P1, typename P2> 445 class UnboundFunctionImpl<FunctionWrapper, R(P1, P2)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P1, P2)> { 446 public: 447 UnboundFunctionImpl(FunctionWrapper functionWrapper) 448 : m_functionWrapper(functionWrapper) 449 { 450 } 451 452 virtual typename FunctionWrapper::ResultType operator()(P1 p1, P2 p2) override 453 { 454 return m_functionWrapper(p1, p2); 455 } 456 457 private: 458 FunctionWrapper m_functionWrapper; 459 }; 460 461 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3> 462 class UnboundFunctionImpl<FunctionWrapper, R(P1, P2, P3)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P1, P2, P3)> { 463 public: 464 UnboundFunctionImpl(FunctionWrapper functionWrapper) 465 : m_functionWrapper(functionWrapper) 466 { 467 } 468 469 virtual typename FunctionWrapper::ResultType operator()(P1 p1, P2 p2, P3 p3) override 470 { 471 return m_functionWrapper(p1, p2, p3); 472 } 473 474 private: 475 FunctionWrapper m_functionWrapper; 476 }; 477 478 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4> 479 class UnboundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P1, P2, P3, P4)> { 480 public: 481 UnboundFunctionImpl(FunctionWrapper functionWrapper) 482 : m_functionWrapper(functionWrapper) 483 { 484 } 485 486 virtual typename FunctionWrapper::ResultType operator()(P1 p1, P2 p2, P3 p3, P4 p4) override 487 { 488 return m_functionWrapper(p1, p2, p3, p4); 489 } 490 491 private: 492 FunctionWrapper m_functionWrapper; 493 }; 494 495 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5> 496 class UnboundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4, P5)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P1, P2, P3, P4, P5)> { 497 public: 498 UnboundFunctionImpl(FunctionWrapper functionWrapper) 499 : m_functionWrapper(functionWrapper) 500 { 501 } 502 503 virtual typename FunctionWrapper::ResultType operator()(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) override 504 { 505 return m_functionWrapper(p1, p2, p3, p4, p5); 506 } 507 508 private: 509 FunctionWrapper m_functionWrapper; 510 }; 511 512 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> 513 class UnboundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4, P5, P6)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P1, P2, P3, P4, P5, P6)> { 514 public: 515 UnboundFunctionImpl(FunctionWrapper functionWrapper) 516 : m_functionWrapper(functionWrapper) 517 { 518 } 519 520 virtual typename FunctionWrapper::ResultType operator()(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) override 521 { 522 return m_functionWrapper(p1, p2, p3, p4, p5, p6); 523 } 524 525 private: 526 FunctionWrapper m_functionWrapper; 527 }; 528 529 template<typename FunctionWrapper, typename FunctionType> 530 class OneArgPartBoundFunctionImpl; 531 532 template<typename FunctionWrapper, typename R, typename P1, typename P2> 533 class OneArgPartBoundFunctionImpl<FunctionWrapper, R(P1, P2)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P2)> { 534 public: 535 OneArgPartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1) 536 : m_functionWrapper(functionWrapper) 537 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 538 { 539 } 540 541 virtual typename FunctionWrapper::ResultType operator()(P2 p2) override 542 { 543 return m_functionWrapper(m_p1, p2); 544 } 545 546 private: 547 FunctionWrapper m_functionWrapper; 548 typename ParamStorageTraits<P1>::StorageType m_p1; 549 }; 550 551 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3> 552 class OneArgPartBoundFunctionImpl<FunctionWrapper, R(P1, P2, P3)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P2, P3)> { 553 public: 554 OneArgPartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1) 555 : m_functionWrapper(functionWrapper) 556 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 557 { 558 } 559 560 virtual typename FunctionWrapper::ResultType operator()(P2 p2, P3 p3) override 561 { 562 return m_functionWrapper(m_p1, p2, p3); 563 } 564 565 private: 566 FunctionWrapper m_functionWrapper; 567 typename ParamStorageTraits<P1>::StorageType m_p1; 568 }; 569 570 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4> 571 class OneArgPartBoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P2, P3, P4)> { 572 public: 573 OneArgPartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1) 574 : m_functionWrapper(functionWrapper) 575 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 576 { 577 } 578 579 virtual typename FunctionWrapper::ResultType operator()(P2 p2, P3 p3, P4 p4) override 580 { 581 return m_functionWrapper(m_p1, p2, p3, p4); 582 } 583 584 private: 585 FunctionWrapper m_functionWrapper; 586 typename ParamStorageTraits<P1>::StorageType m_p1; 587 }; 588 589 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5> 590 class OneArgPartBoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4, P5)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P2, P3, P4, P5)> { 591 public: 592 OneArgPartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1) 593 : m_functionWrapper(functionWrapper) 594 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 595 { 596 } 597 598 virtual typename FunctionWrapper::ResultType operator()(P2 p2, P3 p3, P4 p4, P5 p5) override 599 { 600 return m_functionWrapper(m_p1, p2, p3, p4, p5); 601 } 602 603 private: 604 FunctionWrapper m_functionWrapper; 605 typename ParamStorageTraits<P1>::StorageType m_p1; 606 }; 607 608 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> 609 class OneArgPartBoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4, P5, P6)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P2, P3, P4, P5, P6)> { 610 public: 611 OneArgPartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1) 612 : m_functionWrapper(functionWrapper) 613 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 614 { 615 } 616 617 virtual typename FunctionWrapper::ResultType operator()(P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) override 618 { 619 return m_functionWrapper(m_p1, p2, p3, p4, p5, p6); 620 } 621 622 private: 623 FunctionWrapper m_functionWrapper; 624 typename ParamStorageTraits<P1>::StorageType m_p1; 625 }; 626 627 template<typename FunctionWrapper, typename FunctionType> 628 class TwoArgPartBoundFunctionImpl; 629 630 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3> 631 class TwoArgPartBoundFunctionImpl<FunctionWrapper, R(P1, P2, P3)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P3)> { 632 public: 633 TwoArgPartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2) 634 : m_functionWrapper(functionWrapper) 635 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 636 , m_p2(ParamStorageTraits<P2>::wrap(p2)) 637 { 638 } 639 640 virtual typename FunctionWrapper::ResultType operator()(P3 p3) override 641 { 642 return m_functionWrapper(m_p1, m_p2, p3); 643 } 644 645 private: 646 FunctionWrapper m_functionWrapper; 647 typename ParamStorageTraits<P1>::StorageType m_p1; 648 typename ParamStorageTraits<P2>::StorageType m_p2; 649 }; 650 651 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4> 652 class TwoArgPartBoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P3, P4)> { 653 public: 654 TwoArgPartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2) 655 : m_functionWrapper(functionWrapper) 656 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 657 , m_p2(ParamStorageTraits<P2>::wrap(p2)) 658 { 659 } 660 661 virtual typename FunctionWrapper::ResultType operator()(P3 p3, P4 p4) override 662 { 663 return m_functionWrapper(m_p1, m_p2, p3, p4); 664 } 665 666 private: 667 FunctionWrapper m_functionWrapper; 668 typename ParamStorageTraits<P1>::StorageType m_p1; 669 typename ParamStorageTraits<P2>::StorageType m_p2; 670 }; 671 672 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5> 673 class TwoArgPartBoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4, P5)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P3, P4, P5)> { 674 public: 675 TwoArgPartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2) 676 : m_functionWrapper(functionWrapper) 677 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 678 , m_p2(ParamStorageTraits<P2>::wrap(p2)) 679 { 680 } 681 682 virtual typename FunctionWrapper::ResultType operator()(P3 p3, P4 p4, P5 p5) override 683 { 684 return m_functionWrapper(m_p1, m_p2, p3, p4, p5); 685 } 686 687 private: 688 FunctionWrapper m_functionWrapper; 689 typename ParamStorageTraits<P1>::StorageType m_p1; 690 typename ParamStorageTraits<P2>::StorageType m_p2; 691 }; 692 693 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> 694 class TwoArgPartBoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4, P5, P6)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P3, P4, P5, P6)> { 695 public: 696 TwoArgPartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2) 697 : m_functionWrapper(functionWrapper) 698 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 699 , m_p2(ParamStorageTraits<P2>::wrap(p2)) 700 { 701 } 702 703 virtual typename FunctionWrapper::ResultType operator()(P3 p3, P4 p4, P5 p5, P6 p6) override 704 { 705 return m_functionWrapper(m_p1, m_p2, p3, p4, p5, p6); 706 } 707 708 private: 709 FunctionWrapper m_functionWrapper; 710 typename ParamStorageTraits<P1>::StorageType m_p1; 711 typename ParamStorageTraits<P2>::StorageType m_p2; 712 }; 713 714 template<typename FunctionWrapper, typename FunctionType> 715 class ThreeArgPartBoundFunctionImpl; 716 717 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4> 718 class ThreeArgPartBoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P4)> { 719 public: 720 ThreeArgPartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3) 721 : m_functionWrapper(functionWrapper) 722 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 723 , m_p2(ParamStorageTraits<P2>::wrap(p2)) 724 , m_p3(ParamStorageTraits<P3>::wrap(p3)) 725 { 726 } 727 728 virtual typename FunctionWrapper::ResultType operator()(P4 p4) override 729 { 730 return m_functionWrapper(m_p1, m_p2, m_p3, p4); 731 } 732 733 private: 734 FunctionWrapper m_functionWrapper; 735 typename ParamStorageTraits<P1>::StorageType m_p1; 736 typename ParamStorageTraits<P2>::StorageType m_p2; 737 typename ParamStorageTraits<P3>::StorageType m_p3; 738 }; 739 740 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5> 741 class ThreeArgPartBoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4, P5)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P4, P5)> { 742 public: 743 ThreeArgPartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3) 744 : m_functionWrapper(functionWrapper) 745 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 746 , m_p2(ParamStorageTraits<P2>::wrap(p2)) 747 , m_p3(ParamStorageTraits<P3>::wrap(p3)) 748 { 749 } 750 751 virtual typename FunctionWrapper::ResultType operator()(P4 p4, P5 p5) override 752 { 753 return m_functionWrapper(m_p1, m_p2, m_p3, p4, p5); 754 } 755 756 private: 757 FunctionWrapper m_functionWrapper; 758 typename ParamStorageTraits<P1>::StorageType m_p1; 759 typename ParamStorageTraits<P2>::StorageType m_p2; 760 typename ParamStorageTraits<P3>::StorageType m_p3; 761 }; 762 763 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> 764 class ThreeArgPartBoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4, P5, P6)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P4, P5, P6)> { 765 public: 766 ThreeArgPartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3) 767 : m_functionWrapper(functionWrapper) 768 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 769 , m_p2(ParamStorageTraits<P2>::wrap(p2)) 770 , m_p3(ParamStorageTraits<P3>::wrap(p3)) 771 { 772 } 773 774 virtual typename FunctionWrapper::ResultType operator()(P4 p4, P5 p5, P6 p6) override 775 { 776 return m_functionWrapper(m_p1, m_p2, m_p3, p4, p5, p6); 777 } 778 779 private: 780 FunctionWrapper m_functionWrapper; 781 typename ParamStorageTraits<P1>::StorageType m_p1; 782 typename ParamStorageTraits<P2>::StorageType m_p2; 783 typename ParamStorageTraits<P3>::StorageType m_p3; 784 }; 785 786 template<typename FunctionWrapper, typename FunctionType> 787 class FourArgPartBoundFunctionImpl; 788 789 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5> 790 class FourArgPartBoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4, P5)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P5)> { 791 public: 792 FourArgPartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3, const P4& p4) 793 : m_functionWrapper(functionWrapper) 794 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 795 , m_p2(ParamStorageTraits<P2>::wrap(p2)) 796 , m_p3(ParamStorageTraits<P3>::wrap(p3)) 797 , m_p4(ParamStorageTraits<P4>::wrap(p4)) 798 { 799 } 800 801 virtual typename FunctionWrapper::ResultType operator()(P5 p5) override 802 { 803 return m_functionWrapper(m_p1, m_p2, m_p3, m_p4, p5); 804 } 805 806 private: 807 FunctionWrapper m_functionWrapper; 808 typename ParamStorageTraits<P1>::StorageType m_p1; 809 typename ParamStorageTraits<P2>::StorageType m_p2; 810 typename ParamStorageTraits<P3>::StorageType m_p3; 811 typename ParamStorageTraits<P4>::StorageType m_p4; 812 }; 813 814 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> 815 class FourArgPartBoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4, P5, P6)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P5, P6)> { 816 public: 817 FourArgPartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3, const P4& p4) 818 : m_functionWrapper(functionWrapper) 819 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 820 , m_p2(ParamStorageTraits<P2>::wrap(p2)) 821 , m_p3(ParamStorageTraits<P3>::wrap(p3)) 822 , m_p4(ParamStorageTraits<P4>::wrap(p4)) 823 { 824 } 825 826 virtual typename FunctionWrapper::ResultType operator()(P5 p5, P6 p6) override 827 { 828 return m_functionWrapper(m_p1, m_p2, m_p3, m_p4, p5, p6); 829 } 830 831 private: 832 FunctionWrapper m_functionWrapper; 833 typename ParamStorageTraits<P1>::StorageType m_p1; 834 typename ParamStorageTraits<P2>::StorageType m_p2; 835 typename ParamStorageTraits<P3>::StorageType m_p3; 836 typename ParamStorageTraits<P4>::StorageType m_p4; 837 }; 838 839 template<typename FunctionWrapper, typename FunctionType> 840 class FiveArgPartBoundFunctionImpl; 841 842 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> 843 class FiveArgPartBoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4, P5, P6)> final : public FunctionImpl<typename FunctionWrapper::ResultType(P6)> { 844 public: 845 FiveArgPartBoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3, const P4& p4, const P5& p5) 846 : m_functionWrapper(functionWrapper) 847 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 848 , m_p2(ParamStorageTraits<P2>::wrap(p2)) 849 , m_p3(ParamStorageTraits<P3>::wrap(p3)) 850 , m_p4(ParamStorageTraits<P4>::wrap(p4)) 851 , m_p5(ParamStorageTraits<P5>::wrap(p5)) 852 { 853 } 854 855 virtual typename FunctionWrapper::ResultType operator()(P6 p6) override 856 { 857 return m_functionWrapper(m_p1, m_p2, m_p3, m_p4, m_p5, p6); 858 } 859 860 private: 861 FunctionWrapper m_functionWrapper; 862 typename ParamStorageTraits<P1>::StorageType m_p1; 863 typename ParamStorageTraits<P2>::StorageType m_p2; 864 typename ParamStorageTraits<P3>::StorageType m_p3; 865 typename ParamStorageTraits<P4>::StorageType m_p4; 866 typename ParamStorageTraits<P5>::StorageType m_p5; 867 }; 868 869 template<typename FunctionWrapper, typename FunctionType> 870 class BoundFunctionImpl; 871 872 template<typename FunctionWrapper, typename R> 873 class BoundFunctionImpl<FunctionWrapper, R()> final : public FunctionImpl<typename FunctionWrapper::ResultType()> { 874 public: 875 explicit BoundFunctionImpl(FunctionWrapper functionWrapper) 876 : m_functionWrapper(functionWrapper) 877 { 878 } 879 880 virtual typename FunctionWrapper::ResultType operator()() override 881 { 882 return m_functionWrapper(); 883 } 884 885 private: 886 FunctionWrapper m_functionWrapper; 887 }; 888 889 template<typename FunctionWrapper, typename R, typename P1> 890 class BoundFunctionImpl<FunctionWrapper, R(P1)> final : public FunctionImpl<typename FunctionWrapper::ResultType()> { 891 public: 892 BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1) 893 : m_functionWrapper(functionWrapper) 894 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 895 { 896 } 897 898 virtual typename FunctionWrapper::ResultType operator()() override 899 { 900 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1)); 901 } 902 903 private: 904 FunctionWrapper m_functionWrapper; 905 typename ParamStorageTraits<P1>::StorageType m_p1; 906 }; 907 908 template<typename FunctionWrapper, typename R, typename P1, typename P2> 909 class BoundFunctionImpl<FunctionWrapper, R(P1, P2)> final : public FunctionImpl<typename FunctionWrapper::ResultType()> { 910 public: 911 BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2) 912 : m_functionWrapper(functionWrapper) 913 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 914 , m_p2(ParamStorageTraits<P2>::wrap(p2)) 915 { 916 } 917 918 virtual typename FunctionWrapper::ResultType operator()() override 919 { 920 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageTraits<P2>::unwrap(m_p2)); 921 } 922 923 private: 924 FunctionWrapper m_functionWrapper; 925 typename ParamStorageTraits<P1>::StorageType m_p1; 926 typename ParamStorageTraits<P2>::StorageType m_p2; 927 }; 928 929 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3> 930 class BoundFunctionImpl<FunctionWrapper, R(P1, P2, P3)> final : public FunctionImpl<typename FunctionWrapper::ResultType()> { 931 public: 932 BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3) 933 : m_functionWrapper(functionWrapper) 934 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 935 , m_p2(ParamStorageTraits<P2>::wrap(p2)) 936 , m_p3(ParamStorageTraits<P3>::wrap(p3)) 937 { 938 } 939 940 virtual typename FunctionWrapper::ResultType operator()() override 941 { 942 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3)); 943 } 944 945 private: 946 FunctionWrapper m_functionWrapper; 947 typename ParamStorageTraits<P1>::StorageType m_p1; 948 typename ParamStorageTraits<P2>::StorageType m_p2; 949 typename ParamStorageTraits<P3>::StorageType m_p3; 950 }; 951 952 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4> 953 class BoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4)> final : public FunctionImpl<typename FunctionWrapper::ResultType()> { 954 public: 955 BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3, const P4& p4) 956 : m_functionWrapper(functionWrapper) 957 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 958 , m_p2(ParamStorageTraits<P2>::wrap(p2)) 959 , m_p3(ParamStorageTraits<P3>::wrap(p3)) 960 , m_p4(ParamStorageTraits<P4>::wrap(p4)) 961 { 962 } 963 964 virtual typename FunctionWrapper::ResultType operator()() override 965 { 966 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), ParamStorageTraits<P4>::unwrap(m_p4)); 967 } 968 969 private: 970 FunctionWrapper m_functionWrapper; 971 typename ParamStorageTraits<P1>::StorageType m_p1; 972 typename ParamStorageTraits<P2>::StorageType m_p2; 973 typename ParamStorageTraits<P3>::StorageType m_p3; 974 typename ParamStorageTraits<P4>::StorageType m_p4; 975 }; 976 977 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5> 978 class BoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4, P5)> final : public FunctionImpl<typename FunctionWrapper::ResultType()> { 979 public: 980 BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3, const P4& p4, const P5& p5) 981 : m_functionWrapper(functionWrapper) 982 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 983 , m_p2(ParamStorageTraits<P2>::wrap(p2)) 984 , m_p3(ParamStorageTraits<P3>::wrap(p3)) 985 , m_p4(ParamStorageTraits<P4>::wrap(p4)) 986 , m_p5(ParamStorageTraits<P5>::wrap(p5)) 987 { 988 } 989 990 virtual typename FunctionWrapper::ResultType operator()() override 991 { 992 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), ParamStorageTraits<P4>::unwrap(m_p4), ParamStorageTraits<P5>::unwrap(m_p5)); 993 } 994 995 private: 996 FunctionWrapper m_functionWrapper; 997 typename ParamStorageTraits<P1>::StorageType m_p1; 998 typename ParamStorageTraits<P2>::StorageType m_p2; 999 typename ParamStorageTraits<P3>::StorageType m_p3; 1000 typename ParamStorageTraits<P4>::StorageType m_p4; 1001 typename ParamStorageTraits<P5>::StorageType m_p5; 1002 }; 1003 1004 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> 1005 class BoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4, P5, P6)> final : public FunctionImpl<typename FunctionWrapper::ResultType()> { 1006 public: 1007 BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3, const P4& p4, const P5& p5, const P6& p6) 1008 : m_functionWrapper(functionWrapper) 1009 , m_p1(ParamStorageTraits<P1>::wrap(p1)) 1010 , m_p2(ParamStorageTraits<P2>::wrap(p2)) 1011 , m_p3(ParamStorageTraits<P3>::wrap(p3)) 1012 , m_p4(ParamStorageTraits<P4>::wrap(p4)) 1013 , m_p5(ParamStorageTraits<P5>::wrap(p5)) 1014 , m_p6(ParamStorageTraits<P6>::wrap(p6)) 1015 { 1016 } 1017 1018 virtual typename FunctionWrapper::ResultType operator()() override 1019 { 1020 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), ParamStorageTraits<P4>::unwrap(m_p4), ParamStorageTraits<P5>::unwrap(m_p5), ParamStorageTraits<P6>::unwrap(m_p6)); 1021 } 1022 1023 private: 1024 FunctionWrapper m_functionWrapper; 1025 typename ParamStorageTraits<P1>::StorageType m_p1; 1026 typename ParamStorageTraits<P2>::StorageType m_p2; 1027 typename ParamStorageTraits<P3>::StorageType m_p3; 1028 typename ParamStorageTraits<P4>::StorageType m_p4; 1029 typename ParamStorageTraits<P5>::StorageType m_p5; 1030 typename ParamStorageTraits<P6>::StorageType m_p6; 1031 }; 1032 1033 class FunctionBase { 1034 public: 1035 bool isNull() const 1036 { 1037 return !m_impl; 1038 } 1039 1040 protected: 1041 FunctionBase() 1042 { 1043 } 1044 1045 explicit FunctionBase(PassRefPtr<FunctionImplBase> impl) 1046 : m_impl(impl) 1047 { 1048 } 1049 1050 template<typename FunctionType> FunctionImpl<FunctionType>* impl() const 1051 { 1052 return static_cast<FunctionImpl<FunctionType>*>(m_impl.get()); 1053 } 1054 1055 private: 1056 RefPtr<FunctionImplBase> m_impl; 1057 }; 1058 1059 template<typename> 1060 class Function; 1061 1062 template<typename R> 1063 class Function<R()> : public FunctionBase { 1064 public: 1065 Function() 1066 { 1067 } 1068 1069 Function(PassRefPtr<FunctionImpl<R()> > impl) 1070 : FunctionBase(impl) 1071 { 1072 } 1073 1074 R operator()() const 1075 { 1076 ASSERT(!isNull()); 1077 return impl<R()>()->operator()(); 1078 } 1079 }; 1080 1081 template<typename R, typename A1> 1082 class Function<R(A1)> : public FunctionBase { 1083 public: 1084 Function() 1085 { 1086 } 1087 1088 Function(PassRefPtr<FunctionImpl<R(A1)> > impl) 1089 : FunctionBase(impl) 1090 { 1091 } 1092 1093 R operator()(A1 a1) const 1094 { 1095 ASSERT(!isNull()); 1096 return impl<R(A1)>()->operator()(a1); 1097 } 1098 }; 1099 1100 template<typename R, typename A1, typename A2> 1101 class Function<R(A1, A2)> : public FunctionBase { 1102 public: 1103 Function() 1104 { 1105 } 1106 1107 Function(PassRefPtr<FunctionImpl<R(A1, A2)> > impl) 1108 : FunctionBase(impl) 1109 { 1110 } 1111 1112 R operator()(A1 a1, A2 a2) const 1113 { 1114 ASSERT(!isNull()); 1115 return impl<R(A1, A2)>()->operator()(a1, a2); 1116 } 1117 }; 1118 1119 template<typename R, typename A1, typename A2, typename A3> 1120 class Function<R(A1, A2, A3)> : public FunctionBase { 1121 public: 1122 Function() 1123 { 1124 } 1125 1126 Function(PassRefPtr<FunctionImpl<R(A1, A2, A3)> > impl) 1127 : FunctionBase(impl) 1128 { 1129 } 1130 1131 R operator()(A1 a1, A2 a2, A3 a3) const 1132 { 1133 ASSERT(!isNull()); 1134 return impl<R(A1, A2, A3)>()->operator()(a1, a2, a3); 1135 } 1136 }; 1137 1138 template<typename R, typename A1, typename A2, typename A3, typename A4> 1139 class Function<R(A1, A2, A3, A4)> : public FunctionBase { 1140 public: 1141 Function() 1142 { 1143 } 1144 1145 Function(PassRefPtr<FunctionImpl<R(A1, A2, A3, A4)> > impl) 1146 : FunctionBase(impl) 1147 { 1148 } 1149 1150 R operator()(A1 a1, A2 a2, A3 a3, A4 a4) const 1151 { 1152 ASSERT(!isNull()); 1153 return impl<R(A1, A2, A3, A4)>()->operator()(a1, a2, a3, a4); 1154 } 1155 }; 1156 1157 template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5> 1158 class Function<R(A1, A2, A3, A4, A5)> : public FunctionBase { 1159 public: 1160 Function() 1161 { 1162 } 1163 1164 Function(PassRefPtr<FunctionImpl<R(A1, A2, A3, A4, A5)> > impl) 1165 : FunctionBase(impl) 1166 { 1167 } 1168 1169 R operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const 1170 { 1171 ASSERT(!isNull()); 1172 return impl<R(A1, A2, A3, A4, A5)>()->operator()(a1, a2, a3, a4, a5); 1173 } 1174 }; 1175 1176 template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> 1177 class Function<R(A1, A2, A3, A4, A5, A6)> : public FunctionBase { 1178 public: 1179 Function() 1180 { 1181 } 1182 1183 Function(PassRefPtr<FunctionImpl<R(A1, A2, A3, A4, A5, A6)> > impl) 1184 : FunctionBase(impl) 1185 { 1186 } 1187 1188 R operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const 1189 { 1190 ASSERT(!isNull()); 1191 return impl<R(A1, A2, A3, A4, A5, A6)>()->operator()(a1, a2, a3, a4, a5, a6); 1192 } 1193 }; 1194 1195 template<typename FunctionType> 1196 Function<typename FunctionWrapper<FunctionType>::ResultType()> bind(FunctionType function) 1197 { 1198 return Function<typename FunctionWrapper<FunctionType>::ResultType()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType()>(FunctionWrapper<FunctionType>(function)))); 1199 } 1200 1201 template<typename FunctionType, typename A1> 1202 Function<typename FunctionWrapper<FunctionType>::ResultType()> bind(FunctionType function, const A1& a1) 1203 { 1204 return Function<typename FunctionWrapper<FunctionType>::ResultType()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1)>(FunctionWrapper<FunctionType>(function), a1))); 1205 } 1206 1207 template<typename FunctionType, typename A1, typename A2> 1208 Function<typename FunctionWrapper<FunctionType>::ResultType()> bind(FunctionType function, const A1& a1, const A2& a2) 1209 { 1210 return Function<typename FunctionWrapper<FunctionType>::ResultType()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2)>(FunctionWrapper<FunctionType>(function), a1, a2))); 1211 } 1212 1213 template<typename FunctionType, typename A1, typename A2, typename A3> 1214 Function<typename FunctionWrapper<FunctionType>::ResultType()> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3) 1215 { 1216 return Function<typename FunctionWrapper<FunctionType>::ResultType()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3)>(FunctionWrapper<FunctionType>(function), a1, a2, a3))); 1217 } 1218 1219 template<typename FunctionType, typename A1, typename A2, typename A3, typename A4> 1220 Function<typename FunctionWrapper<FunctionType>::ResultType()> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3, const A4& a4) 1221 { 1222 return Function<typename FunctionWrapper<FunctionType>::ResultType()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4)>(FunctionWrapper<FunctionType>(function), a1, a2, a3, a4))); 1223 } 1224 1225 template<typename FunctionType, typename A1, typename A2, typename A3, typename A4, typename A5> 1226 Function<typename FunctionWrapper<FunctionType>::ResultType()> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) 1227 { 1228 return Function<typename FunctionWrapper<FunctionType>::ResultType()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5)>(FunctionWrapper<FunctionType>(function), a1, a2, a3, a4, a5))); 1229 } 1230 1231 template<typename FunctionType, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> 1232 Function<typename FunctionWrapper<FunctionType>::ResultType()> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6) 1233 { 1234 return Function<typename FunctionWrapper<FunctionType>::ResultType()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5, A6)>(FunctionWrapper<FunctionType>(function), a1, a2, a3, a4, a5, a6))); 1235 } 1236 1237 1238 // Partial parameter binding. 1239 1240 template<typename A1, typename FunctionType> 1241 Function<typename FunctionWrapper<FunctionType>::ResultType(A1)> bind(FunctionType function) 1242 { 1243 return Function<typename FunctionWrapper<FunctionType>::ResultType(A1)>(adoptRef(new UnboundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1)>(FunctionWrapper<FunctionType>(function)))); 1244 } 1245 1246 template<typename A1, typename A2, typename FunctionType> 1247 Function<typename FunctionWrapper<FunctionType>::ResultType(A1, A2)> bind(FunctionType function) 1248 { 1249 return Function<typename FunctionWrapper<FunctionType>::ResultType(A1, A2)>(adoptRef(new UnboundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2)>(FunctionWrapper<FunctionType>(function)))); 1250 } 1251 1252 template<typename A2, typename FunctionType, typename A1> 1253 Function<typename FunctionWrapper<FunctionType>::ResultType(A2)> bind(FunctionType function, const A1& a1) 1254 { 1255 return Function<typename FunctionWrapper<FunctionType>::ResultType(A2)>(adoptRef(new OneArgPartBoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2)>(FunctionWrapper<FunctionType>(function), a1))); 1256 } 1257 1258 template<typename A1, typename A2, typename A3, typename FunctionType> 1259 Function<typename FunctionWrapper<FunctionType>::ResultType(A1, A2, A3)> bind(FunctionType function) 1260 { 1261 return Function<typename FunctionWrapper<FunctionType>::ResultType(A1, A2, A3)>(adoptRef(new UnboundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3)>(FunctionWrapper<FunctionType>(function)))); 1262 } 1263 1264 template<typename A2, typename A3, typename FunctionType, typename A1> 1265 Function<typename FunctionWrapper<FunctionType>::ResultType(A2, A3)> bind(FunctionType function, const A1& a1) 1266 { 1267 return Function<typename FunctionWrapper<FunctionType>::ResultType(A2, A3)>(adoptRef(new OneArgPartBoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3)>(FunctionWrapper<FunctionType>(function), a1))); 1268 } 1269 1270 template<typename A3, typename FunctionType, typename A1, typename A2> 1271 Function<typename FunctionWrapper<FunctionType>::ResultType(A3)> bind(FunctionType function, const A1& a1, const A2& a2) 1272 { 1273 return Function<typename FunctionWrapper<FunctionType>::ResultType(A3)>(adoptRef(new TwoArgPartBoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3)>(FunctionWrapper<FunctionType>(function), a1, a2))); 1274 } 1275 1276 template<typename A1, typename A2, typename A3, typename A4, typename FunctionType> 1277 Function<typename FunctionWrapper<FunctionType>::ResultType(A1, A2, A3, A4)> bind(FunctionType function) 1278 { 1279 return Function<typename FunctionWrapper<FunctionType>::ResultType(A1, A2, A3, A4)>(adoptRef(new UnboundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4)>(FunctionWrapper<FunctionType>(function)))); 1280 } 1281 1282 template<typename A2, typename A3, typename A4, typename FunctionType, typename A1> 1283 Function<typename FunctionWrapper<FunctionType>::ResultType(A2, A3, A4)> bind(FunctionType function, const A1& a1) 1284 { 1285 return Function<typename FunctionWrapper<FunctionType>::ResultType(A2, A3, A4)>(adoptRef(new OneArgPartBoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4)>(FunctionWrapper<FunctionType>(function), a1))); 1286 } 1287 1288 template<typename A3, typename A4, typename FunctionType, typename A1, typename A2> 1289 Function<typename FunctionWrapper<FunctionType>::ResultType(A3, A4)> bind(FunctionType function, const A1& a1, const A2& a2) 1290 { 1291 return Function<typename FunctionWrapper<FunctionType>::ResultType(A3, A4)>(adoptRef(new TwoArgPartBoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4)>(FunctionWrapper<FunctionType>(function), a1, a2))); 1292 } 1293 1294 template<typename A4, typename FunctionType, typename A1, typename A2, typename A3> 1295 Function<typename FunctionWrapper<FunctionType>::ResultType(A4)> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3) 1296 { 1297 return Function<typename FunctionWrapper<FunctionType>::ResultType(A4)>(adoptRef(new ThreeArgPartBoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4)>(FunctionWrapper<FunctionType>(function), a1, a2, a3))); 1298 } 1299 1300 template<typename A1, typename A2, typename A3, typename A4, typename A5, typename FunctionType> 1301 Function<typename FunctionWrapper<FunctionType>::ResultType(A1, A2, A3, A4, A5)> bind(FunctionType function) 1302 { 1303 return Function<typename FunctionWrapper<FunctionType>::ResultType(A1, A2, A3, A4, A5)>(adoptRef(new UnboundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5)>(FunctionWrapper<FunctionType>(function)))); 1304 } 1305 1306 template<typename A2, typename A3, typename A4, typename A5, typename FunctionType, typename A1> 1307 Function<typename FunctionWrapper<FunctionType>::ResultType(A2, A3, A4, A5)> bind(FunctionType function, const A1& a1) 1308 { 1309 return Function<typename FunctionWrapper<FunctionType>::ResultType(A2, A3, A4, A5)>(adoptRef(new OneArgPartBoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5)>(FunctionWrapper<FunctionType>(function), a1))); 1310 } 1311 1312 template<typename A3, typename A4, typename A5, typename FunctionType, typename A1, typename A2> 1313 Function<typename FunctionWrapper<FunctionType>::ResultType(A3, A4, A5)> bind(FunctionType function, const A1& a1, const A2& a2) 1314 { 1315 return Function<typename FunctionWrapper<FunctionType>::ResultType(A3, A4, A5)>(adoptRef(new TwoArgPartBoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5)>(FunctionWrapper<FunctionType>(function), a1, a2))); 1316 } 1317 1318 template<typename A4, typename A5, typename FunctionType, typename A1, typename A2, typename A3> 1319 Function<typename FunctionWrapper<FunctionType>::ResultType(A4, A5)> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3) 1320 { 1321 return Function<typename FunctionWrapper<FunctionType>::ResultType(A4, A5)>(adoptRef(new ThreeArgPartBoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5)>(FunctionWrapper<FunctionType>(function), a1, a2, a3))); 1322 } 1323 1324 template<typename A5, typename FunctionType, typename A1, typename A2, typename A3, typename A4> 1325 Function<typename FunctionWrapper<FunctionType>::ResultType(A5)> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3, const A4& a4) 1326 { 1327 return Function<typename FunctionWrapper<FunctionType>::ResultType(A5)>(adoptRef(new FourArgPartBoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5)>(FunctionWrapper<FunctionType>(function), a1, a2, a3, a4))); 1328 } 1329 1330 template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename FunctionType> 1331 Function<typename FunctionWrapper<FunctionType>::ResultType(A1, A2, A3, A4, A5, A6)> bind(FunctionType function) 1332 { 1333 return Function<typename FunctionWrapper<FunctionType>::ResultType(A1, A2, A3, A4, A5, A6)>(adoptRef(new UnboundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5, A6)>(FunctionWrapper<FunctionType>(function)))); 1334 } 1335 1336 template<typename A2, typename A3, typename A4, typename A5, typename A6, typename FunctionType, typename A1> 1337 Function<typename FunctionWrapper<FunctionType>::ResultType(A2, A3, A4, A5, A6)> bind(FunctionType function, const A1& a1) 1338 { 1339 return Function<typename FunctionWrapper<FunctionType>::ResultType(A2, A3, A4, A5, A6)>(adoptRef(new OneArgPartBoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5, A6)>(FunctionWrapper<FunctionType>(function), a1))); 1340 } 1341 1342 template<typename A3, typename A4, typename A5, typename A6, typename FunctionType, typename A1, typename A2> 1343 Function<typename FunctionWrapper<FunctionType>::ResultType(A3, A4, A5, A6)> bind(FunctionType function, const A1& a1, const A2& a2) 1344 { 1345 return Function<typename FunctionWrapper<FunctionType>::ResultType(A3, A4, A5, A6)>(adoptRef(new TwoArgPartBoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5, A6)>(FunctionWrapper<FunctionType>(function), a1, a2))); 1346 } 1347 1348 template<typename A4, typename A5, typename A6, typename FunctionType, typename A1, typename A2, typename A3> 1349 Function<typename FunctionWrapper<FunctionType>::ResultType(A4, A5, A6)> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3) 1350 { 1351 return Function<typename FunctionWrapper<FunctionType>::ResultType(A4, A5, A6)>(adoptRef(new ThreeArgPartBoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5, A6)>(FunctionWrapper<FunctionType>(function), a1, a2, a3))); 1352 } 1353 1354 template<typename A5, typename A6, typename FunctionType, typename A1, typename A2, typename A3, typename A4> 1355 Function<typename FunctionWrapper<FunctionType>::ResultType(A5, A6)> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3, const A4& a4) 1356 { 1357 return Function<typename FunctionWrapper<FunctionType>::ResultType(A5, A6)>(adoptRef(new FourArgPartBoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5, A6)>(FunctionWrapper<FunctionType>(function), a1, a2, a3, a4))); 1358 } 1359 1360 template<typename A6, typename FunctionType, typename A1, typename A2, typename A3, typename A4, typename A5> 1361 Function<typename FunctionWrapper<FunctionType>::ResultType(A6)> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) 1362 { 1363 return Function<typename FunctionWrapper<FunctionType>::ResultType(A6)>(adoptRef(new FiveArgPartBoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5, A6)>(FunctionWrapper<FunctionType>(function), a1, a2, a3, a4, a5))); 1364 } 1365 1366 typedef Function<void()> Closure; 1367 1368 } 1369 1370 using WTF::Function; 1371 using WTF::bind; 1372 using WTF::Closure; 1373 1374 #endif // WTF_Functional_h 1375