blob: 8fd965fab888f4141b72e52d986f44ed8009c797 [file] [log] [blame]
license.botf003cfe2008-08-24 09:55:55 +09001// 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
3// found in the LICENSE file.
initial.commit3f4a7322008-07-27 06:49:38 +09004
deanm@google.com96aac0a2008-08-25 22:42:07 +09005// A Tuple is a generic templatized container, similar in concept to std::pair.
ojan@google.com38355092008-10-10 06:58:05 +09006// There are classes Tuple0 to Tuple6, cooresponding to the number of elements
7// it contains. The convenient MakeTuple() function takes 0 to 6 arguments,
deanm@google.com96aac0a2008-08-25 22:42:07 +09008// and will construct and return the appropriate Tuple object. The functions
9// DispatchToMethod and DispatchToFunction take a function pointer or instance
10// and method pointer, and unpack a tuple into arguments to the call.
11//
12// Tuple elements are copied by value, and stored in the tuple. See the unit
13// tests for more details of how/when the values are copied.
14//
15// Example usage:
16// // These two methods of creating a Tuple are identical.
17// Tuple2<int, const char*> tuple_a(1, "wee");
18// Tuple2<int, const char*> tuple_b = MakeTuple(1, "wee");
19//
20// void SomeFunc(int a, const char* b) { }
21// DispatchToFunction(&SomeFunc, tuple_a); // SomeFunc(1, "wee")
22// DispatchToFunction(
23// &SomeFunc, MakeTuple(10, "foo")); // SomeFunc(10, "foo")
24//
25// struct { void SomeMeth(int a, int b, int c) { } } foo;
26// DispatchToMethod(&foo, &Foo::SomeMeth, MakeTuple(1, 2, 3));
27// // foo->SomeMeth(1, 2, 3);
28
initial.commit3f4a7322008-07-27 06:49:38 +090029#ifndef BASE_TUPLE_H__
30#define BASE_TUPLE_H__
31
32// Traits ----------------------------------------------------------------------
33//
34// A simple traits class for tuple arguments.
35//
36// ValueType: the bare, nonref version of a type (same as the type for nonrefs).
37// RefType: the ref version of a type (same as the type for refs).
38// ParamType: what type to pass to functions (refs should not be constified).
39
40template <class P>
41struct TupleTraits {
42 typedef P ValueType;
43 typedef P& RefType;
44 typedef const P& ParamType;
45};
46
47template <class P>
48struct TupleTraits<P&> {
49 typedef P ValueType;
50 typedef P& RefType;
51 typedef P& ParamType;
52};
53
54// Tuple -----------------------------------------------------------------------
55//
56// This set of classes is useful for bundling 0 or more heterogeneous data types
57// into a single variable. The advantage of this is that it greatly simplifies
58// function objects that need to take an arbitrary number of parameters; see
59// RunnableMethod and IPC::MessageWithTuple.
60//
deanm@google.comff4b7292008-08-21 19:58:08 +090061// Tuple0 is supplied to act as a 'void' type. It can be used, for example,
62// when dispatching to a function that accepts no arguments (see the
63// Dispatchers below).
initial.commit3f4a7322008-07-27 06:49:38 +090064// Tuple1<A> is rarely useful. One such use is when A is non-const ref that you
65// want filled by the dispatchee, and the tuple is merely a container for that
66// output (a "tier"). See MakeRefTuple and its usages.
67
68struct Tuple0 {
69 typedef Tuple0 ValueTuple;
70 typedef Tuple0 RefTuple;
71};
72
73template <class A>
74struct Tuple1 {
75 public:
76 typedef A TypeA;
77 typedef Tuple1<typename TupleTraits<A>::ValueType> ValueTuple;
78 typedef Tuple1<typename TupleTraits<A>::RefType> RefTuple;
79
80 Tuple1() {}
81 explicit Tuple1(typename TupleTraits<A>::ParamType a) : a(a) {}
82
83 A a;
84};
85
86template <class A, class B>
87struct Tuple2 {
88 public:
89 typedef A TypeA;
90 typedef B TypeB;
91 typedef Tuple2<typename TupleTraits<A>::ValueType,
92 typename TupleTraits<B>::ValueType> ValueTuple;
93 typedef Tuple2<typename TupleTraits<A>::RefType,
94 typename TupleTraits<B>::RefType> RefTuple;
95
96 Tuple2() {}
97 Tuple2(typename TupleTraits<A>::ParamType a,
98 typename TupleTraits<B>::ParamType b)
99 : a(a), b(b) {
100 }
101
102 A a;
103 B b;
104};
105
106template <class A, class B, class C>
107struct Tuple3 {
108 public:
109 typedef A TypeA;
110 typedef B TypeB;
111 typedef C TypeC;
112 typedef Tuple3<typename TupleTraits<A>::ValueType,
113 typename TupleTraits<B>::ValueType,
114 typename TupleTraits<C>::ValueType> ValueTuple;
115 typedef Tuple3<typename TupleTraits<A>::RefType,
116 typename TupleTraits<B>::RefType,
117 typename TupleTraits<C>::RefType> RefTuple;
118
119 Tuple3() {}
120 Tuple3(typename TupleTraits<A>::ParamType a,
121 typename TupleTraits<B>::ParamType b,
122 typename TupleTraits<C>::ParamType c)
123 : a(a), b(b), c(c){
124 }
125
126 A a;
127 B b;
128 C c;
129};
130
131template <class A, class B, class C, class D>
132struct Tuple4 {
133 public:
134 typedef A TypeA;
135 typedef B TypeB;
136 typedef C TypeC;
137 typedef D TypeD;
138 typedef Tuple4<typename TupleTraits<A>::ValueType,
139 typename TupleTraits<B>::ValueType,
140 typename TupleTraits<C>::ValueType,
141 typename TupleTraits<D>::ValueType> ValueTuple;
142 typedef Tuple4<typename TupleTraits<A>::RefType,
143 typename TupleTraits<B>::RefType,
144 typename TupleTraits<C>::RefType,
145 typename TupleTraits<D>::RefType> RefTuple;
146
147 Tuple4() {}
148 Tuple4(typename TupleTraits<A>::ParamType a,
149 typename TupleTraits<B>::ParamType b,
150 typename TupleTraits<C>::ParamType c,
151 typename TupleTraits<D>::ParamType d)
152 : a(a), b(b), c(c), d(d) {
153 }
154
155 A a;
156 B b;
157 C c;
158 D d;
159};
160
161template <class A, class B, class C, class D, class E>
162struct Tuple5 {
163public:
164 typedef A TypeA;
165 typedef B TypeB;
166 typedef C TypeC;
167 typedef D TypeD;
168 typedef E TypeE;
169 typedef Tuple5<typename TupleTraits<A>::ValueType,
170 typename TupleTraits<B>::ValueType,
171 typename TupleTraits<C>::ValueType,
172 typename TupleTraits<D>::ValueType,
173 typename TupleTraits<E>::ValueType> ValueTuple;
174 typedef Tuple5<typename TupleTraits<A>::RefType,
175 typename TupleTraits<B>::RefType,
176 typename TupleTraits<C>::RefType,
177 typename TupleTraits<D>::RefType,
178 typename TupleTraits<E>::RefType> RefTuple;
179
180 Tuple5() {}
181 Tuple5(typename TupleTraits<A>::ParamType a,
182 typename TupleTraits<B>::ParamType b,
183 typename TupleTraits<C>::ParamType c,
184 typename TupleTraits<D>::ParamType d,
185 typename TupleTraits<E>::ParamType e)
186 : a(a), b(b), c(c), d(d), e(e) {
187 }
188
189 A a;
190 B b;
191 C c;
192 D d;
193 E e;
194};
195
ojan@google.com38355092008-10-10 06:58:05 +0900196template <class A, class B, class C, class D, class E, class F>
197struct Tuple6 {
198public:
199 typedef A TypeA;
200 typedef B TypeB;
201 typedef C TypeC;
202 typedef D TypeD;
203 typedef E TypeE;
204 typedef F TypeF;
205 typedef Tuple6<typename TupleTraits<A>::ValueType,
206 typename TupleTraits<B>::ValueType,
207 typename TupleTraits<C>::ValueType,
208 typename TupleTraits<D>::ValueType,
209 typename TupleTraits<E>::ValueType,
210 typename TupleTraits<F>::ValueType> ValueTuple;
211 typedef Tuple6<typename TupleTraits<A>::RefType,
212 typename TupleTraits<B>::RefType,
213 typename TupleTraits<C>::RefType,
214 typename TupleTraits<D>::RefType,
215 typename TupleTraits<E>::RefType,
216 typename TupleTraits<F>::RefType> RefTuple;
217
218 Tuple6() {}
219 Tuple6(typename TupleTraits<A>::ParamType a,
220 typename TupleTraits<B>::ParamType b,
221 typename TupleTraits<C>::ParamType c,
222 typename TupleTraits<D>::ParamType d,
223 typename TupleTraits<E>::ParamType e,
224 typename TupleTraits<F>::ParamType f)
225 : a(a), b(b), c(c), d(d), e(e), f(f) {
226 }
227
228 A a;
229 B b;
230 C c;
231 D d;
232 E e;
233 F f;
234};
235
sky@google.com67c35752008-11-13 07:10:20 +0900236template <class A, class B, class C, class D, class E, class F, class G>
237struct Tuple7 {
238public:
239 typedef A TypeA;
240 typedef B TypeB;
241 typedef C TypeC;
242 typedef D TypeD;
243 typedef E TypeE;
244 typedef F TypeF;
245 typedef G TypeG;
246 typedef Tuple7<typename TupleTraits<A>::ValueType,
247 typename TupleTraits<B>::ValueType,
248 typename TupleTraits<C>::ValueType,
249 typename TupleTraits<D>::ValueType,
250 typename TupleTraits<E>::ValueType,
251 typename TupleTraits<F>::ValueType,
252 typename TupleTraits<G>::ValueType> ValueTuple;
253 typedef Tuple7<typename TupleTraits<A>::RefType,
254 typename TupleTraits<B>::RefType,
255 typename TupleTraits<C>::RefType,
256 typename TupleTraits<D>::RefType,
257 typename TupleTraits<E>::RefType,
258 typename TupleTraits<F>::RefType,
259 typename TupleTraits<G>::RefType> RefTuple;
260
261 Tuple7() {}
262 Tuple7(typename TupleTraits<A>::ParamType a,
263 typename TupleTraits<B>::ParamType b,
264 typename TupleTraits<C>::ParamType c,
265 typename TupleTraits<D>::ParamType d,
266 typename TupleTraits<E>::ParamType e,
267 typename TupleTraits<F>::ParamType f,
268 typename TupleTraits<G>::ParamType g)
269 : a(a), b(b), c(c), d(d), e(e), f(f), g(g) {
270 }
271
272 A a;
273 B b;
274 C c;
275 D d;
276 E e;
277 F f;
278 G g;
279};
280
initial.commit3f4a7322008-07-27 06:49:38 +0900281// Tuple creators -------------------------------------------------------------
282//
283// Helper functions for constructing tuples while inferring the template
284// argument types.
285
286inline Tuple0 MakeTuple() {
287 return Tuple0();
288}
289
290template <class A>
291inline Tuple1<A> MakeTuple(const A& a) {
292 return Tuple1<A>(a);
293}
294
295template <class A, class B>
296inline Tuple2<A, B> MakeTuple(const A& a, const B& b) {
297 return Tuple2<A, B>(a, b);
298}
299
300template <class A, class B, class C>
301inline Tuple3<A, B, C> MakeTuple(const A& a, const B& b, const C& c) {
302 return Tuple3<A, B, C>(a, b, c);
303}
304
305template <class A, class B, class C, class D>
306inline Tuple4<A, B, C, D> MakeTuple(const A& a, const B& b, const C& c,
307 const D& d) {
308 return Tuple4<A, B, C, D>(a, b, c, d);
309}
310
311template <class A, class B, class C, class D, class E>
312inline Tuple5<A, B, C, D, E> MakeTuple(const A& a, const B& b, const C& c,
313 const D& d, const E& e) {
314 return Tuple5<A, B, C, D, E>(a, b, c, d, e);
315}
316
ojan@google.com38355092008-10-10 06:58:05 +0900317template <class A, class B, class C, class D, class E, class F>
318inline Tuple6<A, B, C, D, E, F> MakeTuple(const A& a, const B& b, const C& c,
319 const D& d, const E& e, const F& f) {
320 return Tuple6<A, B, C, D, E, F>(a, b, c, d, e, f);
321}
322
sky@google.com67c35752008-11-13 07:10:20 +0900323template <class A, class B, class C, class D, class E, class F, class G>
324inline Tuple7<A, B, C, D, E, F, G> MakeTuple(const A& a, const B& b, const C& c,
325 const D& d, const E& e, const F& f,
326 const G& g) {
327 return Tuple7<A, B, C, D, E, F, G>(a, b, c, d, e, f, g);
328}
329
initial.commit3f4a7322008-07-27 06:49:38 +0900330// The following set of helpers make what Boost refers to as "Tiers" - a tuple
331// of references.
332
333template <class A>
334inline Tuple1<A&> MakeRefTuple(A& a) {
335 return Tuple1<A&>(a);
336}
337
338template <class A, class B>
339inline Tuple2<A&, B&> MakeRefTuple(A& a, B& b) {
340 return Tuple2<A&, B&>(a, b);
341}
342
343template <class A, class B, class C>
344inline Tuple3<A&, B&, C&> MakeRefTuple(A& a, B& b, C& c) {
345 return Tuple3<A&, B&, C&>(a, b, c);
346}
347
348template <class A, class B, class C, class D>
349inline Tuple4<A&, B&, C&, D&> MakeRefTuple(A& a, B& b, C& c, D& d) {
350 return Tuple4<A&, B&, C&, D&>(a, b, c, d);
351}
352
353template <class A, class B, class C, class D, class E>
354inline Tuple5<A&, B&, C&, D&, E&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e) {
355 return Tuple5<A&, B&, C&, D&, E&>(a, b, c, d, e);
356}
357
ojan@google.com38355092008-10-10 06:58:05 +0900358template <class A, class B, class C, class D, class E, class F>
359inline Tuple6<A&, B&, C&, D&, E&, F&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e,
360 F& f) {
361 return Tuple6<A&, B&, C&, D&, E&, F&>(a, b, c, d, e, f);
362}
363
sky@google.com67c35752008-11-13 07:10:20 +0900364template <class A, class B, class C, class D, class E, class F, class G>
365inline Tuple7<A&, B&, C&, D&, E&, F&, G&> MakeRefTuple(A& a, B& b, C& c, D& d,
366 E& e, F& f, G& g) {
367 return Tuple7<A&, B&, C&, D&, E&, F&, G&>(a, b, c, d, e, f, g);
368}
369
initial.commit3f4a7322008-07-27 06:49:38 +0900370// Dispatchers ----------------------------------------------------------------
371//
372// Helper functions that call the given method on an object, with the unpacked
373// tuple arguments. Notice that they all have the same number of arguments,
374// so you need only write:
375// DispatchToMethod(object, &Object::method, args);
376// This is very useful for templated dispatchers, since they don't need to know
377// what type |args| is.
378
379// Non-Static Dispatchers with no out params.
380
381template <class ObjT, class Method>
382inline void DispatchToMethod(ObjT* obj, Method method, const Tuple0& arg) {
383 (obj->*method)();
384}
385
386template <class ObjT, class Method, class A>
387inline void DispatchToMethod(ObjT* obj, Method method, const A& arg) {
388 (obj->*method)(arg);
389}
390
391template <class ObjT, class Method, class A>
392inline void DispatchToMethod(ObjT* obj, Method method, const Tuple1<A>& arg) {
393 (obj->*method)(arg.a);
394}
395
396template<class ObjT, class Method, class A, class B>
397inline void DispatchToMethod(ObjT* obj, Method method, const Tuple2<A, B>& arg) {
398 (obj->*method)(arg.a, arg.b);
399}
400
401template<class ObjT, class Method, class A, class B, class C>
402inline void DispatchToMethod(ObjT* obj, Method method,
403 const Tuple3<A, B, C>& arg) {
404 (obj->*method)(arg.a, arg.b, arg.c);
405}
406
407template<class ObjT, class Method, class A, class B, class C, class D>
408inline void DispatchToMethod(ObjT* obj, Method method,
409 const Tuple4<A, B, C, D>& arg) {
410 (obj->*method)(arg.a, arg.b, arg.c, arg.d);
411}
412
413template<class ObjT, class Method, class A, class B, class C, class D, class E>
414inline void DispatchToMethod(ObjT* obj, Method method,
415 const Tuple5<A, B, C, D, E>& arg) {
416 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e);
417}
418
ojan@google.com38355092008-10-10 06:58:05 +0900419template<class ObjT, class Method, class A, class B, class C, class D, class E,
420 class F>
421inline void DispatchToMethod(ObjT* obj, Method method,
422 const Tuple6<A, B, C, D, E, F>& arg) {
423 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
424}
425
sky@google.com67c35752008-11-13 07:10:20 +0900426template<class ObjT, class Method, class A, class B, class C, class D, class E,
427 class F, class G>
428inline void DispatchToMethod(ObjT* obj, Method method,
429 const Tuple7<A, B, C, D, E, F, G>& arg) {
430 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g);
431}
432
initial.commit3f4a7322008-07-27 06:49:38 +0900433// Static Dispatchers with no out params.
434
435template <class Function>
436inline void DispatchToFunction(Function function, const Tuple0& arg) {
437 (*function)();
438}
439
440template <class Function, class A>
441inline void DispatchToFunction(Function function, const A& arg) {
442 (*function)(arg);
443}
444
445template <class Function, class A>
446inline void DispatchToFunction(Function function, const Tuple1<A>& arg) {
447 (*function)(arg.a);
448}
449
450template<class Function, class A, class B>
451inline void DispatchToFunction(Function function, const Tuple2<A, B>& arg) {
452 (*function)(arg.a, arg.b);
453}
454
455template<class Function, class A, class B, class C>
456inline void DispatchToFunction(Function function, const Tuple3<A, B, C>& arg) {
457 (*function)(arg.a, arg.b, arg.c);
458}
459
460template<class Function, class A, class B, class C, class D>
461inline void DispatchToFunction(Function function,
462 const Tuple4<A, B, C, D>& arg) {
463 (*function)(arg.a, arg.b, arg.c, arg.d);
464}
465
466template<class Function, class A, class B, class C, class D, class E>
467inline void DispatchToFunction(Function function,
468 const Tuple5<A, B, C, D, E>& arg) {
469 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e);
470}
471
ojan@google.com38355092008-10-10 06:58:05 +0900472template<class Function, class A, class B, class C, class D, class E, class F>
473inline void DispatchToFunction(Function function,
474 const Tuple6<A, B, C, D, E, F>& arg) {
475 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
476}
477
initial.commit3f4a7322008-07-27 06:49:38 +0900478// Dispatchers with 0 out param (as a Tuple0).
479
480template <class ObjT, class Method>
481inline void DispatchToMethod(ObjT* obj, Method method, const Tuple0& arg, Tuple0*) {
482 (obj->*method)();
483}
484
485template <class ObjT, class Method, class A>
486inline void DispatchToMethod(ObjT* obj, Method method, const A& arg, Tuple0*) {
487 (obj->*method)(arg);
488}
489
490template <class ObjT, class Method, class A>
491inline void DispatchToMethod(ObjT* obj, Method method, const Tuple1<A>& arg, Tuple0*) {
492 (obj->*method)(arg.a);
493}
494
495template<class ObjT, class Method, class A, class B>
496inline void DispatchToMethod(ObjT* obj, Method method, const Tuple2<A, B>& arg, Tuple0*) {
497 (obj->*method)(arg.a, arg.b);
498}
499
500template<class ObjT, class Method, class A, class B, class C>
501inline void DispatchToMethod(ObjT* obj, Method method,
502 const Tuple3<A, B, C>& arg, Tuple0*) {
503 (obj->*method)(arg.a, arg.b, arg.c);
504}
505
506template<class ObjT, class Method, class A, class B, class C, class D>
507inline void DispatchToMethod(ObjT* obj, Method method,
508 const Tuple4<A, B, C, D>& arg, Tuple0*) {
509 (obj->*method)(arg.a, arg.b, arg.c, arg.d);
510}
511
512template<class ObjT, class Method, class A, class B, class C, class D, class E>
513inline void DispatchToMethod(ObjT* obj, Method method,
514 const Tuple5<A, B, C, D, E>& arg, Tuple0*) {
515 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e);
516}
517
ojan@google.com38355092008-10-10 06:58:05 +0900518template<class ObjT, class Method, class A, class B, class C, class D, class E,
519 class F>
520inline void DispatchToMethod(ObjT* obj, Method method,
521 const Tuple6<A, B, C, D, E, F>& arg, Tuple0*) {
522 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
523}
524
initial.commit3f4a7322008-07-27 06:49:38 +0900525// Dispatchers with 1 out param.
526
527template<class ObjT, class Method,
528 class OutA>
529inline void DispatchToMethod(ObjT* obj, Method method,
530 const Tuple0& in,
531 Tuple1<OutA>* out) {
532 (obj->*method)(&out->a);
533}
534
535template<class ObjT, class Method, class InA,
536 class OutA>
537inline void DispatchToMethod(ObjT* obj, Method method,
538 const InA& in,
539 Tuple1<OutA>* out) {
540 (obj->*method)(in, &out->a);
541}
542
543template<class ObjT, class Method, class InA,
544 class OutA>
545inline void DispatchToMethod(ObjT* obj, Method method,
546 const Tuple1<InA>& in,
547 Tuple1<OutA>* out) {
548 (obj->*method)(in.a, &out->a);
549}
550
551template<class ObjT, class Method, class InA, class InB,
552 class OutA>
553inline void DispatchToMethod(ObjT* obj, Method method,
554 const Tuple2<InA, InB>& in,
555 Tuple1<OutA>* out) {
556 (obj->*method)(in.a, in.b, &out->a);
557}
558
559template<class ObjT, class Method, class InA, class InB, class InC,
560 class OutA>
561inline void DispatchToMethod(ObjT* obj, Method method,
562 const Tuple3<InA, InB, InC>& in,
563 Tuple1<OutA>* out) {
564 (obj->*method)(in.a, in.b, in.c, &out->a);
565}
566
567template<class ObjT, class Method, class InA, class InB, class InC, class InD,
568 class OutA>
569inline void DispatchToMethod(ObjT* obj, Method method,
570 const Tuple4<InA, InB, InC, InD>& in,
571 Tuple1<OutA>* out) {
572 (obj->*method)(in.a, in.b, in.c, in.d, &out->a);
573}
574
575template<class ObjT, class Method,
576 class InA, class InB, class InC, class InD, class InE,
577 class OutA>
578inline void DispatchToMethod(ObjT* obj, Method method,
579 const Tuple5<InA, InB, InC, InD, InE>& in,
580 Tuple1<OutA>* out) {
581 (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a);
582}
583
ojan@google.com38355092008-10-10 06:58:05 +0900584template<class ObjT, class Method,
585 class InA, class InB, class InC, class InD, class InE, class InF,
586 class OutA>
587inline void DispatchToMethod(ObjT* obj, Method method,
588 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
589 Tuple1<OutA>* out) {
590 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a);
591}
592
initial.commit3f4a7322008-07-27 06:49:38 +0900593// Dispatchers with 2 out params.
594
595template<class ObjT, class Method,
596 class OutA, class OutB>
597inline void DispatchToMethod(ObjT* obj, Method method,
598 const Tuple0& in,
599 Tuple2<OutA, OutB>* out) {
600 (obj->*method)(&out->a, &out->b);
601}
602
603template<class ObjT, class Method, class InA,
604 class OutA, class OutB>
605inline void DispatchToMethod(ObjT* obj, Method method,
606 const InA& in,
607 Tuple2<OutA, OutB>* out) {
608 (obj->*method)(in, &out->a, &out->b);
609}
610
611template<class ObjT, class Method, class InA,
612 class OutA, class OutB>
613inline void DispatchToMethod(ObjT* obj, Method method,
614 const Tuple1<InA>& in,
615 Tuple2<OutA, OutB>* out) {
616 (obj->*method)(in.a, &out->a, &out->b);
617}
618
619template<class ObjT, class Method, class InA, class InB,
620 class OutA, class OutB>
621inline void DispatchToMethod(ObjT* obj, Method method,
622 const Tuple2<InA, InB>& in,
623 Tuple2<OutA, OutB>* out) {
624 (obj->*method)(in.a, in.b, &out->a, &out->b);
625}
626
627template<class ObjT, class Method, class InA, class InB, class InC,
628 class OutA, class OutB>
629inline void DispatchToMethod(ObjT* obj, Method method,
630 const Tuple3<InA, InB, InC>& in,
631 Tuple2<OutA, OutB>* out) {
632 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b);
633}
634
635template<class ObjT, class Method, class InA, class InB, class InC, class InD,
636 class OutA, class OutB>
637inline void DispatchToMethod(ObjT* obj, Method method,
638 const Tuple4<InA, InB, InC, InD>& in,
639 Tuple2<OutA, OutB>* out) {
640 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b);
641}
642
643template<class ObjT, class Method,
644 class InA, class InB, class InC, class InD, class InE,
645 class OutA, class OutB>
646inline void DispatchToMethod(ObjT* obj, Method method,
647 const Tuple5<InA, InB, InC, InD, InE>& in,
648 Tuple2<OutA, OutB>* out) {
649 (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b);
650}
651
ojan@google.com38355092008-10-10 06:58:05 +0900652template<class ObjT, class Method,
653 class InA, class InB, class InC, class InD, class InE, class InF,
654 class OutA, class OutB>
655inline void DispatchToMethod(ObjT* obj, Method method,
656 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
657 Tuple2<OutA, OutB>* out) {
658 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b);
659}
660
initial.commit3f4a7322008-07-27 06:49:38 +0900661// Dispatchers with 3 out params.
662
663template<class ObjT, class Method,
664 class OutA, class OutB, class OutC>
665inline void DispatchToMethod(ObjT* obj, Method method,
666 const Tuple0& in,
667 Tuple3<OutA, OutB, OutC>* out) {
668 (obj->*method)(&out->a, &out->b, &out->c);
669}
670
671template<class ObjT, class Method, class InA,
672 class OutA, class OutB, class OutC>
673inline void DispatchToMethod(ObjT* obj, Method method,
674 const InA& in,
675 Tuple3<OutA, OutB, OutC>* out) {
676 (obj->*method)(in, &out->a, &out->b, &out->c);
677}
678
679template<class ObjT, class Method, class InA,
680 class OutA, class OutB, class OutC>
681inline void DispatchToMethod(ObjT* obj, Method method,
682 const Tuple1<InA>& in,
683 Tuple3<OutA, OutB, OutC>* out) {
684 (obj->*method)(in.a, &out->a, &out->b, &out->c);
685}
686
687template<class ObjT, class Method, class InA, class InB,
688 class OutA, class OutB, class OutC>
689inline void DispatchToMethod(ObjT* obj, Method method,
690 const Tuple2<InA, InB>& in,
691 Tuple3<OutA, OutB, OutC>* out) {
692 (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c);
693}
694
695template<class ObjT, class Method, class InA, class InB, class InC,
696 class OutA, class OutB, class OutC>
697inline void DispatchToMethod(ObjT* obj, Method method,
698 const Tuple3<InA, InB, InC>& in,
699 Tuple3<OutA, OutB, OutC>* out) {
700 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c);
701}
702
703template<class ObjT, class Method, class InA, class InB, class InC, class InD,
704 class OutA, class OutB, class OutC>
705inline void DispatchToMethod(ObjT* obj, Method method,
706 const Tuple4<InA, InB, InC, InD>& in,
707 Tuple3<OutA, OutB, OutC>* out) {
708 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c);
709}
710
711template<class ObjT, class Method,
712 class InA, class InB, class InC, class InD, class InE,
713 class OutA, class OutB, class OutC>
714inline void DispatchToMethod(ObjT* obj, Method method,
715 const Tuple5<InA, InB, InC, InD, InE>& in,
716 Tuple3<OutA, OutB, OutC>* out) {
717 (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b, &out->c);
718}
719
ojan@google.com38355092008-10-10 06:58:05 +0900720template<class ObjT, class Method,
721 class InA, class InB, class InC, class InD, class InE, class InF,
722 class OutA, class OutB, class OutC>
723inline void DispatchToMethod(ObjT* obj, Method method,
724 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
725 Tuple3<OutA, OutB, OutC>* out) {
726 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b, &out->c);
727}
728
initial.commit3f4a7322008-07-27 06:49:38 +0900729// Dispatchers with 4 out params.
730
731template<class ObjT, class Method,
732 class OutA, class OutB, class OutC, class OutD>
733inline void DispatchToMethod(ObjT* obj, Method method,
734 const Tuple0& in,
735 Tuple4<OutA, OutB, OutC, OutD>* out) {
736 (obj->*method)(&out->a, &out->b, &out->c, &out->d);
737}
738
739template<class ObjT, class Method, class InA,
740 class OutA, class OutB, class OutC, class OutD>
741inline void DispatchToMethod(ObjT* obj, Method method,
742 const InA& in,
743 Tuple4<OutA, OutB, OutC, OutD>* out) {
744 (obj->*method)(in, &out->a, &out->b, &out->c, &out->d);
745}
746
747template<class ObjT, class Method, class InA,
748 class OutA, class OutB, class OutC, class OutD>
749inline void DispatchToMethod(ObjT* obj, Method method,
750 const Tuple1<InA>& in,
751 Tuple4<OutA, OutB, OutC, OutD>* out) {
752 (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d);
753}
754
755template<class ObjT, class Method, class InA, class InB,
756 class OutA, class OutB, class OutC, class OutD>
757inline void DispatchToMethod(ObjT* obj, Method method,
758 const Tuple2<InA, InB>& in,
759 Tuple4<OutA, OutB, OutC, OutD>* out) {
760 (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d);
761}
762
763template<class ObjT, class Method, class InA, class InB, class InC,
764 class OutA, class OutB, class OutC, class OutD>
765inline void DispatchToMethod(ObjT* obj, Method method,
766 const Tuple3<InA, InB, InC>& in,
767 Tuple4<OutA, OutB, OutC, OutD>* out) {
768 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d);
769}
770
771template<class ObjT, class Method, class InA, class InB, class InC, class InD,
772 class OutA, class OutB, class OutC, class OutD>
773inline void DispatchToMethod(ObjT* obj, Method method,
774 const Tuple4<InA, InB, InC, InD>& in,
775 Tuple4<OutA, OutB, OutC, OutD>* out) {
776 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d);
777}
778
779template<class ObjT, class Method,
780 class InA, class InB, class InC, class InD, class InE,
781 class OutA, class OutB, class OutC, class OutD>
782inline void DispatchToMethod(ObjT* obj, Method method,
783 const Tuple5<InA, InB, InC, InD, InE>& in,
784 Tuple4<OutA, OutB, OutC, OutD>* out) {
785 (obj->*method)(in.a, in.b, in.c, in.d, in.e,
786 &out->a, &out->b, &out->c, &out->d);
787}
788
ojan@google.com38355092008-10-10 06:58:05 +0900789template<class ObjT, class Method,
790 class InA, class InB, class InC, class InD, class InE, class InF,
791 class OutA, class OutB, class OutC, class OutD>
792inline void DispatchToMethod(ObjT* obj, Method method,
793 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
794 Tuple4<OutA, OutB, OutC, OutD>* out) {
795 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f,
796 &out->a, &out->b, &out->c, &out->d);
797}
798
initial.commit3f4a7322008-07-27 06:49:38 +0900799// Dispatchers with 5 out params.
800
801template<class ObjT, class Method,
802 class OutA, class OutB, class OutC, class OutD, class OutE>
803inline void DispatchToMethod(ObjT* obj, Method method,
804 const Tuple0& in,
805 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
806 (obj->*method)(&out->a, &out->b, &out->c, &out->d, &out->e);
807}
808
809template<class ObjT, class Method, class InA,
810 class OutA, class OutB, class OutC, class OutD, class OutE>
811inline void DispatchToMethod(ObjT* obj, Method method,
812 const InA& in,
813 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
814 (obj->*method)(in, &out->a, &out->b, &out->c, &out->d, &out->e);
815}
816
817template<class ObjT, class Method, class InA,
818 class OutA, class OutB, class OutC, class OutD, class OutE>
819inline void DispatchToMethod(ObjT* obj, Method method,
820 const Tuple1<InA>& in,
821 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
822 (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d, &out->e);
823}
824
825template<class ObjT, class Method, class InA, class InB,
826 class OutA, class OutB, class OutC, class OutD, class OutE>
827inline void DispatchToMethod(ObjT* obj, Method method,
828 const Tuple2<InA, InB>& in,
829 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
830 (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d, &out->e);
831}
832
833template<class ObjT, class Method, class InA, class InB, class InC,
834 class OutA, class OutB, class OutC, class OutD, class OutE>
835inline void DispatchToMethod(ObjT* obj, Method method,
836 const Tuple3<InA, InB, InC>& in,
837 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
838 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d, &out->e);
839}
840
841template<class ObjT, class Method, class InA, class InB, class InC, class InD,
842 class OutA, class OutB, class OutC, class OutD, class OutE>
843inline void DispatchToMethod(ObjT* obj, Method method,
844 const Tuple4<InA, InB, InC, InD>& in,
845 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
846 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d,
847 &out->e);
848}
849
850template<class ObjT, class Method,
851 class InA, class InB, class InC, class InD, class InE,
852 class OutA, class OutB, class OutC, class OutD, class OutE>
853inline void DispatchToMethod(ObjT* obj, Method method,
854 const Tuple5<InA, InB, InC, InD, InE>& in,
855 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
856 (obj->*method)(in.a, in.b, in.c, in.d, in.e,
857 &out->a, &out->b, &out->c, &out->d, &out->e);
858}
859
ojan@google.com38355092008-10-10 06:58:05 +0900860template<class ObjT, class Method,
861 class InA, class InB, class InC, class InD, class InE, class InF,
862 class OutA, class OutB, class OutC, class OutD, class OutE>
863inline void DispatchToMethod(ObjT* obj, Method method,
864 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
865 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
866 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f,
867 &out->a, &out->b, &out->c, &out->d, &out->e);
868}
869
initial.commit3f4a7322008-07-27 06:49:38 +0900870#endif // BASE_TUPLE_H__
license.botf003cfe2008-08-24 09:55:55 +0900871