blob: d17d9f5afc24070811e73d27580c68e5c8a7e724 [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;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +090071 typedef Tuple0 ParamTuple;
initial.commit3f4a7322008-07-27 06:49:38 +090072};
73
74template <class A>
75struct Tuple1 {
76 public:
77 typedef A TypeA;
78 typedef Tuple1<typename TupleTraits<A>::ValueType> ValueTuple;
79 typedef Tuple1<typename TupleTraits<A>::RefType> RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +090080 typedef Tuple1<typename TupleTraits<A>::ParamType> ParamTuple;
initial.commit3f4a7322008-07-27 06:49:38 +090081
82 Tuple1() {}
83 explicit Tuple1(typename TupleTraits<A>::ParamType a) : a(a) {}
84
85 A a;
86};
87
88template <class A, class B>
89struct Tuple2 {
90 public:
91 typedef A TypeA;
92 typedef B TypeB;
93 typedef Tuple2<typename TupleTraits<A>::ValueType,
94 typename TupleTraits<B>::ValueType> ValueTuple;
95 typedef Tuple2<typename TupleTraits<A>::RefType,
96 typename TupleTraits<B>::RefType> RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +090097 typedef Tuple2<typename TupleTraits<A>::ParamType,
98 typename TupleTraits<B>::ParamType> ParamTuple;
initial.commit3f4a7322008-07-27 06:49:38 +090099
100 Tuple2() {}
101 Tuple2(typename TupleTraits<A>::ParamType a,
102 typename TupleTraits<B>::ParamType b)
103 : a(a), b(b) {
104 }
105
106 A a;
107 B b;
108};
109
110template <class A, class B, class C>
111struct Tuple3 {
112 public:
113 typedef A TypeA;
114 typedef B TypeB;
115 typedef C TypeC;
116 typedef Tuple3<typename TupleTraits<A>::ValueType,
117 typename TupleTraits<B>::ValueType,
118 typename TupleTraits<C>::ValueType> ValueTuple;
119 typedef Tuple3<typename TupleTraits<A>::RefType,
120 typename TupleTraits<B>::RefType,
121 typename TupleTraits<C>::RefType> RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +0900122 typedef Tuple3<typename TupleTraits<A>::ParamType,
123 typename TupleTraits<B>::ParamType,
124 typename TupleTraits<C>::ParamType> ParamTuple;
initial.commit3f4a7322008-07-27 06:49:38 +0900125
126 Tuple3() {}
127 Tuple3(typename TupleTraits<A>::ParamType a,
128 typename TupleTraits<B>::ParamType b,
129 typename TupleTraits<C>::ParamType c)
130 : a(a), b(b), c(c){
131 }
132
133 A a;
134 B b;
135 C c;
136};
137
138template <class A, class B, class C, class D>
139struct Tuple4 {
140 public:
141 typedef A TypeA;
142 typedef B TypeB;
143 typedef C TypeC;
144 typedef D TypeD;
145 typedef Tuple4<typename TupleTraits<A>::ValueType,
146 typename TupleTraits<B>::ValueType,
147 typename TupleTraits<C>::ValueType,
148 typename TupleTraits<D>::ValueType> ValueTuple;
149 typedef Tuple4<typename TupleTraits<A>::RefType,
150 typename TupleTraits<B>::RefType,
151 typename TupleTraits<C>::RefType,
152 typename TupleTraits<D>::RefType> RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +0900153 typedef Tuple4<typename TupleTraits<A>::ParamType,
154 typename TupleTraits<B>::ParamType,
155 typename TupleTraits<C>::ParamType,
156 typename TupleTraits<D>::ParamType> ParamTuple;
initial.commit3f4a7322008-07-27 06:49:38 +0900157
158 Tuple4() {}
159 Tuple4(typename TupleTraits<A>::ParamType a,
160 typename TupleTraits<B>::ParamType b,
161 typename TupleTraits<C>::ParamType c,
162 typename TupleTraits<D>::ParamType d)
163 : a(a), b(b), c(c), d(d) {
164 }
165
166 A a;
167 B b;
168 C c;
169 D d;
170};
171
172template <class A, class B, class C, class D, class E>
173struct Tuple5 {
erg@google.combf6ce9f2010-01-27 08:08:02 +0900174 public:
initial.commit3f4a7322008-07-27 06:49:38 +0900175 typedef A TypeA;
176 typedef B TypeB;
177 typedef C TypeC;
178 typedef D TypeD;
179 typedef E TypeE;
180 typedef Tuple5<typename TupleTraits<A>::ValueType,
181 typename TupleTraits<B>::ValueType,
182 typename TupleTraits<C>::ValueType,
183 typename TupleTraits<D>::ValueType,
184 typename TupleTraits<E>::ValueType> ValueTuple;
185 typedef Tuple5<typename TupleTraits<A>::RefType,
186 typename TupleTraits<B>::RefType,
187 typename TupleTraits<C>::RefType,
188 typename TupleTraits<D>::RefType,
189 typename TupleTraits<E>::RefType> RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +0900190 typedef Tuple5<typename TupleTraits<A>::ParamType,
191 typename TupleTraits<B>::ParamType,
192 typename TupleTraits<C>::ParamType,
193 typename TupleTraits<D>::ParamType,
194 typename TupleTraits<E>::ParamType> ParamTuple;
initial.commit3f4a7322008-07-27 06:49:38 +0900195
196 Tuple5() {}
197 Tuple5(typename TupleTraits<A>::ParamType a,
198 typename TupleTraits<B>::ParamType b,
199 typename TupleTraits<C>::ParamType c,
200 typename TupleTraits<D>::ParamType d,
201 typename TupleTraits<E>::ParamType e)
202 : a(a), b(b), c(c), d(d), e(e) {
203 }
204
205 A a;
206 B b;
207 C c;
208 D d;
209 E e;
210};
211
ojan@google.com38355092008-10-10 06:58:05 +0900212template <class A, class B, class C, class D, class E, class F>
213struct Tuple6 {
erg@google.combf6ce9f2010-01-27 08:08:02 +0900214 public:
ojan@google.com38355092008-10-10 06:58:05 +0900215 typedef A TypeA;
216 typedef B TypeB;
217 typedef C TypeC;
218 typedef D TypeD;
219 typedef E TypeE;
220 typedef F TypeF;
221 typedef Tuple6<typename TupleTraits<A>::ValueType,
222 typename TupleTraits<B>::ValueType,
223 typename TupleTraits<C>::ValueType,
224 typename TupleTraits<D>::ValueType,
225 typename TupleTraits<E>::ValueType,
226 typename TupleTraits<F>::ValueType> ValueTuple;
227 typedef Tuple6<typename TupleTraits<A>::RefType,
228 typename TupleTraits<B>::RefType,
229 typename TupleTraits<C>::RefType,
230 typename TupleTraits<D>::RefType,
231 typename TupleTraits<E>::RefType,
232 typename TupleTraits<F>::RefType> RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +0900233 typedef Tuple6<typename TupleTraits<A>::ParamType,
234 typename TupleTraits<B>::ParamType,
235 typename TupleTraits<C>::ParamType,
236 typename TupleTraits<D>::ParamType,
237 typename TupleTraits<E>::ParamType,
238 typename TupleTraits<F>::ParamType> ParamTuple;
ojan@google.com38355092008-10-10 06:58:05 +0900239
240 Tuple6() {}
241 Tuple6(typename TupleTraits<A>::ParamType a,
242 typename TupleTraits<B>::ParamType b,
243 typename TupleTraits<C>::ParamType c,
244 typename TupleTraits<D>::ParamType d,
245 typename TupleTraits<E>::ParamType e,
246 typename TupleTraits<F>::ParamType f)
247 : a(a), b(b), c(c), d(d), e(e), f(f) {
248 }
249
250 A a;
251 B b;
252 C c;
253 D d;
254 E e;
255 F f;
256};
257
sky@google.com67c35752008-11-13 07:10:20 +0900258template <class A, class B, class C, class D, class E, class F, class G>
259struct Tuple7 {
erg@google.combf6ce9f2010-01-27 08:08:02 +0900260 public:
sky@google.com67c35752008-11-13 07:10:20 +0900261 typedef A TypeA;
262 typedef B TypeB;
263 typedef C TypeC;
264 typedef D TypeD;
265 typedef E TypeE;
266 typedef F TypeF;
267 typedef G TypeG;
268 typedef Tuple7<typename TupleTraits<A>::ValueType,
269 typename TupleTraits<B>::ValueType,
270 typename TupleTraits<C>::ValueType,
271 typename TupleTraits<D>::ValueType,
272 typename TupleTraits<E>::ValueType,
273 typename TupleTraits<F>::ValueType,
274 typename TupleTraits<G>::ValueType> ValueTuple;
275 typedef Tuple7<typename TupleTraits<A>::RefType,
276 typename TupleTraits<B>::RefType,
277 typename TupleTraits<C>::RefType,
278 typename TupleTraits<D>::RefType,
279 typename TupleTraits<E>::RefType,
280 typename TupleTraits<F>::RefType,
281 typename TupleTraits<G>::RefType> RefTuple;
mpcomplete@google.coma74ef822009-05-21 03:24:14 +0900282 typedef Tuple7<typename TupleTraits<A>::ParamType,
283 typename TupleTraits<B>::ParamType,
284 typename TupleTraits<C>::ParamType,
285 typename TupleTraits<D>::ParamType,
286 typename TupleTraits<E>::ParamType,
287 typename TupleTraits<F>::ParamType,
288 typename TupleTraits<G>::ParamType> ParamTuple;
sky@google.com67c35752008-11-13 07:10:20 +0900289
290 Tuple7() {}
291 Tuple7(typename TupleTraits<A>::ParamType a,
292 typename TupleTraits<B>::ParamType b,
293 typename TupleTraits<C>::ParamType c,
294 typename TupleTraits<D>::ParamType d,
295 typename TupleTraits<E>::ParamType e,
296 typename TupleTraits<F>::ParamType f,
297 typename TupleTraits<G>::ParamType g)
298 : a(a), b(b), c(c), d(d), e(e), f(f), g(g) {
299 }
300
301 A a;
302 B b;
303 C c;
304 D d;
305 E e;
306 F f;
307 G g;
308};
309
phajdan.jr@chromium.org5a468fc2010-07-21 01:56:26 +0900310template <class A, class B, class C, class D, class E, class F, class G,
311 class H>
312struct Tuple8 {
313 public:
314 typedef A TypeA;
315 typedef B TypeB;
316 typedef C TypeC;
317 typedef D TypeD;
318 typedef E TypeE;
319 typedef F TypeF;
320 typedef G TypeG;
321 typedef H TypeH;
322 typedef Tuple8<typename TupleTraits<A>::ValueType,
323 typename TupleTraits<B>::ValueType,
324 typename TupleTraits<C>::ValueType,
325 typename TupleTraits<D>::ValueType,
326 typename TupleTraits<E>::ValueType,
327 typename TupleTraits<F>::ValueType,
328 typename TupleTraits<G>::ValueType,
329 typename TupleTraits<H>::ValueType> ValueTuple;
330 typedef Tuple8<typename TupleTraits<A>::RefType,
331 typename TupleTraits<B>::RefType,
332 typename TupleTraits<C>::RefType,
333 typename TupleTraits<D>::RefType,
334 typename TupleTraits<E>::RefType,
335 typename TupleTraits<F>::RefType,
336 typename TupleTraits<G>::RefType,
337 typename TupleTraits<H>::RefType> RefTuple;
338 typedef Tuple8<typename TupleTraits<A>::ParamType,
339 typename TupleTraits<B>::ParamType,
340 typename TupleTraits<C>::ParamType,
341 typename TupleTraits<D>::ParamType,
342 typename TupleTraits<E>::ParamType,
343 typename TupleTraits<F>::ParamType,
344 typename TupleTraits<G>::ParamType,
345 typename TupleTraits<H>::ParamType> ParamTuple;
346
347 Tuple8() {}
348 Tuple8(typename TupleTraits<A>::ParamType a,
349 typename TupleTraits<B>::ParamType b,
350 typename TupleTraits<C>::ParamType c,
351 typename TupleTraits<D>::ParamType d,
352 typename TupleTraits<E>::ParamType e,
353 typename TupleTraits<F>::ParamType f,
354 typename TupleTraits<G>::ParamType g,
355 typename TupleTraits<H>::ParamType h)
356 : a(a), b(b), c(c), d(d), e(e), f(f), g(g), h(h) {
357 }
358
359 A a;
360 B b;
361 C c;
362 D d;
363 E e;
364 F f;
365 G g;
366 H h;
367};
368
initial.commit3f4a7322008-07-27 06:49:38 +0900369// Tuple creators -------------------------------------------------------------
370//
371// Helper functions for constructing tuples while inferring the template
372// argument types.
373
374inline Tuple0 MakeTuple() {
375 return Tuple0();
376}
377
378template <class A>
379inline Tuple1<A> MakeTuple(const A& a) {
380 return Tuple1<A>(a);
381}
382
383template <class A, class B>
384inline Tuple2<A, B> MakeTuple(const A& a, const B& b) {
385 return Tuple2<A, B>(a, b);
386}
387
388template <class A, class B, class C>
389inline Tuple3<A, B, C> MakeTuple(const A& a, const B& b, const C& c) {
390 return Tuple3<A, B, C>(a, b, c);
391}
392
393template <class A, class B, class C, class D>
394inline Tuple4<A, B, C, D> MakeTuple(const A& a, const B& b, const C& c,
395 const D& d) {
396 return Tuple4<A, B, C, D>(a, b, c, d);
397}
398
399template <class A, class B, class C, class D, class E>
400inline Tuple5<A, B, C, D, E> MakeTuple(const A& a, const B& b, const C& c,
401 const D& d, const E& e) {
402 return Tuple5<A, B, C, D, E>(a, b, c, d, e);
403}
404
ojan@google.com38355092008-10-10 06:58:05 +0900405template <class A, class B, class C, class D, class E, class F>
406inline Tuple6<A, B, C, D, E, F> MakeTuple(const A& a, const B& b, const C& c,
407 const D& d, const E& e, const F& f) {
408 return Tuple6<A, B, C, D, E, F>(a, b, c, d, e, f);
409}
410
sky@google.com67c35752008-11-13 07:10:20 +0900411template <class A, class B, class C, class D, class E, class F, class G>
412inline Tuple7<A, B, C, D, E, F, G> MakeTuple(const A& a, const B& b, const C& c,
413 const D& d, const E& e, const F& f,
414 const G& g) {
415 return Tuple7<A, B, C, D, E, F, G>(a, b, c, d, e, f, g);
416}
417
phajdan.jr@chromium.org5a468fc2010-07-21 01:56:26 +0900418template <class A, class B, class C, class D, class E, class F, class G,
419 class H>
420inline Tuple8<A, B, C, D, E, F, G, H> MakeTuple(const A& a, const B& b,
421 const C& c, const D& d,
422 const E& e, const F& f,
423 const G& g, const H& h) {
424 return Tuple8<A, B, C, D, E, F, G, H>(a, b, c, d, e, f, g, h);
425}
426
initial.commit3f4a7322008-07-27 06:49:38 +0900427// The following set of helpers make what Boost refers to as "Tiers" - a tuple
428// of references.
429
430template <class A>
431inline Tuple1<A&> MakeRefTuple(A& a) {
432 return Tuple1<A&>(a);
433}
434
435template <class A, class B>
436inline Tuple2<A&, B&> MakeRefTuple(A& a, B& b) {
437 return Tuple2<A&, B&>(a, b);
438}
439
440template <class A, class B, class C>
441inline Tuple3<A&, B&, C&> MakeRefTuple(A& a, B& b, C& c) {
442 return Tuple3<A&, B&, C&>(a, b, c);
443}
444
445template <class A, class B, class C, class D>
446inline Tuple4<A&, B&, C&, D&> MakeRefTuple(A& a, B& b, C& c, D& d) {
447 return Tuple4<A&, B&, C&, D&>(a, b, c, d);
448}
449
450template <class A, class B, class C, class D, class E>
451inline Tuple5<A&, B&, C&, D&, E&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e) {
452 return Tuple5<A&, B&, C&, D&, E&>(a, b, c, d, e);
453}
454
ojan@google.com38355092008-10-10 06:58:05 +0900455template <class A, class B, class C, class D, class E, class F>
456inline Tuple6<A&, B&, C&, D&, E&, F&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e,
457 F& f) {
458 return Tuple6<A&, B&, C&, D&, E&, F&>(a, b, c, d, e, f);
459}
460
sky@google.com67c35752008-11-13 07:10:20 +0900461template <class A, class B, class C, class D, class E, class F, class G>
462inline Tuple7<A&, B&, C&, D&, E&, F&, G&> MakeRefTuple(A& a, B& b, C& c, D& d,
463 E& e, F& f, G& g) {
464 return Tuple7<A&, B&, C&, D&, E&, F&, G&>(a, b, c, d, e, f, g);
465}
466
phajdan.jr@chromium.org5a468fc2010-07-21 01:56:26 +0900467template <class A, class B, class C, class D, class E, class F, class G,
468 class H>
469inline Tuple8<A&, B&, C&, D&, E&, F&, G&, H&> MakeRefTuple(A& a, B& b, C& c,
470 D& d, E& e, F& f,
471 G& g, H& h) {
472 return Tuple8<A&, B&, C&, D&, E&, F&, G&, H&>(a, b, c, d, e, f, g, h);
473}
474
initial.commit3f4a7322008-07-27 06:49:38 +0900475// Dispatchers ----------------------------------------------------------------
476//
477// Helper functions that call the given method on an object, with the unpacked
478// tuple arguments. Notice that they all have the same number of arguments,
479// so you need only write:
480// DispatchToMethod(object, &Object::method, args);
481// This is very useful for templated dispatchers, since they don't need to know
482// what type |args| is.
483
484// Non-Static Dispatchers with no out params.
485
486template <class ObjT, class Method>
487inline void DispatchToMethod(ObjT* obj, Method method, const Tuple0& arg) {
488 (obj->*method)();
489}
490
491template <class ObjT, class Method, class A>
492inline void DispatchToMethod(ObjT* obj, Method method, const A& arg) {
493 (obj->*method)(arg);
494}
495
496template <class ObjT, class Method, class A>
497inline void DispatchToMethod(ObjT* obj, Method method, const Tuple1<A>& arg) {
498 (obj->*method)(arg.a);
499}
500
501template<class ObjT, class Method, class A, class B>
maruel@chromium.org8fe7adc2009-03-04 00:01:12 +0900502inline void DispatchToMethod(ObjT* obj,
503 Method method,
504 const Tuple2<A, B>& arg) {
initial.commit3f4a7322008-07-27 06:49:38 +0900505 (obj->*method)(arg.a, arg.b);
506}
507
508template<class ObjT, class Method, class A, class B, class C>
509inline void DispatchToMethod(ObjT* obj, Method method,
510 const Tuple3<A, B, C>& arg) {
511 (obj->*method)(arg.a, arg.b, arg.c);
512}
513
514template<class ObjT, class Method, class A, class B, class C, class D>
515inline void DispatchToMethod(ObjT* obj, Method method,
516 const Tuple4<A, B, C, D>& arg) {
517 (obj->*method)(arg.a, arg.b, arg.c, arg.d);
518}
519
520template<class ObjT, class Method, class A, class B, class C, class D, class E>
521inline void DispatchToMethod(ObjT* obj, Method method,
522 const Tuple5<A, B, C, D, E>& arg) {
523 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e);
524}
525
ojan@google.com38355092008-10-10 06:58:05 +0900526template<class ObjT, class Method, class A, class B, class C, class D, class E,
527 class F>
528inline void DispatchToMethod(ObjT* obj, Method method,
529 const Tuple6<A, B, C, D, E, F>& arg) {
530 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
531}
532
sky@google.com67c35752008-11-13 07:10:20 +0900533template<class ObjT, class Method, class A, class B, class C, class D, class E,
534 class F, class G>
535inline void DispatchToMethod(ObjT* obj, Method method,
536 const Tuple7<A, B, C, D, E, F, G>& arg) {
537 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g);
538}
539
initial.commit3f4a7322008-07-27 06:49:38 +0900540// Static Dispatchers with no out params.
541
542template <class Function>
543inline void DispatchToFunction(Function function, const Tuple0& arg) {
544 (*function)();
545}
546
547template <class Function, class A>
548inline void DispatchToFunction(Function function, const A& arg) {
549 (*function)(arg);
550}
551
552template <class Function, class A>
553inline void DispatchToFunction(Function function, const Tuple1<A>& arg) {
554 (*function)(arg.a);
555}
556
557template<class Function, class A, class B>
558inline void DispatchToFunction(Function function, const Tuple2<A, B>& arg) {
559 (*function)(arg.a, arg.b);
560}
561
562template<class Function, class A, class B, class C>
563inline void DispatchToFunction(Function function, const Tuple3<A, B, C>& arg) {
564 (*function)(arg.a, arg.b, arg.c);
565}
566
567template<class Function, class A, class B, class C, class D>
568inline void DispatchToFunction(Function function,
569 const Tuple4<A, B, C, D>& arg) {
570 (*function)(arg.a, arg.b, arg.c, arg.d);
571}
572
573template<class Function, class A, class B, class C, class D, class E>
574inline void DispatchToFunction(Function function,
575 const Tuple5<A, B, C, D, E>& arg) {
576 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e);
577}
578
ojan@google.com38355092008-10-10 06:58:05 +0900579template<class Function, class A, class B, class C, class D, class E, class F>
580inline void DispatchToFunction(Function function,
581 const Tuple6<A, B, C, D, E, F>& arg) {
582 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
583}
584
phajdan.jr@chromium.org5a468fc2010-07-21 01:56:26 +0900585template<class Function, class A, class B, class C, class D, class E, class F,
586 class G>
587inline void DispatchToFunction(Function function,
588 const Tuple7<A, B, C, D, E, F, G>& arg) {
589 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g);
590}
591
592template<class Function, class A, class B, class C, class D, class E, class F,
593 class G, class H>
594inline void DispatchToFunction(Function function,
595 const Tuple8<A, B, C, D, E, F, G, H>& arg) {
596 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g, arg.h);
597}
598
initial.commit3f4a7322008-07-27 06:49:38 +0900599// Dispatchers with 0 out param (as a Tuple0).
600
601template <class ObjT, class Method>
maruel@chromium.org8fe7adc2009-03-04 00:01:12 +0900602inline void DispatchToMethod(ObjT* obj,
603 Method method,
604 const Tuple0& arg, Tuple0*) {
initial.commit3f4a7322008-07-27 06:49:38 +0900605 (obj->*method)();
606}
607
608template <class ObjT, class Method, class A>
609inline void DispatchToMethod(ObjT* obj, Method method, const A& arg, Tuple0*) {
610 (obj->*method)(arg);
611}
612
613template <class ObjT, class Method, class A>
maruel@chromium.org8fe7adc2009-03-04 00:01:12 +0900614inline void DispatchToMethod(ObjT* obj,
615 Method method,
616 const Tuple1<A>& arg, Tuple0*) {
initial.commit3f4a7322008-07-27 06:49:38 +0900617 (obj->*method)(arg.a);
618}
619
620template<class ObjT, class Method, class A, class B>
maruel@chromium.org8fe7adc2009-03-04 00:01:12 +0900621inline void DispatchToMethod(ObjT* obj,
622 Method method,
623 const Tuple2<A, B>& arg, Tuple0*) {
initial.commit3f4a7322008-07-27 06:49:38 +0900624 (obj->*method)(arg.a, arg.b);
625}
626
627template<class ObjT, class Method, class A, class B, class C>
628inline void DispatchToMethod(ObjT* obj, Method method,
629 const Tuple3<A, B, C>& arg, Tuple0*) {
630 (obj->*method)(arg.a, arg.b, arg.c);
631}
632
633template<class ObjT, class Method, class A, class B, class C, class D>
634inline void DispatchToMethod(ObjT* obj, Method method,
635 const Tuple4<A, B, C, D>& arg, Tuple0*) {
636 (obj->*method)(arg.a, arg.b, arg.c, arg.d);
637}
638
639template<class ObjT, class Method, class A, class B, class C, class D, class E>
640inline void DispatchToMethod(ObjT* obj, Method method,
641 const Tuple5<A, B, C, D, E>& arg, Tuple0*) {
642 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e);
643}
644
ojan@google.com38355092008-10-10 06:58:05 +0900645template<class ObjT, class Method, class A, class B, class C, class D, class E,
646 class F>
647inline void DispatchToMethod(ObjT* obj, Method method,
648 const Tuple6<A, B, C, D, E, F>& arg, Tuple0*) {
649 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
650}
651
initial.commit3f4a7322008-07-27 06:49:38 +0900652// Dispatchers with 1 out param.
653
654template<class ObjT, class Method,
655 class OutA>
656inline void DispatchToMethod(ObjT* obj, Method method,
657 const Tuple0& in,
658 Tuple1<OutA>* out) {
659 (obj->*method)(&out->a);
660}
661
662template<class ObjT, class Method, class InA,
663 class OutA>
664inline void DispatchToMethod(ObjT* obj, Method method,
665 const InA& in,
666 Tuple1<OutA>* out) {
667 (obj->*method)(in, &out->a);
668}
669
670template<class ObjT, class Method, class InA,
671 class OutA>
672inline void DispatchToMethod(ObjT* obj, Method method,
673 const Tuple1<InA>& in,
674 Tuple1<OutA>* out) {
675 (obj->*method)(in.a, &out->a);
676}
677
678template<class ObjT, class Method, class InA, class InB,
679 class OutA>
680inline void DispatchToMethod(ObjT* obj, Method method,
681 const Tuple2<InA, InB>& in,
682 Tuple1<OutA>* out) {
683 (obj->*method)(in.a, in.b, &out->a);
684}
685
686template<class ObjT, class Method, class InA, class InB, class InC,
687 class OutA>
688inline void DispatchToMethod(ObjT* obj, Method method,
689 const Tuple3<InA, InB, InC>& in,
690 Tuple1<OutA>* out) {
691 (obj->*method)(in.a, in.b, in.c, &out->a);
692}
693
694template<class ObjT, class Method, class InA, class InB, class InC, class InD,
695 class OutA>
696inline void DispatchToMethod(ObjT* obj, Method method,
697 const Tuple4<InA, InB, InC, InD>& in,
698 Tuple1<OutA>* out) {
699 (obj->*method)(in.a, in.b, in.c, in.d, &out->a);
700}
701
erg@google.combf6ce9f2010-01-27 08:08:02 +0900702template<class ObjT, class Method, class InA, class InB, class InC, class InD,
703 class InE, class OutA>
initial.commit3f4a7322008-07-27 06:49:38 +0900704inline void DispatchToMethod(ObjT* obj, Method method,
705 const Tuple5<InA, InB, InC, InD, InE>& in,
706 Tuple1<OutA>* out) {
707 (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a);
708}
709
ojan@google.com38355092008-10-10 06:58:05 +0900710template<class ObjT, class Method,
711 class InA, class InB, class InC, class InD, class InE, class InF,
712 class OutA>
713inline void DispatchToMethod(ObjT* obj, Method method,
714 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
715 Tuple1<OutA>* out) {
716 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a);
717}
718
initial.commit3f4a7322008-07-27 06:49:38 +0900719// Dispatchers with 2 out params.
720
721template<class ObjT, class Method,
722 class OutA, class OutB>
723inline void DispatchToMethod(ObjT* obj, Method method,
724 const Tuple0& in,
725 Tuple2<OutA, OutB>* out) {
726 (obj->*method)(&out->a, &out->b);
727}
728
729template<class ObjT, class Method, class InA,
730 class OutA, class OutB>
731inline void DispatchToMethod(ObjT* obj, Method method,
732 const InA& in,
733 Tuple2<OutA, OutB>* out) {
734 (obj->*method)(in, &out->a, &out->b);
735}
736
737template<class ObjT, class Method, class InA,
738 class OutA, class OutB>
739inline void DispatchToMethod(ObjT* obj, Method method,
740 const Tuple1<InA>& in,
741 Tuple2<OutA, OutB>* out) {
742 (obj->*method)(in.a, &out->a, &out->b);
743}
744
745template<class ObjT, class Method, class InA, class InB,
746 class OutA, class OutB>
747inline void DispatchToMethod(ObjT* obj, Method method,
748 const Tuple2<InA, InB>& in,
749 Tuple2<OutA, OutB>* out) {
750 (obj->*method)(in.a, in.b, &out->a, &out->b);
751}
752
753template<class ObjT, class Method, class InA, class InB, class InC,
754 class OutA, class OutB>
755inline void DispatchToMethod(ObjT* obj, Method method,
756 const Tuple3<InA, InB, InC>& in,
757 Tuple2<OutA, OutB>* out) {
758 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b);
759}
760
761template<class ObjT, class Method, class InA, class InB, class InC, class InD,
762 class OutA, class OutB>
763inline void DispatchToMethod(ObjT* obj, Method method,
764 const Tuple4<InA, InB, InC, InD>& in,
765 Tuple2<OutA, OutB>* out) {
766 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b);
767}
768
769template<class ObjT, class Method,
770 class InA, class InB, class InC, class InD, class InE,
771 class OutA, class OutB>
772inline void DispatchToMethod(ObjT* obj, Method method,
773 const Tuple5<InA, InB, InC, InD, InE>& in,
774 Tuple2<OutA, OutB>* out) {
775 (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b);
776}
777
ojan@google.com38355092008-10-10 06:58:05 +0900778template<class ObjT, class Method,
779 class InA, class InB, class InC, class InD, class InE, class InF,
780 class OutA, class OutB>
781inline void DispatchToMethod(ObjT* obj, Method method,
782 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
783 Tuple2<OutA, OutB>* out) {
784 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b);
785}
786
initial.commit3f4a7322008-07-27 06:49:38 +0900787// Dispatchers with 3 out params.
788
789template<class ObjT, class Method,
790 class OutA, class OutB, class OutC>
791inline void DispatchToMethod(ObjT* obj, Method method,
792 const Tuple0& in,
793 Tuple3<OutA, OutB, OutC>* out) {
794 (obj->*method)(&out->a, &out->b, &out->c);
795}
796
797template<class ObjT, class Method, class InA,
798 class OutA, class OutB, class OutC>
799inline void DispatchToMethod(ObjT* obj, Method method,
800 const InA& in,
801 Tuple3<OutA, OutB, OutC>* out) {
802 (obj->*method)(in, &out->a, &out->b, &out->c);
803}
804
805template<class ObjT, class Method, class InA,
806 class OutA, class OutB, class OutC>
807inline void DispatchToMethod(ObjT* obj, Method method,
808 const Tuple1<InA>& in,
809 Tuple3<OutA, OutB, OutC>* out) {
810 (obj->*method)(in.a, &out->a, &out->b, &out->c);
811}
812
813template<class ObjT, class Method, class InA, class InB,
814 class OutA, class OutB, class OutC>
815inline void DispatchToMethod(ObjT* obj, Method method,
816 const Tuple2<InA, InB>& in,
817 Tuple3<OutA, OutB, OutC>* out) {
818 (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c);
819}
820
821template<class ObjT, class Method, class InA, class InB, class InC,
822 class OutA, class OutB, class OutC>
823inline void DispatchToMethod(ObjT* obj, Method method,
824 const Tuple3<InA, InB, InC>& in,
825 Tuple3<OutA, OutB, OutC>* out) {
826 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c);
827}
828
829template<class ObjT, class Method, class InA, class InB, class InC, class InD,
830 class OutA, class OutB, class OutC>
831inline void DispatchToMethod(ObjT* obj, Method method,
832 const Tuple4<InA, InB, InC, InD>& in,
833 Tuple3<OutA, OutB, OutC>* out) {
834 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c);
835}
836
837template<class ObjT, class Method,
838 class InA, class InB, class InC, class InD, class InE,
839 class OutA, class OutB, class OutC>
840inline void DispatchToMethod(ObjT* obj, Method method,
841 const Tuple5<InA, InB, InC, InD, InE>& in,
842 Tuple3<OutA, OutB, OutC>* out) {
843 (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b, &out->c);
844}
845
ojan@google.com38355092008-10-10 06:58:05 +0900846template<class ObjT, class Method,
847 class InA, class InB, class InC, class InD, class InE, class InF,
848 class OutA, class OutB, class OutC>
849inline void DispatchToMethod(ObjT* obj, Method method,
850 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
851 Tuple3<OutA, OutB, OutC>* out) {
852 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b, &out->c);
853}
854
initial.commit3f4a7322008-07-27 06:49:38 +0900855// Dispatchers with 4 out params.
856
857template<class ObjT, class Method,
858 class OutA, class OutB, class OutC, class OutD>
859inline void DispatchToMethod(ObjT* obj, Method method,
860 const Tuple0& in,
861 Tuple4<OutA, OutB, OutC, OutD>* out) {
862 (obj->*method)(&out->a, &out->b, &out->c, &out->d);
863}
864
865template<class ObjT, class Method, class InA,
866 class OutA, class OutB, class OutC, class OutD>
867inline void DispatchToMethod(ObjT* obj, Method method,
868 const InA& in,
869 Tuple4<OutA, OutB, OutC, OutD>* out) {
870 (obj->*method)(in, &out->a, &out->b, &out->c, &out->d);
871}
872
873template<class ObjT, class Method, class InA,
874 class OutA, class OutB, class OutC, class OutD>
875inline void DispatchToMethod(ObjT* obj, Method method,
876 const Tuple1<InA>& in,
877 Tuple4<OutA, OutB, OutC, OutD>* out) {
878 (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d);
879}
880
881template<class ObjT, class Method, class InA, class InB,
882 class OutA, class OutB, class OutC, class OutD>
883inline void DispatchToMethod(ObjT* obj, Method method,
884 const Tuple2<InA, InB>& in,
885 Tuple4<OutA, OutB, OutC, OutD>* out) {
886 (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d);
887}
888
889template<class ObjT, class Method, class InA, class InB, class InC,
890 class OutA, class OutB, class OutC, class OutD>
891inline void DispatchToMethod(ObjT* obj, Method method,
892 const Tuple3<InA, InB, InC>& in,
893 Tuple4<OutA, OutB, OutC, OutD>* out) {
894 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d);
895}
896
897template<class ObjT, class Method, class InA, class InB, class InC, class InD,
898 class OutA, class OutB, class OutC, class OutD>
899inline void DispatchToMethod(ObjT* obj, Method method,
900 const Tuple4<InA, InB, InC, InD>& in,
901 Tuple4<OutA, OutB, OutC, OutD>* out) {
902 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d);
903}
904
905template<class ObjT, class Method,
906 class InA, class InB, class InC, class InD, class InE,
907 class OutA, class OutB, class OutC, class OutD>
908inline void DispatchToMethod(ObjT* obj, Method method,
909 const Tuple5<InA, InB, InC, InD, InE>& in,
910 Tuple4<OutA, OutB, OutC, OutD>* out) {
911 (obj->*method)(in.a, in.b, in.c, in.d, in.e,
912 &out->a, &out->b, &out->c, &out->d);
913}
914
ojan@google.com38355092008-10-10 06:58:05 +0900915template<class ObjT, class Method,
916 class InA, class InB, class InC, class InD, class InE, class InF,
917 class OutA, class OutB, class OutC, class OutD>
918inline void DispatchToMethod(ObjT* obj, Method method,
919 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
920 Tuple4<OutA, OutB, OutC, OutD>* out) {
921 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f,
922 &out->a, &out->b, &out->c, &out->d);
923}
924
initial.commit3f4a7322008-07-27 06:49:38 +0900925// Dispatchers with 5 out params.
926
927template<class ObjT, class Method,
928 class OutA, class OutB, class OutC, class OutD, class OutE>
929inline void DispatchToMethod(ObjT* obj, Method method,
930 const Tuple0& in,
931 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
932 (obj->*method)(&out->a, &out->b, &out->c, &out->d, &out->e);
933}
934
935template<class ObjT, class Method, class InA,
936 class OutA, class OutB, class OutC, class OutD, class OutE>
937inline void DispatchToMethod(ObjT* obj, Method method,
938 const InA& in,
939 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
940 (obj->*method)(in, &out->a, &out->b, &out->c, &out->d, &out->e);
941}
942
943template<class ObjT, class Method, class InA,
944 class OutA, class OutB, class OutC, class OutD, class OutE>
945inline void DispatchToMethod(ObjT* obj, Method method,
946 const Tuple1<InA>& in,
947 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
948 (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d, &out->e);
949}
950
951template<class ObjT, class Method, class InA, class InB,
952 class OutA, class OutB, class OutC, class OutD, class OutE>
953inline void DispatchToMethod(ObjT* obj, Method method,
954 const Tuple2<InA, InB>& in,
955 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
956 (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d, &out->e);
957}
958
959template<class ObjT, class Method, class InA, class InB, class InC,
960 class OutA, class OutB, class OutC, class OutD, class OutE>
961inline void DispatchToMethod(ObjT* obj, Method method,
962 const Tuple3<InA, InB, InC>& in,
963 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
964 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d, &out->e);
965}
966
967template<class ObjT, class Method, class InA, class InB, class InC, class InD,
968 class OutA, class OutB, class OutC, class OutD, class OutE>
969inline void DispatchToMethod(ObjT* obj, Method method,
970 const Tuple4<InA, InB, InC, InD>& in,
971 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
972 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d,
973 &out->e);
974}
975
976template<class ObjT, class Method,
977 class InA, class InB, class InC, class InD, class InE,
978 class OutA, class OutB, class OutC, class OutD, class OutE>
979inline void DispatchToMethod(ObjT* obj, Method method,
980 const Tuple5<InA, InB, InC, InD, InE>& in,
981 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
982 (obj->*method)(in.a, in.b, in.c, in.d, in.e,
983 &out->a, &out->b, &out->c, &out->d, &out->e);
984}
985
ojan@google.com38355092008-10-10 06:58:05 +0900986template<class ObjT, class Method,
987 class InA, class InB, class InC, class InD, class InE, class InF,
988 class OutA, class OutB, class OutC, class OutD, class OutE>
989inline void DispatchToMethod(ObjT* obj, Method method,
990 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
991 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
992 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f,
993 &out->a, &out->b, &out->c, &out->d, &out->e);
994}
995
initial.commit3f4a7322008-07-27 06:49:38 +0900996#endif // BASE_TUPLE_H__