license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | |
deanm@google.com | 96aac0a | 2008-08-25 22:42:07 +0900 | [diff] [blame] | 5 | // A Tuple is a generic templatized container, similar in concept to std::pair. |
ojan@google.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 6 | // There are classes Tuple0 to Tuple6, cooresponding to the number of elements |
| 7 | // it contains. The convenient MakeTuple() function takes 0 to 6 arguments, |
deanm@google.com | 96aac0a | 2008-08-25 22:42:07 +0900 | [diff] [blame] | 8 | // 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 29 | #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 | |
| 40 | template <class P> |
| 41 | struct TupleTraits { |
| 42 | typedef P ValueType; |
| 43 | typedef P& RefType; |
| 44 | typedef const P& ParamType; |
| 45 | }; |
| 46 | |
| 47 | template <class P> |
| 48 | struct 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.com | ff4b729 | 2008-08-21 19:58:08 +0900 | [diff] [blame] | 61 | // 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 64 | // 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 | |
| 68 | struct Tuple0 { |
| 69 | typedef Tuple0 ValueTuple; |
| 70 | typedef Tuple0 RefTuple; |
mpcomplete@google.com | a74ef82 | 2009-05-21 03:24:14 +0900 | [diff] [blame] | 71 | typedef Tuple0 ParamTuple; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | template <class A> |
| 75 | struct 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.com | a74ef82 | 2009-05-21 03:24:14 +0900 | [diff] [blame] | 80 | typedef Tuple1<typename TupleTraits<A>::ParamType> ParamTuple; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 81 | |
| 82 | Tuple1() {} |
| 83 | explicit Tuple1(typename TupleTraits<A>::ParamType a) : a(a) {} |
| 84 | |
| 85 | A a; |
| 86 | }; |
| 87 | |
| 88 | template <class A, class B> |
| 89 | struct 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.com | a74ef82 | 2009-05-21 03:24:14 +0900 | [diff] [blame] | 97 | typedef Tuple2<typename TupleTraits<A>::ParamType, |
| 98 | typename TupleTraits<B>::ParamType> ParamTuple; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 99 | |
| 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 | |
| 110 | template <class A, class B, class C> |
| 111 | struct 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.com | a74ef82 | 2009-05-21 03:24:14 +0900 | [diff] [blame] | 122 | typedef Tuple3<typename TupleTraits<A>::ParamType, |
| 123 | typename TupleTraits<B>::ParamType, |
| 124 | typename TupleTraits<C>::ParamType> ParamTuple; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 125 | |
| 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 | |
| 138 | template <class A, class B, class C, class D> |
| 139 | struct 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.com | a74ef82 | 2009-05-21 03:24:14 +0900 | [diff] [blame] | 153 | typedef Tuple4<typename TupleTraits<A>::ParamType, |
| 154 | typename TupleTraits<B>::ParamType, |
| 155 | typename TupleTraits<C>::ParamType, |
| 156 | typename TupleTraits<D>::ParamType> ParamTuple; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 157 | |
| 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 | |
| 172 | template <class A, class B, class C, class D, class E> |
| 173 | struct Tuple5 { |
erg@google.com | bf6ce9f | 2010-01-27 08:08:02 +0900 | [diff] [blame] | 174 | public: |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 175 | 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.com | a74ef82 | 2009-05-21 03:24:14 +0900 | [diff] [blame] | 190 | 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 195 | |
| 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 212 | template <class A, class B, class C, class D, class E, class F> |
| 213 | struct Tuple6 { |
erg@google.com | bf6ce9f | 2010-01-27 08:08:02 +0900 | [diff] [blame] | 214 | public: |
ojan@google.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 215 | 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.com | a74ef82 | 2009-05-21 03:24:14 +0900 | [diff] [blame] | 233 | 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 239 | |
| 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.com | 67c3575 | 2008-11-13 07:10:20 +0900 | [diff] [blame] | 258 | template <class A, class B, class C, class D, class E, class F, class G> |
| 259 | struct Tuple7 { |
erg@google.com | bf6ce9f | 2010-01-27 08:08:02 +0900 | [diff] [blame] | 260 | public: |
sky@google.com | 67c3575 | 2008-11-13 07:10:20 +0900 | [diff] [blame] | 261 | 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.com | a74ef82 | 2009-05-21 03:24:14 +0900 | [diff] [blame] | 282 | 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.com | 67c3575 | 2008-11-13 07:10:20 +0900 | [diff] [blame] | 289 | |
| 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.org | 5a468fc | 2010-07-21 01:56:26 +0900 | [diff] [blame] | 310 | template <class A, class B, class C, class D, class E, class F, class G, |
| 311 | class H> |
| 312 | struct 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 369 | // Tuple creators ------------------------------------------------------------- |
| 370 | // |
| 371 | // Helper functions for constructing tuples while inferring the template |
| 372 | // argument types. |
| 373 | |
| 374 | inline Tuple0 MakeTuple() { |
| 375 | return Tuple0(); |
| 376 | } |
| 377 | |
| 378 | template <class A> |
| 379 | inline Tuple1<A> MakeTuple(const A& a) { |
| 380 | return Tuple1<A>(a); |
| 381 | } |
| 382 | |
| 383 | template <class A, class B> |
| 384 | inline Tuple2<A, B> MakeTuple(const A& a, const B& b) { |
| 385 | return Tuple2<A, B>(a, b); |
| 386 | } |
| 387 | |
| 388 | template <class A, class B, class C> |
| 389 | inline 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 | |
| 393 | template <class A, class B, class C, class D> |
| 394 | inline 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 | |
| 399 | template <class A, class B, class C, class D, class E> |
| 400 | inline 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 405 | template <class A, class B, class C, class D, class E, class F> |
| 406 | inline 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.com | 67c3575 | 2008-11-13 07:10:20 +0900 | [diff] [blame] | 411 | template <class A, class B, class C, class D, class E, class F, class G> |
| 412 | inline 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.org | 5a468fc | 2010-07-21 01:56:26 +0900 | [diff] [blame] | 418 | template <class A, class B, class C, class D, class E, class F, class G, |
| 419 | class H> |
| 420 | inline 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 427 | // The following set of helpers make what Boost refers to as "Tiers" - a tuple |
| 428 | // of references. |
| 429 | |
| 430 | template <class A> |
| 431 | inline Tuple1<A&> MakeRefTuple(A& a) { |
| 432 | return Tuple1<A&>(a); |
| 433 | } |
| 434 | |
| 435 | template <class A, class B> |
| 436 | inline Tuple2<A&, B&> MakeRefTuple(A& a, B& b) { |
| 437 | return Tuple2<A&, B&>(a, b); |
| 438 | } |
| 439 | |
| 440 | template <class A, class B, class C> |
| 441 | inline Tuple3<A&, B&, C&> MakeRefTuple(A& a, B& b, C& c) { |
| 442 | return Tuple3<A&, B&, C&>(a, b, c); |
| 443 | } |
| 444 | |
| 445 | template <class A, class B, class C, class D> |
| 446 | inline 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 | |
| 450 | template <class A, class B, class C, class D, class E> |
| 451 | inline 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 455 | template <class A, class B, class C, class D, class E, class F> |
| 456 | inline 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.com | 67c3575 | 2008-11-13 07:10:20 +0900 | [diff] [blame] | 461 | template <class A, class B, class C, class D, class E, class F, class G> |
| 462 | inline 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.org | 5a468fc | 2010-07-21 01:56:26 +0900 | [diff] [blame] | 467 | template <class A, class B, class C, class D, class E, class F, class G, |
| 468 | class H> |
| 469 | inline 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 475 | // 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 | |
| 486 | template <class ObjT, class Method> |
| 487 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple0& arg) { |
| 488 | (obj->*method)(); |
| 489 | } |
| 490 | |
| 491 | template <class ObjT, class Method, class A> |
| 492 | inline void DispatchToMethod(ObjT* obj, Method method, const A& arg) { |
| 493 | (obj->*method)(arg); |
| 494 | } |
| 495 | |
| 496 | template <class ObjT, class Method, class A> |
| 497 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple1<A>& arg) { |
| 498 | (obj->*method)(arg.a); |
| 499 | } |
| 500 | |
| 501 | template<class ObjT, class Method, class A, class B> |
maruel@chromium.org | 8fe7adc | 2009-03-04 00:01:12 +0900 | [diff] [blame] | 502 | inline void DispatchToMethod(ObjT* obj, |
| 503 | Method method, |
| 504 | const Tuple2<A, B>& arg) { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 505 | (obj->*method)(arg.a, arg.b); |
| 506 | } |
| 507 | |
| 508 | template<class ObjT, class Method, class A, class B, class C> |
| 509 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 510 | const Tuple3<A, B, C>& arg) { |
| 511 | (obj->*method)(arg.a, arg.b, arg.c); |
| 512 | } |
| 513 | |
| 514 | template<class ObjT, class Method, class A, class B, class C, class D> |
| 515 | inline 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 | |
| 520 | template<class ObjT, class Method, class A, class B, class C, class D, class E> |
| 521 | inline 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 526 | template<class ObjT, class Method, class A, class B, class C, class D, class E, |
| 527 | class F> |
| 528 | inline 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.com | 67c3575 | 2008-11-13 07:10:20 +0900 | [diff] [blame] | 533 | template<class ObjT, class Method, class A, class B, class C, class D, class E, |
| 534 | class F, class G> |
| 535 | inline 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 540 | // Static Dispatchers with no out params. |
| 541 | |
| 542 | template <class Function> |
| 543 | inline void DispatchToFunction(Function function, const Tuple0& arg) { |
| 544 | (*function)(); |
| 545 | } |
| 546 | |
| 547 | template <class Function, class A> |
| 548 | inline void DispatchToFunction(Function function, const A& arg) { |
| 549 | (*function)(arg); |
| 550 | } |
| 551 | |
| 552 | template <class Function, class A> |
| 553 | inline void DispatchToFunction(Function function, const Tuple1<A>& arg) { |
| 554 | (*function)(arg.a); |
| 555 | } |
| 556 | |
| 557 | template<class Function, class A, class B> |
| 558 | inline void DispatchToFunction(Function function, const Tuple2<A, B>& arg) { |
| 559 | (*function)(arg.a, arg.b); |
| 560 | } |
| 561 | |
| 562 | template<class Function, class A, class B, class C> |
| 563 | inline void DispatchToFunction(Function function, const Tuple3<A, B, C>& arg) { |
| 564 | (*function)(arg.a, arg.b, arg.c); |
| 565 | } |
| 566 | |
| 567 | template<class Function, class A, class B, class C, class D> |
| 568 | inline void DispatchToFunction(Function function, |
| 569 | const Tuple4<A, B, C, D>& arg) { |
| 570 | (*function)(arg.a, arg.b, arg.c, arg.d); |
| 571 | } |
| 572 | |
| 573 | template<class Function, class A, class B, class C, class D, class E> |
| 574 | inline 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 579 | template<class Function, class A, class B, class C, class D, class E, class F> |
| 580 | inline 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.org | 5a468fc | 2010-07-21 01:56:26 +0900 | [diff] [blame] | 585 | template<class Function, class A, class B, class C, class D, class E, class F, |
| 586 | class G> |
| 587 | inline 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 | |
| 592 | template<class Function, class A, class B, class C, class D, class E, class F, |
| 593 | class G, class H> |
| 594 | inline 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 599 | // Dispatchers with 0 out param (as a Tuple0). |
| 600 | |
| 601 | template <class ObjT, class Method> |
maruel@chromium.org | 8fe7adc | 2009-03-04 00:01:12 +0900 | [diff] [blame] | 602 | inline void DispatchToMethod(ObjT* obj, |
| 603 | Method method, |
| 604 | const Tuple0& arg, Tuple0*) { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 605 | (obj->*method)(); |
| 606 | } |
| 607 | |
| 608 | template <class ObjT, class Method, class A> |
| 609 | inline void DispatchToMethod(ObjT* obj, Method method, const A& arg, Tuple0*) { |
| 610 | (obj->*method)(arg); |
| 611 | } |
| 612 | |
| 613 | template <class ObjT, class Method, class A> |
maruel@chromium.org | 8fe7adc | 2009-03-04 00:01:12 +0900 | [diff] [blame] | 614 | inline void DispatchToMethod(ObjT* obj, |
| 615 | Method method, |
| 616 | const Tuple1<A>& arg, Tuple0*) { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 617 | (obj->*method)(arg.a); |
| 618 | } |
| 619 | |
| 620 | template<class ObjT, class Method, class A, class B> |
maruel@chromium.org | 8fe7adc | 2009-03-04 00:01:12 +0900 | [diff] [blame] | 621 | inline void DispatchToMethod(ObjT* obj, |
| 622 | Method method, |
| 623 | const Tuple2<A, B>& arg, Tuple0*) { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 624 | (obj->*method)(arg.a, arg.b); |
| 625 | } |
| 626 | |
| 627 | template<class ObjT, class Method, class A, class B, class C> |
| 628 | inline 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 | |
| 633 | template<class ObjT, class Method, class A, class B, class C, class D> |
| 634 | inline 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 | |
| 639 | template<class ObjT, class Method, class A, class B, class C, class D, class E> |
| 640 | inline 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 645 | template<class ObjT, class Method, class A, class B, class C, class D, class E, |
| 646 | class F> |
| 647 | inline 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 652 | // Dispatchers with 1 out param. |
| 653 | |
| 654 | template<class ObjT, class Method, |
| 655 | class OutA> |
| 656 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 657 | const Tuple0& in, |
| 658 | Tuple1<OutA>* out) { |
| 659 | (obj->*method)(&out->a); |
| 660 | } |
| 661 | |
| 662 | template<class ObjT, class Method, class InA, |
| 663 | class OutA> |
| 664 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 665 | const InA& in, |
| 666 | Tuple1<OutA>* out) { |
| 667 | (obj->*method)(in, &out->a); |
| 668 | } |
| 669 | |
| 670 | template<class ObjT, class Method, class InA, |
| 671 | class OutA> |
| 672 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 673 | const Tuple1<InA>& in, |
| 674 | Tuple1<OutA>* out) { |
| 675 | (obj->*method)(in.a, &out->a); |
| 676 | } |
| 677 | |
| 678 | template<class ObjT, class Method, class InA, class InB, |
| 679 | class OutA> |
| 680 | inline 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 | |
| 686 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 687 | class OutA> |
| 688 | inline 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 | |
| 694 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 695 | class OutA> |
| 696 | inline 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.com | bf6ce9f | 2010-01-27 08:08:02 +0900 | [diff] [blame] | 702 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 703 | class InE, class OutA> |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 704 | inline 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 710 | template<class ObjT, class Method, |
| 711 | class InA, class InB, class InC, class InD, class InE, class InF, |
| 712 | class OutA> |
| 713 | inline 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 719 | // Dispatchers with 2 out params. |
| 720 | |
| 721 | template<class ObjT, class Method, |
| 722 | class OutA, class OutB> |
| 723 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 724 | const Tuple0& in, |
| 725 | Tuple2<OutA, OutB>* out) { |
| 726 | (obj->*method)(&out->a, &out->b); |
| 727 | } |
| 728 | |
| 729 | template<class ObjT, class Method, class InA, |
| 730 | class OutA, class OutB> |
| 731 | inline 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 | |
| 737 | template<class ObjT, class Method, class InA, |
| 738 | class OutA, class OutB> |
| 739 | inline 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 | |
| 745 | template<class ObjT, class Method, class InA, class InB, |
| 746 | class OutA, class OutB> |
| 747 | inline 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 | |
| 753 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 754 | class OutA, class OutB> |
| 755 | inline 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 | |
| 761 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 762 | class OutA, class OutB> |
| 763 | inline 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 | |
| 769 | template<class ObjT, class Method, |
| 770 | class InA, class InB, class InC, class InD, class InE, |
| 771 | class OutA, class OutB> |
| 772 | inline 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 778 | template<class ObjT, class Method, |
| 779 | class InA, class InB, class InC, class InD, class InE, class InF, |
| 780 | class OutA, class OutB> |
| 781 | inline 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 787 | // Dispatchers with 3 out params. |
| 788 | |
| 789 | template<class ObjT, class Method, |
| 790 | class OutA, class OutB, class OutC> |
| 791 | inline 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 | |
| 797 | template<class ObjT, class Method, class InA, |
| 798 | class OutA, class OutB, class OutC> |
| 799 | inline 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 | |
| 805 | template<class ObjT, class Method, class InA, |
| 806 | class OutA, class OutB, class OutC> |
| 807 | inline 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 | |
| 813 | template<class ObjT, class Method, class InA, class InB, |
| 814 | class OutA, class OutB, class OutC> |
| 815 | inline 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 | |
| 821 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 822 | class OutA, class OutB, class OutC> |
| 823 | inline 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 | |
| 829 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 830 | class OutA, class OutB, class OutC> |
| 831 | inline 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 | |
| 837 | template<class ObjT, class Method, |
| 838 | class InA, class InB, class InC, class InD, class InE, |
| 839 | class OutA, class OutB, class OutC> |
| 840 | inline 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 846 | template<class ObjT, class Method, |
| 847 | class InA, class InB, class InC, class InD, class InE, class InF, |
| 848 | class OutA, class OutB, class OutC> |
| 849 | inline 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 855 | // Dispatchers with 4 out params. |
| 856 | |
| 857 | template<class ObjT, class Method, |
| 858 | class OutA, class OutB, class OutC, class OutD> |
| 859 | inline 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 | |
| 865 | template<class ObjT, class Method, class InA, |
| 866 | class OutA, class OutB, class OutC, class OutD> |
| 867 | inline 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 | |
| 873 | template<class ObjT, class Method, class InA, |
| 874 | class OutA, class OutB, class OutC, class OutD> |
| 875 | inline 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 | |
| 881 | template<class ObjT, class Method, class InA, class InB, |
| 882 | class OutA, class OutB, class OutC, class OutD> |
| 883 | inline 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 | |
| 889 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 890 | class OutA, class OutB, class OutC, class OutD> |
| 891 | inline 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 | |
| 897 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 898 | class OutA, class OutB, class OutC, class OutD> |
| 899 | inline 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 | |
| 905 | template<class ObjT, class Method, |
| 906 | class InA, class InB, class InC, class InD, class InE, |
| 907 | class OutA, class OutB, class OutC, class OutD> |
| 908 | inline 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 915 | template<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> |
| 918 | inline 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 925 | // Dispatchers with 5 out params. |
| 926 | |
| 927 | template<class ObjT, class Method, |
| 928 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 929 | inline 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 | |
| 935 | template<class ObjT, class Method, class InA, |
| 936 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 937 | inline 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 | |
| 943 | template<class ObjT, class Method, class InA, |
| 944 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 945 | inline 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 | |
| 951 | template<class ObjT, class Method, class InA, class InB, |
| 952 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 953 | inline 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 | |
| 959 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 960 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 961 | inline 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 | |
| 967 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 968 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 969 | inline 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 | |
| 976 | template<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> |
| 979 | inline 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 986 | template<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> |
| 989 | inline 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 996 | #endif // BASE_TUPLE_H__ |