OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // A Tuple is a generic templatized container, similar in concept to std::pair. | 5 // A Tuple is a generic templatized container, similar in concept to std::pair. |
6 // There are classes Tuple0 to Tuple6, cooresponding to the number of elements | 6 // There are classes Tuple0 to Tuple6, cooresponding to the number of elements |
7 // it contains. The convenient MakeTuple() function takes 0 to 6 arguments, | 7 // it contains. The convenient MakeTuple() function takes 0 to 6 arguments, |
8 // and will construct and return the appropriate Tuple object. The functions | 8 // and will construct and return the appropriate Tuple object. The functions |
9 // DispatchToMethod and DispatchToFunction take a function pointer or instance | 9 // DispatchToMethod and DispatchToFunction take a function pointer or instance |
10 // and method pointer, and unpack a tuple into arguments to the call. | 10 // and method pointer, and unpack a tuple into arguments to the call. |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 300 |
301 A a; | 301 A a; |
302 B b; | 302 B b; |
303 C c; | 303 C c; |
304 D d; | 304 D d; |
305 E e; | 305 E e; |
306 F f; | 306 F f; |
307 G g; | 307 G g; |
308 }; | 308 }; |
309 | 309 |
| 310 template <class A, class B, class C, class D, class E, class F, class G, |
| 311 class H> |
| 312 struct Tuple8 { |
| 313 public: |
| 314 typedef A TypeA; |
| 315 typedef B TypeB; |
| 316 typedef C TypeC; |
| 317 typedef D TypeD; |
| 318 typedef E TypeE; |
| 319 typedef F TypeF; |
| 320 typedef G TypeG; |
| 321 typedef H TypeH; |
| 322 typedef Tuple8<typename TupleTraits<A>::ValueType, |
| 323 typename TupleTraits<B>::ValueType, |
| 324 typename TupleTraits<C>::ValueType, |
| 325 typename TupleTraits<D>::ValueType, |
| 326 typename TupleTraits<E>::ValueType, |
| 327 typename TupleTraits<F>::ValueType, |
| 328 typename TupleTraits<G>::ValueType, |
| 329 typename TupleTraits<H>::ValueType> ValueTuple; |
| 330 typedef Tuple8<typename TupleTraits<A>::RefType, |
| 331 typename TupleTraits<B>::RefType, |
| 332 typename TupleTraits<C>::RefType, |
| 333 typename TupleTraits<D>::RefType, |
| 334 typename TupleTraits<E>::RefType, |
| 335 typename TupleTraits<F>::RefType, |
| 336 typename TupleTraits<G>::RefType, |
| 337 typename TupleTraits<H>::RefType> RefTuple; |
| 338 typedef Tuple8<typename TupleTraits<A>::ParamType, |
| 339 typename TupleTraits<B>::ParamType, |
| 340 typename TupleTraits<C>::ParamType, |
| 341 typename TupleTraits<D>::ParamType, |
| 342 typename TupleTraits<E>::ParamType, |
| 343 typename TupleTraits<F>::ParamType, |
| 344 typename TupleTraits<G>::ParamType, |
| 345 typename TupleTraits<H>::ParamType> ParamTuple; |
| 346 |
| 347 Tuple8() {} |
| 348 Tuple8(typename TupleTraits<A>::ParamType a, |
| 349 typename TupleTraits<B>::ParamType b, |
| 350 typename TupleTraits<C>::ParamType c, |
| 351 typename TupleTraits<D>::ParamType d, |
| 352 typename TupleTraits<E>::ParamType e, |
| 353 typename TupleTraits<F>::ParamType f, |
| 354 typename TupleTraits<G>::ParamType g, |
| 355 typename TupleTraits<H>::ParamType h) |
| 356 : a(a), b(b), c(c), d(d), e(e), f(f), g(g), h(h) { |
| 357 } |
| 358 |
| 359 A a; |
| 360 B b; |
| 361 C c; |
| 362 D d; |
| 363 E e; |
| 364 F f; |
| 365 G g; |
| 366 H h; |
| 367 }; |
| 368 |
310 // Tuple creators ------------------------------------------------------------- | 369 // Tuple creators ------------------------------------------------------------- |
311 // | 370 // |
312 // Helper functions for constructing tuples while inferring the template | 371 // Helper functions for constructing tuples while inferring the template |
313 // argument types. | 372 // argument types. |
314 | 373 |
315 inline Tuple0 MakeTuple() { | 374 inline Tuple0 MakeTuple() { |
316 return Tuple0(); | 375 return Tuple0(); |
317 } | 376 } |
318 | 377 |
319 template <class A> | 378 template <class A> |
(...skipping 29 matching lines...) Expand all Loading... |
349 return Tuple6<A, B, C, D, E, F>(a, b, c, d, e, f); | 408 return Tuple6<A, B, C, D, E, F>(a, b, c, d, e, f); |
350 } | 409 } |
351 | 410 |
352 template <class A, class B, class C, class D, class E, class F, class G> | 411 template <class A, class B, class C, class D, class E, class F, class G> |
353 inline Tuple7<A, B, C, D, E, F, G> MakeTuple(const A& a, const B& b, const C& c, | 412 inline Tuple7<A, B, C, D, E, F, G> MakeTuple(const A& a, const B& b, const C& c, |
354 const D& d, const E& e, const F& f, | 413 const D& d, const E& e, const F& f, |
355 const G& g) { | 414 const G& g) { |
356 return Tuple7<A, B, C, D, E, F, G>(a, b, c, d, e, f, g); | 415 return Tuple7<A, B, C, D, E, F, G>(a, b, c, d, e, f, g); |
357 } | 416 } |
358 | 417 |
| 418 template <class A, class B, class C, class D, class E, class F, class G, |
| 419 class H> |
| 420 inline Tuple8<A, B, C, D, E, F, G, H> MakeTuple(const A& a, const B& b, |
| 421 const C& c, const D& d, |
| 422 const E& e, const F& f, |
| 423 const G& g, const H& h) { |
| 424 return Tuple8<A, B, C, D, E, F, G, H>(a, b, c, d, e, f, g, h); |
| 425 } |
| 426 |
359 // The following set of helpers make what Boost refers to as "Tiers" - a tuple | 427 // The following set of helpers make what Boost refers to as "Tiers" - a tuple |
360 // of references. | 428 // of references. |
361 | 429 |
362 template <class A> | 430 template <class A> |
363 inline Tuple1<A&> MakeRefTuple(A& a) { | 431 inline Tuple1<A&> MakeRefTuple(A& a) { |
364 return Tuple1<A&>(a); | 432 return Tuple1<A&>(a); |
365 } | 433 } |
366 | 434 |
367 template <class A, class B> | 435 template <class A, class B> |
368 inline Tuple2<A&, B&> MakeRefTuple(A& a, B& b) { | 436 inline Tuple2<A&, B&> MakeRefTuple(A& a, B& b) { |
(...skipping 20 matching lines...) Expand all Loading... |
389 F& f) { | 457 F& f) { |
390 return Tuple6<A&, B&, C&, D&, E&, F&>(a, b, c, d, e, f); | 458 return Tuple6<A&, B&, C&, D&, E&, F&>(a, b, c, d, e, f); |
391 } | 459 } |
392 | 460 |
393 template <class A, class B, class C, class D, class E, class F, class G> | 461 template <class A, class B, class C, class D, class E, class F, class G> |
394 inline Tuple7<A&, B&, C&, D&, E&, F&, G&> MakeRefTuple(A& a, B& b, C& c, D& d, | 462 inline Tuple7<A&, B&, C&, D&, E&, F&, G&> MakeRefTuple(A& a, B& b, C& c, D& d, |
395 E& e, F& f, G& g) { | 463 E& e, F& f, G& g) { |
396 return Tuple7<A&, B&, C&, D&, E&, F&, G&>(a, b, c, d, e, f, g); | 464 return Tuple7<A&, B&, C&, D&, E&, F&, G&>(a, b, c, d, e, f, g); |
397 } | 465 } |
398 | 466 |
| 467 template <class A, class B, class C, class D, class E, class F, class G, |
| 468 class H> |
| 469 inline Tuple8<A&, B&, C&, D&, E&, F&, G&, H&> MakeRefTuple(A& a, B& b, C& c, |
| 470 D& d, E& e, F& f, |
| 471 G& g, H& h) { |
| 472 return Tuple8<A&, B&, C&, D&, E&, F&, G&, H&>(a, b, c, d, e, f, g, h); |
| 473 } |
| 474 |
399 // Dispatchers ---------------------------------------------------------------- | 475 // Dispatchers ---------------------------------------------------------------- |
400 // | 476 // |
401 // Helper functions that call the given method on an object, with the unpacked | 477 // Helper functions that call the given method on an object, with the unpacked |
402 // tuple arguments. Notice that they all have the same number of arguments, | 478 // tuple arguments. Notice that they all have the same number of arguments, |
403 // so you need only write: | 479 // so you need only write: |
404 // DispatchToMethod(object, &Object::method, args); | 480 // DispatchToMethod(object, &Object::method, args); |
405 // This is very useful for templated dispatchers, since they don't need to know | 481 // This is very useful for templated dispatchers, since they don't need to know |
406 // what type |args| is. | 482 // what type |args| is. |
407 | 483 |
408 // Non-Static Dispatchers with no out params. | 484 // Non-Static Dispatchers with no out params. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 const Tuple5<A, B, C, D, E>& arg) { | 575 const Tuple5<A, B, C, D, E>& arg) { |
500 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e); | 576 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e); |
501 } | 577 } |
502 | 578 |
503 template<class Function, class A, class B, class C, class D, class E, class F> | 579 template<class Function, class A, class B, class C, class D, class E, class F> |
504 inline void DispatchToFunction(Function function, | 580 inline void DispatchToFunction(Function function, |
505 const Tuple6<A, B, C, D, E, F>& arg) { | 581 const Tuple6<A, B, C, D, E, F>& arg) { |
506 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f); | 582 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f); |
507 } | 583 } |
508 | 584 |
| 585 template<class Function, class A, class B, class C, class D, class E, class F, |
| 586 class G> |
| 587 inline void DispatchToFunction(Function function, |
| 588 const Tuple7<A, B, C, D, E, F, G>& arg) { |
| 589 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g); |
| 590 } |
| 591 |
| 592 template<class Function, class A, class B, class C, class D, class E, class F, |
| 593 class G, class H> |
| 594 inline void DispatchToFunction(Function function, |
| 595 const Tuple8<A, B, C, D, E, F, G, H>& arg) { |
| 596 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g, arg.h); |
| 597 } |
| 598 |
509 // Dispatchers with 0 out param (as a Tuple0). | 599 // Dispatchers with 0 out param (as a Tuple0). |
510 | 600 |
511 template <class ObjT, class Method> | 601 template <class ObjT, class Method> |
512 inline void DispatchToMethod(ObjT* obj, | 602 inline void DispatchToMethod(ObjT* obj, |
513 Method method, | 603 Method method, |
514 const Tuple0& arg, Tuple0*) { | 604 const Tuple0& arg, Tuple0*) { |
515 (obj->*method)(); | 605 (obj->*method)(); |
516 } | 606 } |
517 | 607 |
518 template <class ObjT, class Method, class A> | 608 template <class ObjT, class Method, class A> |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 class InA, class InB, class InC, class InD, class InE, class InF, | 987 class InA, class InB, class InC, class InD, class InE, class InF, |
898 class OutA, class OutB, class OutC, class OutD, class OutE> | 988 class OutA, class OutB, class OutC, class OutD, class OutE> |
899 inline void DispatchToMethod(ObjT* obj, Method method, | 989 inline void DispatchToMethod(ObjT* obj, Method method, |
900 const Tuple6<InA, InB, InC, InD, InE, InF>& in, | 990 const Tuple6<InA, InB, InC, InD, InE, InF>& in, |
901 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { | 991 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
902 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, | 992 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, |
903 &out->a, &out->b, &out->c, &out->d, &out->e); | 993 &out->a, &out->b, &out->c, &out->d, &out->e); |
904 } | 994 } |
905 | 995 |
906 #endif // BASE_TUPLE_H__ | 996 #endif // BASE_TUPLE_H__ |
OLD | NEW |