blob: 13d8722eb31b59ec84c8c3870a9f90a4c365cd8d [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
oshima@chromium.org061e50f2010-12-02 09:11:40 +090033#if defined(OS_CHROMEOS)
34// To troubleshoot crosbug.com/7327.
35#include "base/logging.h"
36#endif
initial.commit3f4a7322008-07-27 06:49:38 +090037// Traits ----------------------------------------------------------------------
38//
39// A simple traits class for tuple arguments.
40//
41// ValueType: the bare, nonref version of a type (same as the type for nonrefs).
42// RefType: the ref version of a type (same as the type for refs).
43// ParamType: what type to pass to functions (refs should not be constified).
44
45template <class P>
46struct TupleTraits {
47 typedef P ValueType;
48 typedef P& RefType;
49 typedef const P& ParamType;
50};
51
52template <class P>
53struct TupleTraits<P&> {
54 typedef P ValueType;
55 typedef P& RefType;
56 typedef P& ParamType;
57};
58
erg@google.come6ffcb52010-08-18 03:38:24 +090059template <class P>
60struct TupleTypes { };
61
initial.commit3f4a7322008-07-27 06:49:38 +090062// Tuple -----------------------------------------------------------------------
63//
64// This set of classes is useful for bundling 0 or more heterogeneous data types
65// into a single variable. The advantage of this is that it greatly simplifies
66// function objects that need to take an arbitrary number of parameters; see
67// RunnableMethod and IPC::MessageWithTuple.
68//
deanm@google.comff4b7292008-08-21 19:58:08 +090069// Tuple0 is supplied to act as a 'void' type. It can be used, for example,
70// when dispatching to a function that accepts no arguments (see the
71// Dispatchers below).
initial.commit3f4a7322008-07-27 06:49:38 +090072// Tuple1<A> is rarely useful. One such use is when A is non-const ref that you
73// want filled by the dispatchee, and the tuple is merely a container for that
74// output (a "tier"). See MakeRefTuple and its usages.
75
76struct Tuple0 {
77 typedef Tuple0 ValueTuple;
78 typedef Tuple0 RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +090079 typedef Tuple0 ParamTuple;
initial.commit3f4a7322008-07-27 06:49:38 +090080};
81
82template <class A>
83struct Tuple1 {
84 public:
85 typedef A TypeA;
initial.commit3f4a7322008-07-27 06:49:38 +090086
87 Tuple1() {}
88 explicit Tuple1(typename TupleTraits<A>::ParamType a) : a(a) {}
89
90 A a;
91};
92
93template <class A, class B>
94struct Tuple2 {
95 public:
96 typedef A TypeA;
97 typedef B TypeB;
initial.commit3f4a7322008-07-27 06:49:38 +090098
99 Tuple2() {}
100 Tuple2(typename TupleTraits<A>::ParamType a,
101 typename TupleTraits<B>::ParamType b)
102 : a(a), b(b) {
103 }
104
105 A a;
106 B b;
107};
108
109template <class A, class B, class C>
110struct Tuple3 {
111 public:
112 typedef A TypeA;
113 typedef B TypeB;
114 typedef C TypeC;
initial.commit3f4a7322008-07-27 06:49:38 +0900115
116 Tuple3() {}
117 Tuple3(typename TupleTraits<A>::ParamType a,
118 typename TupleTraits<B>::ParamType b,
119 typename TupleTraits<C>::ParamType c)
120 : a(a), b(b), c(c){
121 }
122
123 A a;
124 B b;
125 C c;
126};
127
128template <class A, class B, class C, class D>
129struct Tuple4 {
130 public:
131 typedef A TypeA;
132 typedef B TypeB;
133 typedef C TypeC;
134 typedef D TypeD;
initial.commit3f4a7322008-07-27 06:49:38 +0900135
136 Tuple4() {}
137 Tuple4(typename TupleTraits<A>::ParamType a,
138 typename TupleTraits<B>::ParamType b,
139 typename TupleTraits<C>::ParamType c,
140 typename TupleTraits<D>::ParamType d)
141 : a(a), b(b), c(c), d(d) {
142 }
143
144 A a;
145 B b;
146 C c;
147 D d;
148};
149
150template <class A, class B, class C, class D, class E>
151struct Tuple5 {
erg@google.combf6ce9f2010-01-27 08:08:02 +0900152 public:
initial.commit3f4a7322008-07-27 06:49:38 +0900153 typedef A TypeA;
154 typedef B TypeB;
155 typedef C TypeC;
156 typedef D TypeD;
157 typedef E TypeE;
initial.commit3f4a7322008-07-27 06:49:38 +0900158
159 Tuple5() {}
160 Tuple5(typename TupleTraits<A>::ParamType a,
161 typename TupleTraits<B>::ParamType b,
162 typename TupleTraits<C>::ParamType c,
163 typename TupleTraits<D>::ParamType d,
164 typename TupleTraits<E>::ParamType e)
165 : a(a), b(b), c(c), d(d), e(e) {
166 }
167
168 A a;
169 B b;
170 C c;
171 D d;
172 E e;
173};
174
ojan@google.com38355092008-10-10 06:58:05 +0900175template <class A, class B, class C, class D, class E, class F>
176struct Tuple6 {
erg@google.combf6ce9f2010-01-27 08:08:02 +0900177 public:
ojan@google.com38355092008-10-10 06:58:05 +0900178 typedef A TypeA;
179 typedef B TypeB;
180 typedef C TypeC;
181 typedef D TypeD;
182 typedef E TypeE;
183 typedef F TypeF;
ojan@google.com38355092008-10-10 06:58:05 +0900184
185 Tuple6() {}
186 Tuple6(typename TupleTraits<A>::ParamType a,
187 typename TupleTraits<B>::ParamType b,
188 typename TupleTraits<C>::ParamType c,
189 typename TupleTraits<D>::ParamType d,
190 typename TupleTraits<E>::ParamType e,
191 typename TupleTraits<F>::ParamType f)
192 : a(a), b(b), c(c), d(d), e(e), f(f) {
193 }
194
195 A a;
196 B b;
197 C c;
198 D d;
199 E e;
200 F f;
201};
202
sky@google.com67c35752008-11-13 07:10:20 +0900203template <class A, class B, class C, class D, class E, class F, class G>
204struct Tuple7 {
erg@google.combf6ce9f2010-01-27 08:08:02 +0900205 public:
sky@google.com67c35752008-11-13 07:10:20 +0900206 typedef A TypeA;
207 typedef B TypeB;
208 typedef C TypeC;
209 typedef D TypeD;
210 typedef E TypeE;
211 typedef F TypeF;
212 typedef G TypeG;
sky@google.com67c35752008-11-13 07:10:20 +0900213
214 Tuple7() {}
215 Tuple7(typename TupleTraits<A>::ParamType a,
216 typename TupleTraits<B>::ParamType b,
217 typename TupleTraits<C>::ParamType c,
218 typename TupleTraits<D>::ParamType d,
219 typename TupleTraits<E>::ParamType e,
220 typename TupleTraits<F>::ParamType f,
221 typename TupleTraits<G>::ParamType g)
222 : a(a), b(b), c(c), d(d), e(e), f(f), g(g) {
223 }
224
225 A a;
226 B b;
227 C c;
228 D d;
229 E e;
230 F f;
231 G g;
232};
233
phajdan.jr@chromium.org5a468fc2010-07-21 01:56:26 +0900234template <class A, class B, class C, class D, class E, class F, class G,
235 class H>
236struct Tuple8 {
237 public:
238 typedef A TypeA;
239 typedef B TypeB;
240 typedef C TypeC;
241 typedef D TypeD;
242 typedef E TypeE;
243 typedef F TypeF;
244 typedef G TypeG;
245 typedef H TypeH;
phajdan.jr@chromium.org5a468fc2010-07-21 01:56:26 +0900246
247 Tuple8() {}
248 Tuple8(typename TupleTraits<A>::ParamType a,
249 typename TupleTraits<B>::ParamType b,
250 typename TupleTraits<C>::ParamType c,
251 typename TupleTraits<D>::ParamType d,
252 typename TupleTraits<E>::ParamType e,
253 typename TupleTraits<F>::ParamType f,
254 typename TupleTraits<G>::ParamType g,
255 typename TupleTraits<H>::ParamType h)
256 : a(a), b(b), c(c), d(d), e(e), f(f), g(g), h(h) {
257 }
258
259 A a;
260 B b;
261 C c;
262 D d;
263 E e;
264 F f;
265 G g;
266 H h;
267};
268
erg@google.come6ffcb52010-08-18 03:38:24 +0900269// Tuple types ----------------------------------------------------------------
270//
271// Allows for selection of ValueTuple/RefTuple/ParamTuple without needing the
272// definitions of class types the tuple takes as parameters.
273
274template <>
275struct TupleTypes< Tuple0 > {
276 typedef Tuple0 ValueTuple;
277 typedef Tuple0 RefTuple;
278 typedef Tuple0 ParamTuple;
279};
280
281template <class A>
282struct TupleTypes< Tuple1<A> > {
283 typedef Tuple1<typename TupleTraits<A>::ValueType> ValueTuple;
284 typedef Tuple1<typename TupleTraits<A>::RefType> RefTuple;
285 typedef Tuple1<typename TupleTraits<A>::ParamType> ParamTuple;
286};
287
288template <class A, class B>
289struct TupleTypes< Tuple2<A, B> > {
290 typedef Tuple2<typename TupleTraits<A>::ValueType,
291 typename TupleTraits<B>::ValueType> ValueTuple;
292typedef Tuple2<typename TupleTraits<A>::RefType,
293 typename TupleTraits<B>::RefType> RefTuple;
294 typedef Tuple2<typename TupleTraits<A>::ParamType,
295 typename TupleTraits<B>::ParamType> ParamTuple;
296};
297
298template <class A, class B, class C>
299struct TupleTypes< Tuple3<A, B, C> > {
300 typedef Tuple3<typename TupleTraits<A>::ValueType,
301 typename TupleTraits<B>::ValueType,
302 typename TupleTraits<C>::ValueType> ValueTuple;
303typedef Tuple3<typename TupleTraits<A>::RefType,
304 typename TupleTraits<B>::RefType,
305 typename TupleTraits<C>::RefType> RefTuple;
306 typedef Tuple3<typename TupleTraits<A>::ParamType,
307 typename TupleTraits<B>::ParamType,
308 typename TupleTraits<C>::ParamType> ParamTuple;
309};
310
311template <class A, class B, class C, class D>
312struct TupleTypes< Tuple4<A, B, C, D> > {
313 typedef Tuple4<typename TupleTraits<A>::ValueType,
314 typename TupleTraits<B>::ValueType,
315 typename TupleTraits<C>::ValueType,
316 typename TupleTraits<D>::ValueType> ValueTuple;
317typedef Tuple4<typename TupleTraits<A>::RefType,
318 typename TupleTraits<B>::RefType,
319 typename TupleTraits<C>::RefType,
320 typename TupleTraits<D>::RefType> RefTuple;
321 typedef Tuple4<typename TupleTraits<A>::ParamType,
322 typename TupleTraits<B>::ParamType,
323 typename TupleTraits<C>::ParamType,
324 typename TupleTraits<D>::ParamType> ParamTuple;
325};
326
327template <class A, class B, class C, class D, class E>
328struct TupleTypes< Tuple5<A, B, C, D, E> > {
329 typedef Tuple5<typename TupleTraits<A>::ValueType,
330 typename TupleTraits<B>::ValueType,
331 typename TupleTraits<C>::ValueType,
332 typename TupleTraits<D>::ValueType,
333 typename TupleTraits<E>::ValueType> ValueTuple;
334typedef Tuple5<typename TupleTraits<A>::RefType,
335 typename TupleTraits<B>::RefType,
336 typename TupleTraits<C>::RefType,
337 typename TupleTraits<D>::RefType,
338 typename TupleTraits<E>::RefType> RefTuple;
339 typedef Tuple5<typename TupleTraits<A>::ParamType,
340 typename TupleTraits<B>::ParamType,
341 typename TupleTraits<C>::ParamType,
342 typename TupleTraits<D>::ParamType,
343 typename TupleTraits<E>::ParamType> ParamTuple;
344};
345
346template <class A, class B, class C, class D, class E, class F>
347struct TupleTypes< Tuple6<A, B, C, D, E, F> > {
348 typedef Tuple6<typename TupleTraits<A>::ValueType,
349 typename TupleTraits<B>::ValueType,
350 typename TupleTraits<C>::ValueType,
351 typename TupleTraits<D>::ValueType,
352 typename TupleTraits<E>::ValueType,
353 typename TupleTraits<F>::ValueType> ValueTuple;
354typedef Tuple6<typename TupleTraits<A>::RefType,
355 typename TupleTraits<B>::RefType,
356 typename TupleTraits<C>::RefType,
357 typename TupleTraits<D>::RefType,
358 typename TupleTraits<E>::RefType,
359 typename TupleTraits<F>::RefType> RefTuple;
360 typedef Tuple6<typename TupleTraits<A>::ParamType,
361 typename TupleTraits<B>::ParamType,
362 typename TupleTraits<C>::ParamType,
363 typename TupleTraits<D>::ParamType,
364 typename TupleTraits<E>::ParamType,
365 typename TupleTraits<F>::ParamType> ParamTuple;
366};
367
368template <class A, class B, class C, class D, class E, class F, class G>
369struct TupleTypes< Tuple7<A, B, C, D, E, F, G> > {
370 typedef Tuple7<typename TupleTraits<A>::ValueType,
371 typename TupleTraits<B>::ValueType,
372 typename TupleTraits<C>::ValueType,
373 typename TupleTraits<D>::ValueType,
374 typename TupleTraits<E>::ValueType,
375 typename TupleTraits<F>::ValueType,
376 typename TupleTraits<G>::ValueType> ValueTuple;
377typedef Tuple7<typename TupleTraits<A>::RefType,
378 typename TupleTraits<B>::RefType,
379 typename TupleTraits<C>::RefType,
380 typename TupleTraits<D>::RefType,
381 typename TupleTraits<E>::RefType,
382 typename TupleTraits<F>::RefType,
383 typename TupleTraits<G>::RefType> RefTuple;
384 typedef Tuple7<typename TupleTraits<A>::ParamType,
385 typename TupleTraits<B>::ParamType,
386 typename TupleTraits<C>::ParamType,
387 typename TupleTraits<D>::ParamType,
388 typename TupleTraits<E>::ParamType,
389 typename TupleTraits<F>::ParamType,
390 typename TupleTraits<G>::ParamType> ParamTuple;
391};
392
393template <class A, class B, class C, class D, class E, class F, class G,
394 class H>
395struct TupleTypes< Tuple8<A, B, C, D, E, F, G, H> > {
396 typedef Tuple8<typename TupleTraits<A>::ValueType,
397 typename TupleTraits<B>::ValueType,
398 typename TupleTraits<C>::ValueType,
399 typename TupleTraits<D>::ValueType,
400 typename TupleTraits<E>::ValueType,
401 typename TupleTraits<F>::ValueType,
402 typename TupleTraits<G>::ValueType,
403 typename TupleTraits<H>::ValueType> ValueTuple;
404typedef Tuple8<typename TupleTraits<A>::RefType,
405 typename TupleTraits<B>::RefType,
406 typename TupleTraits<C>::RefType,
407 typename TupleTraits<D>::RefType,
408 typename TupleTraits<E>::RefType,
409 typename TupleTraits<F>::RefType,
410 typename TupleTraits<G>::RefType,
411 typename TupleTraits<H>::RefType> RefTuple;
412 typedef Tuple8<typename TupleTraits<A>::ParamType,
413 typename TupleTraits<B>::ParamType,
414 typename TupleTraits<C>::ParamType,
415 typename TupleTraits<D>::ParamType,
416 typename TupleTraits<E>::ParamType,
417 typename TupleTraits<F>::ParamType,
418 typename TupleTraits<G>::ParamType,
419 typename TupleTraits<H>::ParamType> ParamTuple;
420};
421
initial.commit3f4a7322008-07-27 06:49:38 +0900422// Tuple creators -------------------------------------------------------------
423//
424// Helper functions for constructing tuples while inferring the template
425// argument types.
426
427inline Tuple0 MakeTuple() {
428 return Tuple0();
429}
430
431template <class A>
432inline Tuple1<A> MakeTuple(const A& a) {
433 return Tuple1<A>(a);
434}
435
436template <class A, class B>
437inline Tuple2<A, B> MakeTuple(const A& a, const B& b) {
438 return Tuple2<A, B>(a, b);
439}
440
441template <class A, class B, class C>
442inline Tuple3<A, B, C> MakeTuple(const A& a, const B& b, const 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> MakeTuple(const A& a, const B& b, const C& c,
448 const D& d) {
449 return Tuple4<A, B, C, D>(a, b, c, d);
450}
451
452template <class A, class B, class C, class D, class E>
453inline Tuple5<A, B, C, D, E> MakeTuple(const A& a, const B& b, const C& c,
454 const D& d, const E& e) {
455 return Tuple5<A, B, C, D, E>(a, b, c, d, e);
456}
457
ojan@google.com38355092008-10-10 06:58:05 +0900458template <class A, class B, class C, class D, class E, class F>
459inline Tuple6<A, B, C, D, E, F> MakeTuple(const A& a, const B& b, const C& c,
460 const D& d, const E& e, const F& f) {
461 return Tuple6<A, B, C, D, E, F>(a, b, c, d, e, f);
462}
463
sky@google.com67c35752008-11-13 07:10:20 +0900464template <class A, class B, class C, class D, class E, class F, class G>
465inline Tuple7<A, B, C, D, E, F, G> MakeTuple(const A& a, const B& b, const C& c,
466 const D& d, const E& e, const F& f,
467 const G& g) {
468 return Tuple7<A, B, C, D, E, F, G>(a, b, c, d, e, f, g);
469}
470
phajdan.jr@chromium.org5a468fc2010-07-21 01:56:26 +0900471template <class A, class B, class C, class D, class E, class F, class G,
472 class H>
473inline Tuple8<A, B, C, D, E, F, G, H> MakeTuple(const A& a, const B& b,
474 const C& c, const D& d,
475 const E& e, const F& f,
476 const G& g, const H& h) {
477 return Tuple8<A, B, C, D, E, F, G, H>(a, b, c, d, e, f, g, h);
478}
479
initial.commit3f4a7322008-07-27 06:49:38 +0900480// The following set of helpers make what Boost refers to as "Tiers" - a tuple
481// of references.
482
483template <class A>
484inline Tuple1<A&> MakeRefTuple(A& a) {
485 return Tuple1<A&>(a);
486}
487
488template <class A, class B>
489inline Tuple2<A&, B&> MakeRefTuple(A& a, B& b) {
490 return Tuple2<A&, B&>(a, b);
491}
492
493template <class A, class B, class C>
494inline Tuple3<A&, B&, C&> MakeRefTuple(A& a, B& b, C& c) {
495 return Tuple3<A&, B&, C&>(a, b, c);
496}
497
498template <class A, class B, class C, class D>
499inline Tuple4<A&, B&, C&, D&> MakeRefTuple(A& a, B& b, C& c, D& d) {
500 return Tuple4<A&, B&, C&, D&>(a, b, c, d);
501}
502
503template <class A, class B, class C, class D, class E>
504inline Tuple5<A&, B&, C&, D&, E&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e) {
505 return Tuple5<A&, B&, C&, D&, E&>(a, b, c, d, e);
506}
507
ojan@google.com38355092008-10-10 06:58:05 +0900508template <class A, class B, class C, class D, class E, class F>
509inline Tuple6<A&, B&, C&, D&, E&, F&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e,
510 F& f) {
511 return Tuple6<A&, B&, C&, D&, E&, F&>(a, b, c, d, e, f);
512}
513
sky@google.com67c35752008-11-13 07:10:20 +0900514template <class A, class B, class C, class D, class E, class F, class G>
515inline Tuple7<A&, B&, C&, D&, E&, F&, G&> MakeRefTuple(A& a, B& b, C& c, D& d,
516 E& e, F& f, G& g) {
517 return Tuple7<A&, B&, C&, D&, E&, F&, G&>(a, b, c, d, e, f, g);
518}
519
phajdan.jr@chromium.org5a468fc2010-07-21 01:56:26 +0900520template <class A, class B, class C, class D, class E, class F, class G,
521 class H>
522inline Tuple8<A&, B&, C&, D&, E&, F&, G&, H&> MakeRefTuple(A& a, B& b, C& c,
523 D& d, E& e, F& f,
524 G& g, H& h) {
525 return Tuple8<A&, B&, C&, D&, E&, F&, G&, H&>(a, b, c, d, e, f, g, h);
526}
527
initial.commit3f4a7322008-07-27 06:49:38 +0900528// Dispatchers ----------------------------------------------------------------
529//
530// Helper functions that call the given method on an object, with the unpacked
531// tuple arguments. Notice that they all have the same number of arguments,
532// so you need only write:
533// DispatchToMethod(object, &Object::method, args);
534// This is very useful for templated dispatchers, since they don't need to know
535// what type |args| is.
536
537// Non-Static Dispatchers with no out params.
538
539template <class ObjT, class Method>
540inline void DispatchToMethod(ObjT* obj, Method method, const Tuple0& arg) {
541 (obj->*method)();
542}
543
544template <class ObjT, class Method, class A>
545inline void DispatchToMethod(ObjT* obj, Method method, const A& arg) {
546 (obj->*method)(arg);
547}
548
549template <class ObjT, class Method, class A>
550inline void DispatchToMethod(ObjT* obj, Method method, const Tuple1<A>& arg) {
551 (obj->*method)(arg.a);
552}
553
554template<class ObjT, class Method, class A, class B>
maruel@chromium.org8fe7adc2009-03-04 00:01:12 +0900555inline void DispatchToMethod(ObjT* obj,
556 Method method,
557 const Tuple2<A, B>& arg) {
initial.commit3f4a7322008-07-27 06:49:38 +0900558 (obj->*method)(arg.a, arg.b);
559}
560
561template<class ObjT, class Method, class A, class B, class C>
562inline void DispatchToMethod(ObjT* obj, Method method,
563 const Tuple3<A, B, C>& arg) {
564 (obj->*method)(arg.a, arg.b, arg.c);
565}
566
567template<class ObjT, class Method, class A, class B, class C, class D>
568inline void DispatchToMethod(ObjT* obj, Method method,
569 const Tuple4<A, B, C, D>& arg) {
570 (obj->*method)(arg.a, arg.b, arg.c, arg.d);
571}
572
573template<class ObjT, class Method, class A, class B, class C, class D, class E>
574inline void DispatchToMethod(ObjT* obj, Method method,
575 const Tuple5<A, B, C, D, E>& arg) {
576 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e);
577}
578
ojan@google.com38355092008-10-10 06:58:05 +0900579template<class ObjT, class Method, class A, class B, class C, class D, class E,
580 class F>
581inline void DispatchToMethod(ObjT* obj, Method method,
582 const Tuple6<A, B, C, D, E, F>& arg) {
583 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
584}
585
sky@google.com67c35752008-11-13 07:10:20 +0900586template<class ObjT, class Method, class A, class B, class C, class D, class E,
587 class F, class G>
588inline void DispatchToMethod(ObjT* obj, Method method,
589 const Tuple7<A, B, C, D, E, F, G>& arg) {
590 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g);
591}
592
initial.commit3f4a7322008-07-27 06:49:38 +0900593// Static Dispatchers with no out params.
594
595template <class Function>
596inline void DispatchToFunction(Function function, const Tuple0& arg) {
597 (*function)();
598}
599
600template <class Function, class A>
601inline void DispatchToFunction(Function function, const A& arg) {
602 (*function)(arg);
603}
604
605template <class Function, class A>
606inline void DispatchToFunction(Function function, const Tuple1<A>& arg) {
607 (*function)(arg.a);
608}
609
610template<class Function, class A, class B>
611inline void DispatchToFunction(Function function, const Tuple2<A, B>& arg) {
612 (*function)(arg.a, arg.b);
613}
614
615template<class Function, class A, class B, class C>
616inline void DispatchToFunction(Function function, const Tuple3<A, B, C>& arg) {
617 (*function)(arg.a, arg.b, arg.c);
618}
619
620template<class Function, class A, class B, class C, class D>
621inline void DispatchToFunction(Function function,
622 const Tuple4<A, B, C, D>& arg) {
623 (*function)(arg.a, arg.b, arg.c, arg.d);
624}
625
626template<class Function, class A, class B, class C, class D, class E>
627inline void DispatchToFunction(Function function,
628 const Tuple5<A, B, C, D, E>& arg) {
629 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e);
630}
631
ojan@google.com38355092008-10-10 06:58:05 +0900632template<class Function, class A, class B, class C, class D, class E, class F>
633inline void DispatchToFunction(Function function,
634 const Tuple6<A, B, C, D, E, F>& arg) {
635 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
636}
637
phajdan.jr@chromium.org5a468fc2010-07-21 01:56:26 +0900638template<class Function, class A, class B, class C, class D, class E, class F,
639 class G>
640inline void DispatchToFunction(Function function,
641 const Tuple7<A, B, C, D, E, F, G>& arg) {
642 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g);
643}
644
645template<class Function, class A, class B, class C, class D, class E, class F,
646 class G, class H>
647inline void DispatchToFunction(Function function,
648 const Tuple8<A, B, C, D, E, F, G, H>& arg) {
649 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g, arg.h);
650}
651
initial.commit3f4a7322008-07-27 06:49:38 +0900652// Dispatchers with 0 out param (as a Tuple0).
653
654template <class ObjT, class Method>
maruel@chromium.org8fe7adc2009-03-04 00:01:12 +0900655inline void DispatchToMethod(ObjT* obj,
656 Method method,
657 const Tuple0& arg, Tuple0*) {
initial.commit3f4a7322008-07-27 06:49:38 +0900658 (obj->*method)();
659}
660
661template <class ObjT, class Method, class A>
662inline void DispatchToMethod(ObjT* obj, Method method, const A& arg, Tuple0*) {
663 (obj->*method)(arg);
664}
665
666template <class ObjT, class Method, class A>
maruel@chromium.org8fe7adc2009-03-04 00:01:12 +0900667inline void DispatchToMethod(ObjT* obj,
668 Method method,
669 const Tuple1<A>& arg, Tuple0*) {
initial.commit3f4a7322008-07-27 06:49:38 +0900670 (obj->*method)(arg.a);
671}
672
673template<class ObjT, class Method, class A, class B>
maruel@chromium.org8fe7adc2009-03-04 00:01:12 +0900674inline void DispatchToMethod(ObjT* obj,
675 Method method,
676 const Tuple2<A, B>& arg, Tuple0*) {
initial.commit3f4a7322008-07-27 06:49:38 +0900677 (obj->*method)(arg.a, arg.b);
678}
679
680template<class ObjT, class Method, class A, class B, class C>
681inline void DispatchToMethod(ObjT* obj, Method method,
682 const Tuple3<A, B, C>& arg, Tuple0*) {
683 (obj->*method)(arg.a, arg.b, arg.c);
684}
685
686template<class ObjT, class Method, class A, class B, class C, class D>
687inline void DispatchToMethod(ObjT* obj, Method method,
688 const Tuple4<A, B, C, D>& arg, Tuple0*) {
689 (obj->*method)(arg.a, arg.b, arg.c, arg.d);
690}
691
692template<class ObjT, class Method, class A, class B, class C, class D, class E>
693inline void DispatchToMethod(ObjT* obj, Method method,
694 const Tuple5<A, B, C, D, E>& arg, Tuple0*) {
695 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e);
696}
697
ojan@google.com38355092008-10-10 06:58:05 +0900698template<class ObjT, class Method, class A, class B, class C, class D, class E,
699 class F>
700inline void DispatchToMethod(ObjT* obj, Method method,
701 const Tuple6<A, B, C, D, E, F>& arg, Tuple0*) {
702 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
703}
704
initial.commit3f4a7322008-07-27 06:49:38 +0900705// Dispatchers with 1 out param.
706
707template<class ObjT, class Method,
708 class OutA>
709inline void DispatchToMethod(ObjT* obj, Method method,
710 const Tuple0& in,
711 Tuple1<OutA>* out) {
712 (obj->*method)(&out->a);
713}
714
715template<class ObjT, class Method, class InA,
716 class OutA>
717inline void DispatchToMethod(ObjT* obj, Method method,
718 const InA& in,
719 Tuple1<OutA>* out) {
720 (obj->*method)(in, &out->a);
721}
722
723template<class ObjT, class Method, class InA,
724 class OutA>
725inline void DispatchToMethod(ObjT* obj, Method method,
726 const Tuple1<InA>& in,
727 Tuple1<OutA>* out) {
728 (obj->*method)(in.a, &out->a);
729}
730
731template<class ObjT, class Method, class InA, class InB,
732 class OutA>
733inline void DispatchToMethod(ObjT* obj, Method method,
734 const Tuple2<InA, InB>& in,
735 Tuple1<OutA>* out) {
736 (obj->*method)(in.a, in.b, &out->a);
737}
738
739template<class ObjT, class Method, class InA, class InB, class InC,
740 class OutA>
741inline void DispatchToMethod(ObjT* obj, Method method,
742 const Tuple3<InA, InB, InC>& in,
743 Tuple1<OutA>* out) {
744 (obj->*method)(in.a, in.b, in.c, &out->a);
745}
746
747template<class ObjT, class Method, class InA, class InB, class InC, class InD,
748 class OutA>
749inline void DispatchToMethod(ObjT* obj, Method method,
750 const Tuple4<InA, InB, InC, InD>& in,
751 Tuple1<OutA>* out) {
752 (obj->*method)(in.a, in.b, in.c, in.d, &out->a);
753}
754
erg@google.combf6ce9f2010-01-27 08:08:02 +0900755template<class ObjT, class Method, class InA, class InB, class InC, class InD,
756 class InE, class OutA>
initial.commit3f4a7322008-07-27 06:49:38 +0900757inline void DispatchToMethod(ObjT* obj, Method method,
758 const Tuple5<InA, InB, InC, InD, InE>& in,
759 Tuple1<OutA>* out) {
760 (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a);
761}
762
ojan@google.com38355092008-10-10 06:58:05 +0900763template<class ObjT, class Method,
764 class InA, class InB, class InC, class InD, class InE, class InF,
765 class OutA>
766inline void DispatchToMethod(ObjT* obj, Method method,
767 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
768 Tuple1<OutA>* out) {
769 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a);
770}
771
initial.commit3f4a7322008-07-27 06:49:38 +0900772// Dispatchers with 2 out params.
773
774template<class ObjT, class Method,
775 class OutA, class OutB>
776inline void DispatchToMethod(ObjT* obj, Method method,
777 const Tuple0& in,
778 Tuple2<OutA, OutB>* out) {
779 (obj->*method)(&out->a, &out->b);
780}
781
782template<class ObjT, class Method, class InA,
783 class OutA, class OutB>
784inline void DispatchToMethod(ObjT* obj, Method method,
785 const InA& in,
786 Tuple2<OutA, OutB>* out) {
787 (obj->*method)(in, &out->a, &out->b);
788}
789
790template<class ObjT, class Method, class InA,
791 class OutA, class OutB>
792inline void DispatchToMethod(ObjT* obj, Method method,
793 const Tuple1<InA>& in,
794 Tuple2<OutA, OutB>* out) {
795 (obj->*method)(in.a, &out->a, &out->b);
796}
797
798template<class ObjT, class Method, class InA, class InB,
799 class OutA, class OutB>
800inline void DispatchToMethod(ObjT* obj, Method method,
801 const Tuple2<InA, InB>& in,
802 Tuple2<OutA, OutB>* out) {
803 (obj->*method)(in.a, in.b, &out->a, &out->b);
804}
805
806template<class ObjT, class Method, class InA, class InB, class InC,
807 class OutA, class OutB>
808inline void DispatchToMethod(ObjT* obj, Method method,
809 const Tuple3<InA, InB, InC>& in,
810 Tuple2<OutA, OutB>* out) {
811 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b);
812}
813
814template<class ObjT, class Method, class InA, class InB, class InC, class InD,
815 class OutA, class OutB>
816inline void DispatchToMethod(ObjT* obj, Method method,
817 const Tuple4<InA, InB, InC, InD>& in,
818 Tuple2<OutA, OutB>* out) {
819 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b);
820}
821
822template<class ObjT, class Method,
823 class InA, class InB, class InC, class InD, class InE,
824 class OutA, class OutB>
825inline void DispatchToMethod(ObjT* obj, Method method,
826 const Tuple5<InA, InB, InC, InD, InE>& in,
827 Tuple2<OutA, OutB>* out) {
828 (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b);
829}
830
ojan@google.com38355092008-10-10 06:58:05 +0900831template<class ObjT, class Method,
832 class InA, class InB, class InC, class InD, class InE, class InF,
833 class OutA, class OutB>
834inline void DispatchToMethod(ObjT* obj, Method method,
835 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
836 Tuple2<OutA, OutB>* out) {
837 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b);
838}
839
initial.commit3f4a7322008-07-27 06:49:38 +0900840// Dispatchers with 3 out params.
841
842template<class ObjT, class Method,
843 class OutA, class OutB, class OutC>
844inline void DispatchToMethod(ObjT* obj, Method method,
845 const Tuple0& in,
846 Tuple3<OutA, OutB, OutC>* out) {
847 (obj->*method)(&out->a, &out->b, &out->c);
848}
849
850template<class ObjT, class Method, class InA,
851 class OutA, class OutB, class OutC>
852inline void DispatchToMethod(ObjT* obj, Method method,
853 const InA& in,
854 Tuple3<OutA, OutB, OutC>* out) {
855 (obj->*method)(in, &out->a, &out->b, &out->c);
856}
857
858template<class ObjT, class Method, class InA,
859 class OutA, class OutB, class OutC>
860inline void DispatchToMethod(ObjT* obj, Method method,
861 const Tuple1<InA>& in,
862 Tuple3<OutA, OutB, OutC>* out) {
863 (obj->*method)(in.a, &out->a, &out->b, &out->c);
864}
865
866template<class ObjT, class Method, class InA, class InB,
867 class OutA, class OutB, class OutC>
868inline void DispatchToMethod(ObjT* obj, Method method,
869 const Tuple2<InA, InB>& in,
870 Tuple3<OutA, OutB, OutC>* out) {
871 (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c);
872}
873
874template<class ObjT, class Method, class InA, class InB, class InC,
875 class OutA, class OutB, class OutC>
876inline void DispatchToMethod(ObjT* obj, Method method,
877 const Tuple3<InA, InB, InC>& in,
878 Tuple3<OutA, OutB, OutC>* out) {
879 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c);
880}
881
882template<class ObjT, class Method, class InA, class InB, class InC, class InD,
883 class OutA, class OutB, class OutC>
884inline void DispatchToMethod(ObjT* obj, Method method,
885 const Tuple4<InA, InB, InC, InD>& in,
886 Tuple3<OutA, OutB, OutC>* out) {
887 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c);
888}
889
890template<class ObjT, class Method,
891 class InA, class InB, class InC, class InD, class InE,
892 class OutA, class OutB, class OutC>
893inline void DispatchToMethod(ObjT* obj, Method method,
894 const Tuple5<InA, InB, InC, InD, InE>& in,
895 Tuple3<OutA, OutB, OutC>* out) {
896 (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b, &out->c);
897}
898
ojan@google.com38355092008-10-10 06:58:05 +0900899template<class ObjT, class Method,
900 class InA, class InB, class InC, class InD, class InE, class InF,
901 class OutA, class OutB, class OutC>
902inline void DispatchToMethod(ObjT* obj, Method method,
903 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
904 Tuple3<OutA, OutB, OutC>* out) {
905 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b, &out->c);
906}
907
initial.commit3f4a7322008-07-27 06:49:38 +0900908// Dispatchers with 4 out params.
909
910template<class ObjT, class Method,
911 class OutA, class OutB, class OutC, class OutD>
912inline void DispatchToMethod(ObjT* obj, Method method,
913 const Tuple0& in,
914 Tuple4<OutA, OutB, OutC, OutD>* out) {
915 (obj->*method)(&out->a, &out->b, &out->c, &out->d);
916}
917
918template<class ObjT, class Method, class InA,
919 class OutA, class OutB, class OutC, class OutD>
920inline void DispatchToMethod(ObjT* obj, Method method,
921 const InA& in,
922 Tuple4<OutA, OutB, OutC, OutD>* out) {
923 (obj->*method)(in, &out->a, &out->b, &out->c, &out->d);
924}
925
926template<class ObjT, class Method, class InA,
927 class OutA, class OutB, class OutC, class OutD>
928inline void DispatchToMethod(ObjT* obj, Method method,
929 const Tuple1<InA>& in,
930 Tuple4<OutA, OutB, OutC, OutD>* out) {
931 (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d);
932}
933
934template<class ObjT, class Method, class InA, class InB,
935 class OutA, class OutB, class OutC, class OutD>
936inline void DispatchToMethod(ObjT* obj, Method method,
937 const Tuple2<InA, InB>& in,
938 Tuple4<OutA, OutB, OutC, OutD>* out) {
939 (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d);
940}
941
942template<class ObjT, class Method, class InA, class InB, class InC,
943 class OutA, class OutB, class OutC, class OutD>
944inline void DispatchToMethod(ObjT* obj, Method method,
945 const Tuple3<InA, InB, InC>& in,
946 Tuple4<OutA, OutB, OutC, OutD>* out) {
947 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d);
948}
949
950template<class ObjT, class Method, class InA, class InB, class InC, class InD,
951 class OutA, class OutB, class OutC, class OutD>
952inline void DispatchToMethod(ObjT* obj, Method method,
953 const Tuple4<InA, InB, InC, InD>& in,
954 Tuple4<OutA, OutB, OutC, OutD>* out) {
955 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d);
956}
957
958template<class ObjT, class Method,
959 class InA, class InB, class InC, class InD, class InE,
960 class OutA, class OutB, class OutC, class OutD>
961inline void DispatchToMethod(ObjT* obj, Method method,
962 const Tuple5<InA, InB, InC, InD, InE>& in,
963 Tuple4<OutA, OutB, OutC, OutD>* out) {
964 (obj->*method)(in.a, in.b, in.c, in.d, in.e,
965 &out->a, &out->b, &out->c, &out->d);
966}
967
ojan@google.com38355092008-10-10 06:58:05 +0900968template<class ObjT, class Method,
969 class InA, class InB, class InC, class InD, class InE, class InF,
970 class OutA, class OutB, class OutC, class OutD>
971inline void DispatchToMethod(ObjT* obj, Method method,
972 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
973 Tuple4<OutA, OutB, OutC, OutD>* out) {
974 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f,
975 &out->a, &out->b, &out->c, &out->d);
976}
977
initial.commit3f4a7322008-07-27 06:49:38 +0900978// Dispatchers with 5 out params.
979
980template<class ObjT, class Method,
981 class OutA, class OutB, class OutC, class OutD, class OutE>
982inline void DispatchToMethod(ObjT* obj, Method method,
983 const Tuple0& in,
984 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
985 (obj->*method)(&out->a, &out->b, &out->c, &out->d, &out->e);
986}
987
988template<class ObjT, class Method, class InA,
989 class OutA, class OutB, class OutC, class OutD, class OutE>
990inline void DispatchToMethod(ObjT* obj, Method method,
991 const InA& in,
992 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
993 (obj->*method)(in, &out->a, &out->b, &out->c, &out->d, &out->e);
994}
995
996template<class ObjT, class Method, class InA,
997 class OutA, class OutB, class OutC, class OutD, class OutE>
998inline void DispatchToMethod(ObjT* obj, Method method,
999 const Tuple1<InA>& in,
1000 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
1001 (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d, &out->e);
1002}
1003
1004template<class ObjT, class Method, class InA, class InB,
1005 class OutA, class OutB, class OutC, class OutD, class OutE>
1006inline void DispatchToMethod(ObjT* obj, Method method,
1007 const Tuple2<InA, InB>& in,
1008 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
1009 (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d, &out->e);
1010}
1011
1012template<class ObjT, class Method, class InA, class InB, class InC,
1013 class OutA, class OutB, class OutC, class OutD, class OutE>
1014inline void DispatchToMethod(ObjT* obj, Method method,
1015 const Tuple3<InA, InB, InC>& in,
1016 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
1017 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d, &out->e);
1018}
1019
1020template<class ObjT, class Method, class InA, class InB, class InC, class InD,
1021 class OutA, class OutB, class OutC, class OutD, class OutE>
1022inline void DispatchToMethod(ObjT* obj, Method method,
1023 const Tuple4<InA, InB, InC, InD>& in,
1024 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
1025 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d,
1026 &out->e);
1027}
1028
1029template<class ObjT, class Method,
1030 class InA, class InB, class InC, class InD, class InE,
1031 class OutA, class OutB, class OutC, class OutD, class OutE>
1032inline void DispatchToMethod(ObjT* obj, Method method,
1033 const Tuple5<InA, InB, InC, InD, InE>& in,
1034 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
1035 (obj->*method)(in.a, in.b, in.c, in.d, in.e,
1036 &out->a, &out->b, &out->c, &out->d, &out->e);
1037}
1038
ojan@google.com38355092008-10-10 06:58:05 +09001039template<class ObjT, class Method,
1040 class InA, class InB, class InC, class InD, class InE, class InF,
1041 class OutA, class OutB, class OutC, class OutD, class OutE>
1042inline void DispatchToMethod(ObjT* obj, Method method,
1043 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
1044 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
1045 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f,
1046 &out->a, &out->b, &out->c, &out->d, &out->e);
1047}
1048
initial.commit3f4a7322008-07-27 06:49:38 +09001049#endif // BASE_TUPLE_H__