blob: bcd2ad4f2ef76b116d5fa2ba3eefa8e87946c93d [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__
thakis@chromium.org01d14522010-07-27 08:08:24 +090031#pragma once
initial.commit3f4a7322008-07-27 06:49:38 +090032
33// Traits ----------------------------------------------------------------------
34//
35// A simple traits class for tuple arguments.
36//
37// 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).
39// ParamType: what type to pass to functions (refs should not be constified).
40
41template <class P>
42struct TupleTraits {
43 typedef P ValueType;
44 typedef P& RefType;
45 typedef const P& ParamType;
46};
47
48template <class P>
49struct TupleTraits<P&> {
50 typedef P ValueType;
51 typedef P& RefType;
52 typedef P& ParamType;
53};
54
55// Tuple -----------------------------------------------------------------------
56//
57// This set of classes is useful for bundling 0 or more heterogeneous data types
58// into a single variable. The advantage of this is that it greatly simplifies
59// function objects that need to take an arbitrary number of parameters; see
60// RunnableMethod and IPC::MessageWithTuple.
61//
deanm@google.comff4b7292008-08-21 19:58:08 +090062// Tuple0 is supplied to act as a 'void' type. It can be used, for example,
63// when dispatching to a function that accepts no arguments (see the
64// Dispatchers below).
initial.commit3f4a7322008-07-27 06:49:38 +090065// Tuple1<A> is rarely useful. One such use is when A is non-const ref that you
66// want filled by the dispatchee, and the tuple is merely a container for that
67// output (a "tier"). See MakeRefTuple and its usages.
68
69struct Tuple0 {
70 typedef Tuple0 ValueTuple;
71 typedef Tuple0 RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +090072 typedef Tuple0 ParamTuple;
initial.commit3f4a7322008-07-27 06:49:38 +090073};
74
75template <class A>
76struct Tuple1 {
77 public:
78 typedef A TypeA;
79 typedef Tuple1<typename TupleTraits<A>::ValueType> ValueTuple;
80 typedef Tuple1<typename TupleTraits<A>::RefType> RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +090081 typedef Tuple1<typename TupleTraits<A>::ParamType> ParamTuple;
initial.commit3f4a7322008-07-27 06:49:38 +090082
83 Tuple1() {}
84 explicit Tuple1(typename TupleTraits<A>::ParamType a) : a(a) {}
85
86 A a;
87};
88
89template <class A, class B>
90struct Tuple2 {
91 public:
92 typedef A TypeA;
93 typedef B TypeB;
94 typedef Tuple2<typename TupleTraits<A>::ValueType,
95 typename TupleTraits<B>::ValueType> ValueTuple;
96 typedef Tuple2<typename TupleTraits<A>::RefType,
97 typename TupleTraits<B>::RefType> RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +090098 typedef Tuple2<typename TupleTraits<A>::ParamType,
99 typename TupleTraits<B>::ParamType> ParamTuple;
initial.commit3f4a7322008-07-27 06:49:38 +0900100
101 Tuple2() {}
102 Tuple2(typename TupleTraits<A>::ParamType a,
103 typename TupleTraits<B>::ParamType b)
104 : a(a), b(b) {
105 }
106
107 A a;
108 B b;
109};
110
111template <class A, class B, class C>
112struct Tuple3 {
113 public:
114 typedef A TypeA;
115 typedef B TypeB;
116 typedef C TypeC;
117 typedef Tuple3<typename TupleTraits<A>::ValueType,
118 typename TupleTraits<B>::ValueType,
119 typename TupleTraits<C>::ValueType> ValueTuple;
120 typedef Tuple3<typename TupleTraits<A>::RefType,
121 typename TupleTraits<B>::RefType,
122 typename TupleTraits<C>::RefType> RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +0900123 typedef Tuple3<typename TupleTraits<A>::ParamType,
124 typename TupleTraits<B>::ParamType,
125 typename TupleTraits<C>::ParamType> ParamTuple;
initial.commit3f4a7322008-07-27 06:49:38 +0900126
127 Tuple3() {}
128 Tuple3(typename TupleTraits<A>::ParamType a,
129 typename TupleTraits<B>::ParamType b,
130 typename TupleTraits<C>::ParamType c)
131 : a(a), b(b), c(c){
132 }
133
134 A a;
135 B b;
136 C c;
137};
138
139template <class A, class B, class C, class D>
140struct Tuple4 {
141 public:
142 typedef A TypeA;
143 typedef B TypeB;
144 typedef C TypeC;
145 typedef D TypeD;
146 typedef Tuple4<typename TupleTraits<A>::ValueType,
147 typename TupleTraits<B>::ValueType,
148 typename TupleTraits<C>::ValueType,
149 typename TupleTraits<D>::ValueType> ValueTuple;
150 typedef Tuple4<typename TupleTraits<A>::RefType,
151 typename TupleTraits<B>::RefType,
152 typename TupleTraits<C>::RefType,
153 typename TupleTraits<D>::RefType> RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +0900154 typedef Tuple4<typename TupleTraits<A>::ParamType,
155 typename TupleTraits<B>::ParamType,
156 typename TupleTraits<C>::ParamType,
157 typename TupleTraits<D>::ParamType> ParamTuple;
initial.commit3f4a7322008-07-27 06:49:38 +0900158
159 Tuple4() {}
160 Tuple4(typename TupleTraits<A>::ParamType a,
161 typename TupleTraits<B>::ParamType b,
162 typename TupleTraits<C>::ParamType c,
163 typename TupleTraits<D>::ParamType d)
164 : a(a), b(b), c(c), d(d) {
165 }
166
167 A a;
168 B b;
169 C c;
170 D d;
171};
172
173template <class A, class B, class C, class D, class E>
174struct Tuple5 {
erg@google.combf6ce9f2010-01-27 08:08:02 +0900175 public:
initial.commit3f4a7322008-07-27 06:49:38 +0900176 typedef A TypeA;
177 typedef B TypeB;
178 typedef C TypeC;
179 typedef D TypeD;
180 typedef E TypeE;
181 typedef Tuple5<typename TupleTraits<A>::ValueType,
182 typename TupleTraits<B>::ValueType,
183 typename TupleTraits<C>::ValueType,
184 typename TupleTraits<D>::ValueType,
185 typename TupleTraits<E>::ValueType> ValueTuple;
186 typedef Tuple5<typename TupleTraits<A>::RefType,
187 typename TupleTraits<B>::RefType,
188 typename TupleTraits<C>::RefType,
189 typename TupleTraits<D>::RefType,
190 typename TupleTraits<E>::RefType> RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +0900191 typedef Tuple5<typename TupleTraits<A>::ParamType,
192 typename TupleTraits<B>::ParamType,
193 typename TupleTraits<C>::ParamType,
194 typename TupleTraits<D>::ParamType,
195 typename TupleTraits<E>::ParamType> ParamTuple;
initial.commit3f4a7322008-07-27 06:49:38 +0900196
197 Tuple5() {}
198 Tuple5(typename TupleTraits<A>::ParamType a,
199 typename TupleTraits<B>::ParamType b,
200 typename TupleTraits<C>::ParamType c,
201 typename TupleTraits<D>::ParamType d,
202 typename TupleTraits<E>::ParamType e)
203 : a(a), b(b), c(c), d(d), e(e) {
204 }
205
206 A a;
207 B b;
208 C c;
209 D d;
210 E e;
211};
212
ojan@google.com38355092008-10-10 06:58:05 +0900213template <class A, class B, class C, class D, class E, class F>
214struct Tuple6 {
erg@google.combf6ce9f2010-01-27 08:08:02 +0900215 public:
ojan@google.com38355092008-10-10 06:58:05 +0900216 typedef A TypeA;
217 typedef B TypeB;
218 typedef C TypeC;
219 typedef D TypeD;
220 typedef E TypeE;
221 typedef F TypeF;
222 typedef Tuple6<typename TupleTraits<A>::ValueType,
223 typename TupleTraits<B>::ValueType,
224 typename TupleTraits<C>::ValueType,
225 typename TupleTraits<D>::ValueType,
226 typename TupleTraits<E>::ValueType,
227 typename TupleTraits<F>::ValueType> ValueTuple;
228 typedef Tuple6<typename TupleTraits<A>::RefType,
229 typename TupleTraits<B>::RefType,
230 typename TupleTraits<C>::RefType,
231 typename TupleTraits<D>::RefType,
232 typename TupleTraits<E>::RefType,
233 typename TupleTraits<F>::RefType> RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +0900234 typedef Tuple6<typename TupleTraits<A>::ParamType,
235 typename TupleTraits<B>::ParamType,
236 typename TupleTraits<C>::ParamType,
237 typename TupleTraits<D>::ParamType,
238 typename TupleTraits<E>::ParamType,
239 typename TupleTraits<F>::ParamType> ParamTuple;
ojan@google.com38355092008-10-10 06:58:05 +0900240
241 Tuple6() {}
242 Tuple6(typename TupleTraits<A>::ParamType a,
243 typename TupleTraits<B>::ParamType b,
244 typename TupleTraits<C>::ParamType c,
245 typename TupleTraits<D>::ParamType d,
246 typename TupleTraits<E>::ParamType e,
247 typename TupleTraits<F>::ParamType f)
248 : a(a), b(b), c(c), d(d), e(e), f(f) {
249 }
250
251 A a;
252 B b;
253 C c;
254 D d;
255 E e;
256 F f;
257};
258
sky@google.com67c35752008-11-13 07:10:20 +0900259template <class A, class B, class C, class D, class E, class F, class G>
260struct Tuple7 {
erg@google.combf6ce9f2010-01-27 08:08:02 +0900261 public:
sky@google.com67c35752008-11-13 07:10:20 +0900262 typedef A TypeA;
263 typedef B TypeB;
264 typedef C TypeC;
265 typedef D TypeD;
266 typedef E TypeE;
267 typedef F TypeF;
268 typedef G TypeG;
269 typedef Tuple7<typename TupleTraits<A>::ValueType,
270 typename TupleTraits<B>::ValueType,
271 typename TupleTraits<C>::ValueType,
272 typename TupleTraits<D>::ValueType,
273 typename TupleTraits<E>::ValueType,
274 typename TupleTraits<F>::ValueType,
275 typename TupleTraits<G>::ValueType> ValueTuple;
276 typedef Tuple7<typename TupleTraits<A>::RefType,
277 typename TupleTraits<B>::RefType,
278 typename TupleTraits<C>::RefType,
279 typename TupleTraits<D>::RefType,
280 typename TupleTraits<E>::RefType,
281 typename TupleTraits<F>::RefType,
282 typename TupleTraits<G>::RefType> RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +0900283 typedef Tuple7<typename TupleTraits<A>::ParamType,
284 typename TupleTraits<B>::ParamType,
285 typename TupleTraits<C>::ParamType,
286 typename TupleTraits<D>::ParamType,
287 typename TupleTraits<E>::ParamType,
288 typename TupleTraits<F>::ParamType,
289 typename TupleTraits<G>::ParamType> ParamTuple;
sky@google.com67c35752008-11-13 07:10:20 +0900290
291 Tuple7() {}
292 Tuple7(typename TupleTraits<A>::ParamType a,
293 typename TupleTraits<B>::ParamType b,
294 typename TupleTraits<C>::ParamType c,
295 typename TupleTraits<D>::ParamType d,
296 typename TupleTraits<E>::ParamType e,
297 typename TupleTraits<F>::ParamType f,
298 typename TupleTraits<G>::ParamType g)
299 : a(a), b(b), c(c), d(d), e(e), f(f), g(g) {
300 }
301
302 A a;
303 B b;
304 C c;
305 D d;
306 E e;
307 F f;
308 G g;
309};
310
phajdan.jr@chromium.org5a468fc2010-07-21 01:56:26 +0900311template <class A, class B, class C, class D, class E, class F, class G,
312 class H>
313struct Tuple8 {
314 public:
315 typedef A TypeA;
316 typedef B TypeB;
317 typedef C TypeC;
318 typedef D TypeD;
319 typedef E TypeE;
320 typedef F TypeF;
321 typedef G TypeG;
322 typedef H TypeH;
323 typedef Tuple8<typename TupleTraits<A>::ValueType,
324 typename TupleTraits<B>::ValueType,
325 typename TupleTraits<C>::ValueType,
326 typename TupleTraits<D>::ValueType,
327 typename TupleTraits<E>::ValueType,
328 typename TupleTraits<F>::ValueType,
329 typename TupleTraits<G>::ValueType,
330 typename TupleTraits<H>::ValueType> ValueTuple;
331 typedef Tuple8<typename TupleTraits<A>::RefType,
332 typename TupleTraits<B>::RefType,
333 typename TupleTraits<C>::RefType,
334 typename TupleTraits<D>::RefType,
335 typename TupleTraits<E>::RefType,
336 typename TupleTraits<F>::RefType,
337 typename TupleTraits<G>::RefType,
338 typename TupleTraits<H>::RefType> RefTuple;
339 typedef Tuple8<typename TupleTraits<A>::ParamType,
340 typename TupleTraits<B>::ParamType,
341 typename TupleTraits<C>::ParamType,
342 typename TupleTraits<D>::ParamType,
343 typename TupleTraits<E>::ParamType,
344 typename TupleTraits<F>::ParamType,
345 typename TupleTraits<G>::ParamType,
346 typename TupleTraits<H>::ParamType> ParamTuple;
347
348 Tuple8() {}
349 Tuple8(typename TupleTraits<A>::ParamType a,
350 typename TupleTraits<B>::ParamType b,
351 typename TupleTraits<C>::ParamType c,
352 typename TupleTraits<D>::ParamType d,
353 typename TupleTraits<E>::ParamType e,
354 typename TupleTraits<F>::ParamType f,
355 typename TupleTraits<G>::ParamType g,
356 typename TupleTraits<H>::ParamType h)
357 : a(a), b(b), c(c), d(d), e(e), f(f), g(g), h(h) {
358 }
359
360 A a;
361 B b;
362 C c;
363 D d;
364 E e;
365 F f;
366 G g;
367 H h;
368};
369
initial.commit3f4a7322008-07-27 06:49:38 +0900370// Tuple creators -------------------------------------------------------------
371//
372// Helper functions for constructing tuples while inferring the template
373// argument types.
374
375inline Tuple0 MakeTuple() {
376 return Tuple0();
377}
378
379template <class A>
380inline Tuple1<A> MakeTuple(const A& a) {
381 return Tuple1<A>(a);
382}
383
384template <class A, class B>
385inline Tuple2<A, B> MakeTuple(const A& a, const B& b) {
386 return Tuple2<A, B>(a, b);
387}
388
389template <class A, class B, class C>
390inline Tuple3<A, B, C> MakeTuple(const A& a, const B& b, const C& c) {
391 return Tuple3<A, B, C>(a, b, c);
392}
393
394template <class A, class B, class C, class D>
395inline Tuple4<A, B, C, D> MakeTuple(const A& a, const B& b, const C& c,
396 const D& d) {
397 return Tuple4<A, B, C, D>(a, b, c, d);
398}
399
400template <class A, class B, class C, class D, class E>
401inline Tuple5<A, B, C, D, E> MakeTuple(const A& a, const B& b, const C& c,
402 const D& d, const E& e) {
403 return Tuple5<A, B, C, D, E>(a, b, c, d, e);
404}
405
ojan@google.com38355092008-10-10 06:58:05 +0900406template <class A, class B, class C, class D, class E, class F>
407inline Tuple6<A, B, C, D, E, F> MakeTuple(const A& a, const B& b, const C& c,
408 const D& d, const E& e, const F& f) {
409 return Tuple6<A, B, C, D, E, F>(a, b, c, d, e, f);
410}
411
sky@google.com67c35752008-11-13 07:10:20 +0900412template <class A, class B, class C, class D, class E, class F, class G>
413inline Tuple7<A, B, C, D, E, F, G> MakeTuple(const A& a, const B& b, const C& c,
414 const D& d, const E& e, const F& f,
415 const G& g) {
416 return Tuple7<A, B, C, D, E, F, G>(a, b, c, d, e, f, g);
417}
418
phajdan.jr@chromium.org5a468fc2010-07-21 01:56:26 +0900419template <class A, class B, class C, class D, class E, class F, class G,
420 class H>
421inline Tuple8<A, B, C, D, E, F, G, H> MakeTuple(const A& a, const B& b,
422 const C& c, const D& d,
423 const E& e, const F& f,
424 const G& g, const H& h) {
425 return Tuple8<A, B, C, D, E, F, G, H>(a, b, c, d, e, f, g, h);
426}
427
initial.commit3f4a7322008-07-27 06:49:38 +0900428// The following set of helpers make what Boost refers to as "Tiers" - a tuple
429// of references.
430
431template <class A>
432inline Tuple1<A&> MakeRefTuple(A& a) {
433 return Tuple1<A&>(a);
434}
435
436template <class A, class B>
437inline Tuple2<A&, B&> MakeRefTuple(A& a, B& b) {
438 return Tuple2<A&, B&>(a, b);
439}
440
441template <class A, class B, class C>
442inline Tuple3<A&, B&, C&> MakeRefTuple(A& a, B& b, C& c) {
443 return Tuple3<A&, B&, C&>(a, b, c);
444}
445
446template <class A, class B, class C, class D>
447inline Tuple4<A&, B&, C&, D&> MakeRefTuple(A& a, B& b, C& c, D& d) {
448 return Tuple4<A&, B&, C&, D&>(a, b, c, d);
449}
450
451template <class A, class B, class C, class D, class E>
452inline Tuple5<A&, B&, C&, D&, E&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e) {
453 return Tuple5<A&, B&, C&, D&, E&>(a, b, c, d, e);
454}
455
ojan@google.com38355092008-10-10 06:58:05 +0900456template <class A, class B, class C, class D, class E, class F>
457inline Tuple6<A&, B&, C&, D&, E&, F&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e,
458 F& f) {
459 return Tuple6<A&, B&, C&, D&, E&, F&>(a, b, c, d, e, f);
460}
461
sky@google.com67c35752008-11-13 07:10:20 +0900462template <class A, class B, class C, class D, class E, class F, class G>
463inline Tuple7<A&, B&, C&, D&, E&, F&, G&> MakeRefTuple(A& a, B& b, C& c, D& d,
464 E& e, F& f, G& g) {
465 return Tuple7<A&, B&, C&, D&, E&, F&, G&>(a, b, c, d, e, f, g);
466}
467
phajdan.jr@chromium.org5a468fc2010-07-21 01:56:26 +0900468template <class A, class B, class C, class D, class E, class F, class G,
469 class H>
470inline Tuple8<A&, B&, C&, D&, E&, F&, G&, H&> MakeRefTuple(A& a, B& b, C& c,
471 D& d, E& e, F& f,
472 G& g, H& h) {
473 return Tuple8<A&, B&, C&, D&, E&, F&, G&, H&>(a, b, c, d, e, f, g, h);
474}
475
initial.commit3f4a7322008-07-27 06:49:38 +0900476// Dispatchers ----------------------------------------------------------------
477//
478// Helper functions that call the given method on an object, with the unpacked
479// tuple arguments. Notice that they all have the same number of arguments,
480// so you need only write:
481// DispatchToMethod(object, &Object::method, args);
482// This is very useful for templated dispatchers, since they don't need to know
483// what type |args| is.
484
485// Non-Static Dispatchers with no out params.
486
487template <class ObjT, class Method>
488inline void DispatchToMethod(ObjT* obj, Method method, const Tuple0& arg) {
489 (obj->*method)();
490}
491
492template <class ObjT, class Method, class A>
493inline void DispatchToMethod(ObjT* obj, Method method, const A& arg) {
494 (obj->*method)(arg);
495}
496
497template <class ObjT, class Method, class A>
498inline void DispatchToMethod(ObjT* obj, Method method, const Tuple1<A>& arg) {
499 (obj->*method)(arg.a);
500}
501
502template<class ObjT, class Method, class A, class B>
maruel@chromium.org8fe7adc2009-03-04 00:01:12 +0900503inline void DispatchToMethod(ObjT* obj,
504 Method method,
505 const Tuple2<A, B>& arg) {
initial.commit3f4a7322008-07-27 06:49:38 +0900506 (obj->*method)(arg.a, arg.b);
507}
508
509template<class ObjT, class Method, class A, class B, class C>
510inline void DispatchToMethod(ObjT* obj, Method method,
511 const Tuple3<A, B, C>& arg) {
512 (obj->*method)(arg.a, arg.b, arg.c);
513}
514
515template<class ObjT, class Method, class A, class B, class C, class D>
516inline void DispatchToMethod(ObjT* obj, Method method,
517 const Tuple4<A, B, C, D>& arg) {
518 (obj->*method)(arg.a, arg.b, arg.c, arg.d);
519}
520
521template<class ObjT, class Method, class A, class B, class C, class D, class E>
522inline void DispatchToMethod(ObjT* obj, Method method,
523 const Tuple5<A, B, C, D, E>& arg) {
524 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e);
525}
526
ojan@google.com38355092008-10-10 06:58:05 +0900527template<class ObjT, class Method, class A, class B, class C, class D, class E,
528 class F>
529inline void DispatchToMethod(ObjT* obj, Method method,
530 const Tuple6<A, B, C, D, E, F>& arg) {
531 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
532}
533
sky@google.com67c35752008-11-13 07:10:20 +0900534template<class ObjT, class Method, class A, class B, class C, class D, class E,
535 class F, class G>
536inline void DispatchToMethod(ObjT* obj, Method method,
537 const Tuple7<A, B, C, D, E, F, G>& arg) {
538 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g);
539}
540
initial.commit3f4a7322008-07-27 06:49:38 +0900541// Static Dispatchers with no out params.
542
543template <class Function>
544inline void DispatchToFunction(Function function, const Tuple0& arg) {
545 (*function)();
546}
547
548template <class Function, class A>
549inline void DispatchToFunction(Function function, const A& arg) {
550 (*function)(arg);
551}
552
553template <class Function, class A>
554inline void DispatchToFunction(Function function, const Tuple1<A>& arg) {
555 (*function)(arg.a);
556}
557
558template<class Function, class A, class B>
559inline void DispatchToFunction(Function function, const Tuple2<A, B>& arg) {
560 (*function)(arg.a, arg.b);
561}
562
563template<class Function, class A, class B, class C>
564inline void DispatchToFunction(Function function, const Tuple3<A, B, C>& arg) {
565 (*function)(arg.a, arg.b, arg.c);
566}
567
568template<class Function, class A, class B, class C, class D>
569inline void DispatchToFunction(Function function,
570 const Tuple4<A, B, C, D>& arg) {
571 (*function)(arg.a, arg.b, arg.c, arg.d);
572}
573
574template<class Function, class A, class B, class C, class D, class E>
575inline void DispatchToFunction(Function function,
576 const Tuple5<A, B, C, D, E>& arg) {
577 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e);
578}
579
ojan@google.com38355092008-10-10 06:58:05 +0900580template<class Function, class A, class B, class C, class D, class E, class F>
581inline void DispatchToFunction(Function function,
582 const Tuple6<A, B, C, D, E, F>& arg) {
583 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
584}
585
phajdan.jr@chromium.org5a468fc2010-07-21 01:56:26 +0900586template<class Function, class A, class B, class C, class D, class E, class F,
587 class G>
588inline void DispatchToFunction(Function function,
589 const Tuple7<A, B, C, D, E, F, G>& arg) {
590 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g);
591}
592
593template<class Function, class A, class B, class C, class D, class E, class F,
594 class G, class H>
595inline void DispatchToFunction(Function function,
596 const Tuple8<A, B, C, D, E, F, G, H>& arg) {
597 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g, arg.h);
598}
599
initial.commit3f4a7322008-07-27 06:49:38 +0900600// Dispatchers with 0 out param (as a Tuple0).
601
602template <class ObjT, class Method>
maruel@chromium.org8fe7adc2009-03-04 00:01:12 +0900603inline void DispatchToMethod(ObjT* obj,
604 Method method,
605 const Tuple0& arg, Tuple0*) {
initial.commit3f4a7322008-07-27 06:49:38 +0900606 (obj->*method)();
607}
608
609template <class ObjT, class Method, class A>
610inline void DispatchToMethod(ObjT* obj, Method method, const A& arg, Tuple0*) {
611 (obj->*method)(arg);
612}
613
614template <class ObjT, class Method, class A>
maruel@chromium.org8fe7adc2009-03-04 00:01:12 +0900615inline void DispatchToMethod(ObjT* obj,
616 Method method,
617 const Tuple1<A>& arg, Tuple0*) {
initial.commit3f4a7322008-07-27 06:49:38 +0900618 (obj->*method)(arg.a);
619}
620
621template<class ObjT, class Method, class A, class B>
maruel@chromium.org8fe7adc2009-03-04 00:01:12 +0900622inline void DispatchToMethod(ObjT* obj,
623 Method method,
624 const Tuple2<A, B>& arg, Tuple0*) {
initial.commit3f4a7322008-07-27 06:49:38 +0900625 (obj->*method)(arg.a, arg.b);
626}
627
628template<class ObjT, class Method, class A, class B, class C>
629inline void DispatchToMethod(ObjT* obj, Method method,
630 const Tuple3<A, B, C>& arg, Tuple0*) {
631 (obj->*method)(arg.a, arg.b, arg.c);
632}
633
634template<class ObjT, class Method, class A, class B, class C, class D>
635inline void DispatchToMethod(ObjT* obj, Method method,
636 const Tuple4<A, B, C, D>& arg, Tuple0*) {
637 (obj->*method)(arg.a, arg.b, arg.c, arg.d);
638}
639
640template<class ObjT, class Method, class A, class B, class C, class D, class E>
641inline void DispatchToMethod(ObjT* obj, Method method,
642 const Tuple5<A, B, C, D, E>& arg, Tuple0*) {
643 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e);
644}
645
ojan@google.com38355092008-10-10 06:58:05 +0900646template<class ObjT, class Method, class A, class B, class C, class D, class E,
647 class F>
648inline void DispatchToMethod(ObjT* obj, Method method,
649 const Tuple6<A, B, C, D, E, F>& arg, Tuple0*) {
650 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
651}
652
initial.commit3f4a7322008-07-27 06:49:38 +0900653// Dispatchers with 1 out param.
654
655template<class ObjT, class Method,
656 class OutA>
657inline void DispatchToMethod(ObjT* obj, Method method,
658 const Tuple0& in,
659 Tuple1<OutA>* out) {
660 (obj->*method)(&out->a);
661}
662
663template<class ObjT, class Method, class InA,
664 class OutA>
665inline void DispatchToMethod(ObjT* obj, Method method,
666 const InA& in,
667 Tuple1<OutA>* out) {
668 (obj->*method)(in, &out->a);
669}
670
671template<class ObjT, class Method, class InA,
672 class OutA>
673inline void DispatchToMethod(ObjT* obj, Method method,
674 const Tuple1<InA>& in,
675 Tuple1<OutA>* out) {
676 (obj->*method)(in.a, &out->a);
677}
678
679template<class ObjT, class Method, class InA, class InB,
680 class OutA>
681inline void DispatchToMethod(ObjT* obj, Method method,
682 const Tuple2<InA, InB>& in,
683 Tuple1<OutA>* out) {
684 (obj->*method)(in.a, in.b, &out->a);
685}
686
687template<class ObjT, class Method, class InA, class InB, class InC,
688 class OutA>
689inline void DispatchToMethod(ObjT* obj, Method method,
690 const Tuple3<InA, InB, InC>& in,
691 Tuple1<OutA>* out) {
692 (obj->*method)(in.a, in.b, in.c, &out->a);
693}
694
695template<class ObjT, class Method, class InA, class InB, class InC, class InD,
696 class OutA>
697inline void DispatchToMethod(ObjT* obj, Method method,
698 const Tuple4<InA, InB, InC, InD>& in,
699 Tuple1<OutA>* out) {
700 (obj->*method)(in.a, in.b, in.c, in.d, &out->a);
701}
702
erg@google.combf6ce9f2010-01-27 08:08:02 +0900703template<class ObjT, class Method, class InA, class InB, class InC, class InD,
704 class InE, class OutA>
initial.commit3f4a7322008-07-27 06:49:38 +0900705inline void DispatchToMethod(ObjT* obj, Method method,
706 const Tuple5<InA, InB, InC, InD, InE>& in,
707 Tuple1<OutA>* out) {
708 (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a);
709}
710
ojan@google.com38355092008-10-10 06:58:05 +0900711template<class ObjT, class Method,
712 class InA, class InB, class InC, class InD, class InE, class InF,
713 class OutA>
714inline void DispatchToMethod(ObjT* obj, Method method,
715 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
716 Tuple1<OutA>* out) {
717 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a);
718}
719
initial.commit3f4a7322008-07-27 06:49:38 +0900720// Dispatchers with 2 out params.
721
722template<class ObjT, class Method,
723 class OutA, class OutB>
724inline void DispatchToMethod(ObjT* obj, Method method,
725 const Tuple0& in,
726 Tuple2<OutA, OutB>* out) {
727 (obj->*method)(&out->a, &out->b);
728}
729
730template<class ObjT, class Method, class InA,
731 class OutA, class OutB>
732inline void DispatchToMethod(ObjT* obj, Method method,
733 const InA& in,
734 Tuple2<OutA, OutB>* out) {
735 (obj->*method)(in, &out->a, &out->b);
736}
737
738template<class ObjT, class Method, class InA,
739 class OutA, class OutB>
740inline void DispatchToMethod(ObjT* obj, Method method,
741 const Tuple1<InA>& in,
742 Tuple2<OutA, OutB>* out) {
743 (obj->*method)(in.a, &out->a, &out->b);
744}
745
746template<class ObjT, class Method, class InA, class InB,
747 class OutA, class OutB>
748inline void DispatchToMethod(ObjT* obj, Method method,
749 const Tuple2<InA, InB>& in,
750 Tuple2<OutA, OutB>* out) {
751 (obj->*method)(in.a, in.b, &out->a, &out->b);
752}
753
754template<class ObjT, class Method, class InA, class InB, class InC,
755 class OutA, class OutB>
756inline void DispatchToMethod(ObjT* obj, Method method,
757 const Tuple3<InA, InB, InC>& in,
758 Tuple2<OutA, OutB>* out) {
759 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b);
760}
761
762template<class ObjT, class Method, class InA, class InB, class InC, class InD,
763 class OutA, class OutB>
764inline void DispatchToMethod(ObjT* obj, Method method,
765 const Tuple4<InA, InB, InC, InD>& in,
766 Tuple2<OutA, OutB>* out) {
767 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b);
768}
769
770template<class ObjT, class Method,
771 class InA, class InB, class InC, class InD, class InE,
772 class OutA, class OutB>
773inline void DispatchToMethod(ObjT* obj, Method method,
774 const Tuple5<InA, InB, InC, InD, InE>& in,
775 Tuple2<OutA, OutB>* out) {
776 (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b);
777}
778
ojan@google.com38355092008-10-10 06:58:05 +0900779template<class ObjT, class Method,
780 class InA, class InB, class InC, class InD, class InE, class InF,
781 class OutA, class OutB>
782inline void DispatchToMethod(ObjT* obj, Method method,
783 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
784 Tuple2<OutA, OutB>* out) {
785 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b);
786}
787
initial.commit3f4a7322008-07-27 06:49:38 +0900788// Dispatchers with 3 out params.
789
790template<class ObjT, class Method,
791 class OutA, class OutB, class OutC>
792inline void DispatchToMethod(ObjT* obj, Method method,
793 const Tuple0& in,
794 Tuple3<OutA, OutB, OutC>* out) {
795 (obj->*method)(&out->a, &out->b, &out->c);
796}
797
798template<class ObjT, class Method, class InA,
799 class OutA, class OutB, class OutC>
800inline void DispatchToMethod(ObjT* obj, Method method,
801 const InA& in,
802 Tuple3<OutA, OutB, OutC>* out) {
803 (obj->*method)(in, &out->a, &out->b, &out->c);
804}
805
806template<class ObjT, class Method, class InA,
807 class OutA, class OutB, class OutC>
808inline void DispatchToMethod(ObjT* obj, Method method,
809 const Tuple1<InA>& in,
810 Tuple3<OutA, OutB, OutC>* out) {
811 (obj->*method)(in.a, &out->a, &out->b, &out->c);
812}
813
814template<class ObjT, class Method, class InA, class InB,
815 class OutA, class OutB, class OutC>
816inline void DispatchToMethod(ObjT* obj, Method method,
817 const Tuple2<InA, InB>& in,
818 Tuple3<OutA, OutB, OutC>* out) {
819 (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c);
820}
821
822template<class ObjT, class Method, class InA, class InB, class InC,
823 class OutA, class OutB, class OutC>
824inline void DispatchToMethod(ObjT* obj, Method method,
825 const Tuple3<InA, InB, InC>& in,
826 Tuple3<OutA, OutB, OutC>* out) {
827 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c);
828}
829
830template<class ObjT, class Method, class InA, class InB, class InC, class InD,
831 class OutA, class OutB, class OutC>
832inline void DispatchToMethod(ObjT* obj, Method method,
833 const Tuple4<InA, InB, InC, InD>& in,
834 Tuple3<OutA, OutB, OutC>* out) {
835 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c);
836}
837
838template<class ObjT, class Method,
839 class InA, class InB, class InC, class InD, class InE,
840 class OutA, class OutB, class OutC>
841inline void DispatchToMethod(ObjT* obj, Method method,
842 const Tuple5<InA, InB, InC, InD, InE>& in,
843 Tuple3<OutA, OutB, OutC>* out) {
844 (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b, &out->c);
845}
846
ojan@google.com38355092008-10-10 06:58:05 +0900847template<class ObjT, class Method,
848 class InA, class InB, class InC, class InD, class InE, class InF,
849 class OutA, class OutB, class OutC>
850inline void DispatchToMethod(ObjT* obj, Method method,
851 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
852 Tuple3<OutA, OutB, OutC>* out) {
853 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b, &out->c);
854}
855
initial.commit3f4a7322008-07-27 06:49:38 +0900856// Dispatchers with 4 out params.
857
858template<class ObjT, class Method,
859 class OutA, class OutB, class OutC, class OutD>
860inline void DispatchToMethod(ObjT* obj, Method method,
861 const Tuple0& in,
862 Tuple4<OutA, OutB, OutC, OutD>* out) {
863 (obj->*method)(&out->a, &out->b, &out->c, &out->d);
864}
865
866template<class ObjT, class Method, class InA,
867 class OutA, class OutB, class OutC, class OutD>
868inline void DispatchToMethod(ObjT* obj, Method method,
869 const InA& in,
870 Tuple4<OutA, OutB, OutC, OutD>* out) {
871 (obj->*method)(in, &out->a, &out->b, &out->c, &out->d);
872}
873
874template<class ObjT, class Method, class InA,
875 class OutA, class OutB, class OutC, class OutD>
876inline void DispatchToMethod(ObjT* obj, Method method,
877 const Tuple1<InA>& in,
878 Tuple4<OutA, OutB, OutC, OutD>* out) {
879 (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d);
880}
881
882template<class ObjT, class Method, class InA, class InB,
883 class OutA, class OutB, class OutC, class OutD>
884inline void DispatchToMethod(ObjT* obj, Method method,
885 const Tuple2<InA, InB>& in,
886 Tuple4<OutA, OutB, OutC, OutD>* out) {
887 (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d);
888}
889
890template<class ObjT, class Method, class InA, class InB, class InC,
891 class OutA, class OutB, class OutC, class OutD>
892inline void DispatchToMethod(ObjT* obj, Method method,
893 const Tuple3<InA, InB, InC>& in,
894 Tuple4<OutA, OutB, OutC, OutD>* out) {
895 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d);
896}
897
898template<class ObjT, class Method, class InA, class InB, class InC, class InD,
899 class OutA, class OutB, class OutC, class OutD>
900inline void DispatchToMethod(ObjT* obj, Method method,
901 const Tuple4<InA, InB, InC, InD>& in,
902 Tuple4<OutA, OutB, OutC, OutD>* out) {
903 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d);
904}
905
906template<class ObjT, class Method,
907 class InA, class InB, class InC, class InD, class InE,
908 class OutA, class OutB, class OutC, class OutD>
909inline void DispatchToMethod(ObjT* obj, Method method,
910 const Tuple5<InA, InB, InC, InD, InE>& in,
911 Tuple4<OutA, OutB, OutC, OutD>* out) {
912 (obj->*method)(in.a, in.b, in.c, in.d, in.e,
913 &out->a, &out->b, &out->c, &out->d);
914}
915
ojan@google.com38355092008-10-10 06:58:05 +0900916template<class ObjT, class Method,
917 class InA, class InB, class InC, class InD, class InE, class InF,
918 class OutA, class OutB, class OutC, class OutD>
919inline void DispatchToMethod(ObjT* obj, Method method,
920 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
921 Tuple4<OutA, OutB, OutC, OutD>* out) {
922 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f,
923 &out->a, &out->b, &out->c, &out->d);
924}
925
initial.commit3f4a7322008-07-27 06:49:38 +0900926// Dispatchers with 5 out params.
927
928template<class ObjT, class Method,
929 class OutA, class OutB, class OutC, class OutD, class OutE>
930inline void DispatchToMethod(ObjT* obj, Method method,
931 const Tuple0& in,
932 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
933 (obj->*method)(&out->a, &out->b, &out->c, &out->d, &out->e);
934}
935
936template<class ObjT, class Method, class InA,
937 class OutA, class OutB, class OutC, class OutD, class OutE>
938inline void DispatchToMethod(ObjT* obj, Method method,
939 const InA& in,
940 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
941 (obj->*method)(in, &out->a, &out->b, &out->c, &out->d, &out->e);
942}
943
944template<class ObjT, class Method, class InA,
945 class OutA, class OutB, class OutC, class OutD, class OutE>
946inline void DispatchToMethod(ObjT* obj, Method method,
947 const Tuple1<InA>& in,
948 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
949 (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d, &out->e);
950}
951
952template<class ObjT, class Method, class InA, class InB,
953 class OutA, class OutB, class OutC, class OutD, class OutE>
954inline void DispatchToMethod(ObjT* obj, Method method,
955 const Tuple2<InA, InB>& in,
956 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
957 (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d, &out->e);
958}
959
960template<class ObjT, class Method, class InA, class InB, class InC,
961 class OutA, class OutB, class OutC, class OutD, class OutE>
962inline void DispatchToMethod(ObjT* obj, Method method,
963 const Tuple3<InA, InB, InC>& in,
964 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
965 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d, &out->e);
966}
967
968template<class ObjT, class Method, class InA, class InB, class InC, class InD,
969 class OutA, class OutB, class OutC, class OutD, class OutE>
970inline void DispatchToMethod(ObjT* obj, Method method,
971 const Tuple4<InA, InB, InC, InD>& in,
972 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
973 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d,
974 &out->e);
975}
976
977template<class ObjT, class Method,
978 class InA, class InB, class InC, class InD, class InE,
979 class OutA, class OutB, class OutC, class OutD, class OutE>
980inline void DispatchToMethod(ObjT* obj, Method method,
981 const Tuple5<InA, InB, InC, InD, InE>& in,
982 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
983 (obj->*method)(in.a, in.b, in.c, in.d, in.e,
984 &out->a, &out->b, &out->c, &out->d, &out->e);
985}
986
ojan@google.com38355092008-10-10 06:58:05 +0900987template<class ObjT, class Method,
988 class InA, class InB, class InC, class InD, class InE, class InF,
989 class OutA, class OutB, class OutC, class OutD, class OutE>
990inline void DispatchToMethod(ObjT* obj, Method method,
991 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
992 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
993 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f,
994 &out->a, &out->b, &out->c, &out->d, &out->e);
995}
996
initial.commit3f4a7322008-07-27 06:49:38 +0900997#endif // BASE_TUPLE_H__