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 12 matching lines...) Expand all Loading... |
23 // &SomeFunc, MakeTuple(10, "foo")); // SomeFunc(10, "foo") | 23 // &SomeFunc, MakeTuple(10, "foo")); // SomeFunc(10, "foo") |
24 // | 24 // |
25 // struct { void SomeMeth(int a, int b, int c) { } } foo; | 25 // struct { void SomeMeth(int a, int b, int c) { } } foo; |
26 // DispatchToMethod(&foo, &Foo::SomeMeth, MakeTuple(1, 2, 3)); | 26 // DispatchToMethod(&foo, &Foo::SomeMeth, MakeTuple(1, 2, 3)); |
27 // // foo->SomeMeth(1, 2, 3); | 27 // // foo->SomeMeth(1, 2, 3); |
28 | 28 |
29 #ifndef BASE_TUPLE_H__ | 29 #ifndef BASE_TUPLE_H__ |
30 #define BASE_TUPLE_H__ | 30 #define BASE_TUPLE_H__ |
31 #pragma once | 31 #pragma once |
32 | 32 |
| 33 #if defined(OS_CHROMEOS) |
| 34 // To troubleshoot crosbug.com/7327. |
| 35 #include "base/logging.h" |
| 36 #endif |
33 // Traits ---------------------------------------------------------------------- | 37 // Traits ---------------------------------------------------------------------- |
34 // | 38 // |
35 // A simple traits class for tuple arguments. | 39 // A simple traits class for tuple arguments. |
36 // | 40 // |
37 // ValueType: the bare, nonref version of a type (same as the type for nonrefs). | 41 // ValueType: the bare, nonref version of a type (same as the type for nonrefs). |
38 // RefType: the ref version of a type (same as the type for refs). | 42 // RefType: the ref version of a type (same as the type for refs). |
39 // ParamType: what type to pass to functions (refs should not be constified). | 43 // ParamType: what type to pass to functions (refs should not be constified). |
40 | 44 |
41 template <class P> | 45 template <class P> |
42 struct TupleTraits { | 46 struct TupleTraits { |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 } | 542 } |
539 | 543 |
540 template <class ObjT, class Method, class A> | 544 template <class ObjT, class Method, class A> |
541 inline void DispatchToMethod(ObjT* obj, Method method, const A& arg) { | 545 inline void DispatchToMethod(ObjT* obj, Method method, const A& arg) { |
542 (obj->*method)(arg); | 546 (obj->*method)(arg); |
543 } | 547 } |
544 | 548 |
545 template <class ObjT, class Method, class A> | 549 template <class ObjT, class Method, class A> |
546 inline void DispatchToMethod(ObjT* obj, Method method, const Tuple1<A>& arg) { | 550 inline void DispatchToMethod(ObjT* obj, Method method, const Tuple1<A>& arg) { |
547 | 551 |
548 #if defined(OS_CHROMEOS) && defined(CHECK) | 552 #if defined(OS_CHROMEOS) |
549 // To troubleshoot crosbug.com/7327. | 553 // To troubleshoot crosbug.com/7327. |
550 CHECK(obj); | 554 CHECK(obj); |
551 CHECK(&arg); | 555 CHECK(&arg); |
552 CHECK(method); | 556 CHECK(method); |
553 #endif | 557 #endif |
554 (obj->*method)(arg.a); | 558 (obj->*method)(arg.a); |
555 } | 559 } |
556 | 560 |
557 template<class ObjT, class Method, class A, class B> | 561 template<class ObjT, class Method, class A, class B> |
558 inline void DispatchToMethod(ObjT* obj, | 562 inline void DispatchToMethod(ObjT* obj, |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 class InA, class InB, class InC, class InD, class InE, class InF, | 1047 class InA, class InB, class InC, class InD, class InE, class InF, |
1044 class OutA, class OutB, class OutC, class OutD, class OutE> | 1048 class OutA, class OutB, class OutC, class OutD, class OutE> |
1045 inline void DispatchToMethod(ObjT* obj, Method method, | 1049 inline void DispatchToMethod(ObjT* obj, Method method, |
1046 const Tuple6<InA, InB, InC, InD, InE, InF>& in, | 1050 const Tuple6<InA, InB, InC, InD, InE, InF>& in, |
1047 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { | 1051 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
1048 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, | 1052 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, |
1049 &out->a, &out->b, &out->c, &out->d, &out->e); | 1053 &out->a, &out->b, &out->c, &out->d, &out->e); |
1050 } | 1054 } |
1051 | 1055 |
1052 #endif // BASE_TUPLE_H__ | 1056 #endif // BASE_TUPLE_H__ |
OLD | NEW |