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__ |
thakis@chromium.org | 01d1452 | 2010-07-27 08:08:24 +0900 | [diff] [blame] | 31 | #pragma once |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 32 | |
oshima@chromium.org | 061e50f | 2010-12-02 09:11:40 +0900 | [diff] [blame^] | 33 | #if defined(OS_CHROMEOS) |
| 34 | // To troubleshoot crosbug.com/7327. |
| 35 | #include "base/logging.h" |
| 36 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 37 | // 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 | |
| 45 | template <class P> |
| 46 | struct TupleTraits { |
| 47 | typedef P ValueType; |
| 48 | typedef P& RefType; |
| 49 | typedef const P& ParamType; |
| 50 | }; |
| 51 | |
| 52 | template <class P> |
| 53 | struct TupleTraits<P&> { |
| 54 | typedef P ValueType; |
| 55 | typedef P& RefType; |
| 56 | typedef P& ParamType; |
| 57 | }; |
| 58 | |
erg@google.com | e6ffcb5 | 2010-08-18 03:38:24 +0900 | [diff] [blame] | 59 | template <class P> |
| 60 | struct TupleTypes { }; |
| 61 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 62 | // 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.com | ff4b729 | 2008-08-21 19:58:08 +0900 | [diff] [blame] | 69 | // 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 72 | // 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 | |
| 76 | struct Tuple0 { |
| 77 | typedef Tuple0 ValueTuple; |
| 78 | typedef Tuple0 RefTuple; |
mpcomplete@google.com | a74ef82 | 2009-05-21 03:24:14 +0900 | [diff] [blame] | 79 | typedef Tuple0 ParamTuple; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | template <class A> |
| 83 | struct Tuple1 { |
| 84 | public: |
| 85 | typedef A TypeA; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 86 | |
| 87 | Tuple1() {} |
| 88 | explicit Tuple1(typename TupleTraits<A>::ParamType a) : a(a) {} |
| 89 | |
| 90 | A a; |
| 91 | }; |
| 92 | |
| 93 | template <class A, class B> |
| 94 | struct Tuple2 { |
| 95 | public: |
| 96 | typedef A TypeA; |
| 97 | typedef B TypeB; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 98 | |
| 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 | |
| 109 | template <class A, class B, class C> |
| 110 | struct Tuple3 { |
| 111 | public: |
| 112 | typedef A TypeA; |
| 113 | typedef B TypeB; |
| 114 | typedef C TypeC; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 115 | |
| 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 | |
| 128 | template <class A, class B, class C, class D> |
| 129 | struct Tuple4 { |
| 130 | public: |
| 131 | typedef A TypeA; |
| 132 | typedef B TypeB; |
| 133 | typedef C TypeC; |
| 134 | typedef D TypeD; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 135 | |
| 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 | |
| 150 | template <class A, class B, class C, class D, class E> |
| 151 | struct Tuple5 { |
erg@google.com | bf6ce9f | 2010-01-27 08:08:02 +0900 | [diff] [blame] | 152 | public: |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 153 | typedef A TypeA; |
| 154 | typedef B TypeB; |
| 155 | typedef C TypeC; |
| 156 | typedef D TypeD; |
| 157 | typedef E TypeE; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 158 | |
| 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 175 | template <class A, class B, class C, class D, class E, class F> |
| 176 | struct Tuple6 { |
erg@google.com | bf6ce9f | 2010-01-27 08:08:02 +0900 | [diff] [blame] | 177 | public: |
ojan@google.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 178 | 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 184 | |
| 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.com | 67c3575 | 2008-11-13 07:10:20 +0900 | [diff] [blame] | 203 | template <class A, class B, class C, class D, class E, class F, class G> |
| 204 | struct Tuple7 { |
erg@google.com | bf6ce9f | 2010-01-27 08:08:02 +0900 | [diff] [blame] | 205 | public: |
sky@google.com | 67c3575 | 2008-11-13 07:10:20 +0900 | [diff] [blame] | 206 | 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.com | 67c3575 | 2008-11-13 07:10:20 +0900 | [diff] [blame] | 213 | |
| 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.org | 5a468fc | 2010-07-21 01:56:26 +0900 | [diff] [blame] | 234 | template <class A, class B, class C, class D, class E, class F, class G, |
| 235 | class H> |
| 236 | struct 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.org | 5a468fc | 2010-07-21 01:56:26 +0900 | [diff] [blame] | 246 | |
| 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.com | e6ffcb5 | 2010-08-18 03:38:24 +0900 | [diff] [blame] | 269 | // 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 | |
| 274 | template <> |
| 275 | struct TupleTypes< Tuple0 > { |
| 276 | typedef Tuple0 ValueTuple; |
| 277 | typedef Tuple0 RefTuple; |
| 278 | typedef Tuple0 ParamTuple; |
| 279 | }; |
| 280 | |
| 281 | template <class A> |
| 282 | struct 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 | |
| 288 | template <class A, class B> |
| 289 | struct TupleTypes< Tuple2<A, B> > { |
| 290 | typedef Tuple2<typename TupleTraits<A>::ValueType, |
| 291 | typename TupleTraits<B>::ValueType> ValueTuple; |
| 292 | typedef 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 | |
| 298 | template <class A, class B, class C> |
| 299 | struct TupleTypes< Tuple3<A, B, C> > { |
| 300 | typedef Tuple3<typename TupleTraits<A>::ValueType, |
| 301 | typename TupleTraits<B>::ValueType, |
| 302 | typename TupleTraits<C>::ValueType> ValueTuple; |
| 303 | typedef 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 | |
| 311 | template <class A, class B, class C, class D> |
| 312 | struct 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; |
| 317 | typedef 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 | |
| 327 | template <class A, class B, class C, class D, class E> |
| 328 | struct 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; |
| 334 | typedef 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 | |
| 346 | template <class A, class B, class C, class D, class E, class F> |
| 347 | struct 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; |
| 354 | typedef 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 | |
| 368 | template <class A, class B, class C, class D, class E, class F, class G> |
| 369 | struct 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; |
| 377 | typedef 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 | |
| 393 | template <class A, class B, class C, class D, class E, class F, class G, |
| 394 | class H> |
| 395 | struct 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; |
| 404 | typedef 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 422 | // Tuple creators ------------------------------------------------------------- |
| 423 | // |
| 424 | // Helper functions for constructing tuples while inferring the template |
| 425 | // argument types. |
| 426 | |
| 427 | inline Tuple0 MakeTuple() { |
| 428 | return Tuple0(); |
| 429 | } |
| 430 | |
| 431 | template <class A> |
| 432 | inline Tuple1<A> MakeTuple(const A& a) { |
| 433 | return Tuple1<A>(a); |
| 434 | } |
| 435 | |
| 436 | template <class A, class B> |
| 437 | inline Tuple2<A, B> MakeTuple(const A& a, const B& b) { |
| 438 | return Tuple2<A, B>(a, b); |
| 439 | } |
| 440 | |
| 441 | template <class A, class B, class C> |
| 442 | inline 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 | |
| 446 | template <class A, class B, class C, class D> |
| 447 | inline 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 | |
| 452 | template <class A, class B, class C, class D, class E> |
| 453 | inline 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 458 | template <class A, class B, class C, class D, class E, class F> |
| 459 | inline 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.com | 67c3575 | 2008-11-13 07:10:20 +0900 | [diff] [blame] | 464 | template <class A, class B, class C, class D, class E, class F, class G> |
| 465 | inline 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.org | 5a468fc | 2010-07-21 01:56:26 +0900 | [diff] [blame] | 471 | template <class A, class B, class C, class D, class E, class F, class G, |
| 472 | class H> |
| 473 | inline 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 480 | // The following set of helpers make what Boost refers to as "Tiers" - a tuple |
| 481 | // of references. |
| 482 | |
| 483 | template <class A> |
| 484 | inline Tuple1<A&> MakeRefTuple(A& a) { |
| 485 | return Tuple1<A&>(a); |
| 486 | } |
| 487 | |
| 488 | template <class A, class B> |
| 489 | inline Tuple2<A&, B&> MakeRefTuple(A& a, B& b) { |
| 490 | return Tuple2<A&, B&>(a, b); |
| 491 | } |
| 492 | |
| 493 | template <class A, class B, class C> |
| 494 | inline Tuple3<A&, B&, C&> MakeRefTuple(A& a, B& b, C& c) { |
| 495 | return Tuple3<A&, B&, C&>(a, b, c); |
| 496 | } |
| 497 | |
| 498 | template <class A, class B, class C, class D> |
| 499 | inline 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 | |
| 503 | template <class A, class B, class C, class D, class E> |
| 504 | inline 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.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 508 | template <class A, class B, class C, class D, class E, class F> |
| 509 | inline 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.com | 67c3575 | 2008-11-13 07:10:20 +0900 | [diff] [blame] | 514 | template <class A, class B, class C, class D, class E, class F, class G> |
| 515 | inline 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.org | 5a468fc | 2010-07-21 01:56:26 +0900 | [diff] [blame] | 520 | template <class A, class B, class C, class D, class E, class F, class G, |
| 521 | class H> |
| 522 | inline 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.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 528 | // 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 | |
| 539 | template <class ObjT, class Method> |
| 540 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple0& arg) { |
| 541 | (obj->*method)(); |
| 542 | } |
| 543 | |
| 544 | template <class ObjT, class Method, class A> |
| 545 | inline void DispatchToMethod(ObjT* obj, Method method, const A& arg) { |
| 546 | (obj->*method)(arg); |
| 547 | } |
| 548 | |
| 549 | template <class ObjT, class Method, class A> |
| 550 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple1<A>& arg) { |
oshima@chromium.org | b7c8e32 | 2010-11-11 08:47:56 +0900 | [diff] [blame] | 551 | |
oshima@chromium.org | 061e50f | 2010-12-02 09:11:40 +0900 | [diff] [blame^] | 552 | #if defined(OS_CHROMEOS) |
oshima@chromium.org | b7c8e32 | 2010-11-11 08:47:56 +0900 | [diff] [blame] | 553 | // To troubleshoot crosbug.com/7327. |
| 554 | CHECK(obj); |
| 555 | CHECK(&arg); |
| 556 | CHECK(method); |
| 557 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 558 | (obj->*method)(arg.a); |
| 559 | } |
| 560 | |
| 561 | template<class ObjT, class Method, class A, class B> |
maruel@chromium.org | 8fe7adc | 2009-03-04 00:01:12 +0900 | [diff] [blame] | 562 | inline void DispatchToMethod(ObjT* obj, |
| 563 | Method method, |
| 564 | const Tuple2<A, B>& arg) { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 565 | (obj->*method)(arg.a, arg.b); |
| 566 | } |
| 567 | |
| 568 | template<class ObjT, class Method, class A, class B, class C> |
| 569 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 570 | const Tuple3<A, B, C>& arg) { |
| 571 | (obj->*method)(arg.a, arg.b, arg.c); |
| 572 | } |
| 573 | |
| 574 | template<class ObjT, class Method, class A, class B, class C, class D> |
| 575 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 576 | const Tuple4<A, B, C, D>& arg) { |
| 577 | (obj->*method)(arg.a, arg.b, arg.c, arg.d); |
| 578 | } |
| 579 | |
| 580 | template<class ObjT, class Method, class A, class B, class C, class D, class E> |
| 581 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 582 | const Tuple5<A, B, C, D, E>& arg) { |
| 583 | (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e); |
| 584 | } |
| 585 | |
ojan@google.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 586 | template<class ObjT, class Method, class A, class B, class C, class D, class E, |
| 587 | class F> |
| 588 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 589 | const Tuple6<A, B, C, D, E, F>& arg) { |
| 590 | (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f); |
| 591 | } |
| 592 | |
sky@google.com | 67c3575 | 2008-11-13 07:10:20 +0900 | [diff] [blame] | 593 | template<class ObjT, class Method, class A, class B, class C, class D, class E, |
| 594 | class F, class G> |
| 595 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 596 | const Tuple7<A, B, C, D, E, F, G>& arg) { |
| 597 | (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g); |
| 598 | } |
| 599 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 600 | // Static Dispatchers with no out params. |
| 601 | |
| 602 | template <class Function> |
| 603 | inline void DispatchToFunction(Function function, const Tuple0& arg) { |
| 604 | (*function)(); |
| 605 | } |
| 606 | |
| 607 | template <class Function, class A> |
| 608 | inline void DispatchToFunction(Function function, const A& arg) { |
| 609 | (*function)(arg); |
| 610 | } |
| 611 | |
| 612 | template <class Function, class A> |
| 613 | inline void DispatchToFunction(Function function, const Tuple1<A>& arg) { |
| 614 | (*function)(arg.a); |
| 615 | } |
| 616 | |
| 617 | template<class Function, class A, class B> |
| 618 | inline void DispatchToFunction(Function function, const Tuple2<A, B>& arg) { |
| 619 | (*function)(arg.a, arg.b); |
| 620 | } |
| 621 | |
| 622 | template<class Function, class A, class B, class C> |
| 623 | inline void DispatchToFunction(Function function, const Tuple3<A, B, C>& arg) { |
| 624 | (*function)(arg.a, arg.b, arg.c); |
| 625 | } |
| 626 | |
| 627 | template<class Function, class A, class B, class C, class D> |
| 628 | inline void DispatchToFunction(Function function, |
| 629 | const Tuple4<A, B, C, D>& arg) { |
| 630 | (*function)(arg.a, arg.b, arg.c, arg.d); |
| 631 | } |
| 632 | |
| 633 | template<class Function, class A, class B, class C, class D, class E> |
| 634 | inline void DispatchToFunction(Function function, |
| 635 | const Tuple5<A, B, C, D, E>& arg) { |
| 636 | (*function)(arg.a, arg.b, arg.c, arg.d, arg.e); |
| 637 | } |
| 638 | |
ojan@google.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 639 | template<class Function, class A, class B, class C, class D, class E, class F> |
| 640 | inline void DispatchToFunction(Function function, |
| 641 | const Tuple6<A, B, C, D, E, F>& arg) { |
| 642 | (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f); |
| 643 | } |
| 644 | |
phajdan.jr@chromium.org | 5a468fc | 2010-07-21 01:56:26 +0900 | [diff] [blame] | 645 | template<class Function, class A, class B, class C, class D, class E, class F, |
| 646 | class G> |
| 647 | inline void DispatchToFunction(Function function, |
| 648 | const Tuple7<A, B, C, D, E, F, G>& arg) { |
| 649 | (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g); |
| 650 | } |
| 651 | |
| 652 | template<class Function, class A, class B, class C, class D, class E, class F, |
| 653 | class G, class H> |
| 654 | inline void DispatchToFunction(Function function, |
| 655 | const Tuple8<A, B, C, D, E, F, G, H>& arg) { |
| 656 | (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g, arg.h); |
| 657 | } |
| 658 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 659 | // Dispatchers with 0 out param (as a Tuple0). |
| 660 | |
| 661 | template <class ObjT, class Method> |
maruel@chromium.org | 8fe7adc | 2009-03-04 00:01:12 +0900 | [diff] [blame] | 662 | inline void DispatchToMethod(ObjT* obj, |
| 663 | Method method, |
| 664 | const Tuple0& arg, Tuple0*) { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 665 | (obj->*method)(); |
| 666 | } |
| 667 | |
| 668 | template <class ObjT, class Method, class A> |
| 669 | inline void DispatchToMethod(ObjT* obj, Method method, const A& arg, Tuple0*) { |
| 670 | (obj->*method)(arg); |
| 671 | } |
| 672 | |
| 673 | template <class ObjT, class Method, class A> |
maruel@chromium.org | 8fe7adc | 2009-03-04 00:01:12 +0900 | [diff] [blame] | 674 | inline void DispatchToMethod(ObjT* obj, |
| 675 | Method method, |
| 676 | const Tuple1<A>& arg, Tuple0*) { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 677 | (obj->*method)(arg.a); |
| 678 | } |
| 679 | |
| 680 | template<class ObjT, class Method, class A, class B> |
maruel@chromium.org | 8fe7adc | 2009-03-04 00:01:12 +0900 | [diff] [blame] | 681 | inline void DispatchToMethod(ObjT* obj, |
| 682 | Method method, |
| 683 | const Tuple2<A, B>& arg, Tuple0*) { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 684 | (obj->*method)(arg.a, arg.b); |
| 685 | } |
| 686 | |
| 687 | template<class ObjT, class Method, class A, class B, class C> |
| 688 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 689 | const Tuple3<A, B, C>& arg, Tuple0*) { |
| 690 | (obj->*method)(arg.a, arg.b, arg.c); |
| 691 | } |
| 692 | |
| 693 | template<class ObjT, class Method, class A, class B, class C, class D> |
| 694 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 695 | const Tuple4<A, B, C, D>& arg, Tuple0*) { |
| 696 | (obj->*method)(arg.a, arg.b, arg.c, arg.d); |
| 697 | } |
| 698 | |
| 699 | template<class ObjT, class Method, class A, class B, class C, class D, class E> |
| 700 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 701 | const Tuple5<A, B, C, D, E>& arg, Tuple0*) { |
| 702 | (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e); |
| 703 | } |
| 704 | |
ojan@google.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 705 | template<class ObjT, class Method, class A, class B, class C, class D, class E, |
| 706 | class F> |
| 707 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 708 | const Tuple6<A, B, C, D, E, F>& arg, Tuple0*) { |
| 709 | (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f); |
| 710 | } |
| 711 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 712 | // Dispatchers with 1 out param. |
| 713 | |
| 714 | template<class ObjT, class Method, |
| 715 | class OutA> |
| 716 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 717 | const Tuple0& in, |
| 718 | Tuple1<OutA>* out) { |
| 719 | (obj->*method)(&out->a); |
| 720 | } |
| 721 | |
| 722 | template<class ObjT, class Method, class InA, |
| 723 | class OutA> |
| 724 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 725 | const InA& in, |
| 726 | Tuple1<OutA>* out) { |
| 727 | (obj->*method)(in, &out->a); |
| 728 | } |
| 729 | |
| 730 | template<class ObjT, class Method, class InA, |
| 731 | class OutA> |
| 732 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 733 | const Tuple1<InA>& in, |
| 734 | Tuple1<OutA>* out) { |
| 735 | (obj->*method)(in.a, &out->a); |
| 736 | } |
| 737 | |
| 738 | template<class ObjT, class Method, class InA, class InB, |
| 739 | class OutA> |
| 740 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 741 | const Tuple2<InA, InB>& in, |
| 742 | Tuple1<OutA>* out) { |
| 743 | (obj->*method)(in.a, in.b, &out->a); |
| 744 | } |
| 745 | |
| 746 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 747 | class OutA> |
| 748 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 749 | const Tuple3<InA, InB, InC>& in, |
| 750 | Tuple1<OutA>* out) { |
| 751 | (obj->*method)(in.a, in.b, in.c, &out->a); |
| 752 | } |
| 753 | |
| 754 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 755 | class OutA> |
| 756 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 757 | const Tuple4<InA, InB, InC, InD>& in, |
| 758 | Tuple1<OutA>* out) { |
| 759 | (obj->*method)(in.a, in.b, in.c, in.d, &out->a); |
| 760 | } |
| 761 | |
erg@google.com | bf6ce9f | 2010-01-27 08:08:02 +0900 | [diff] [blame] | 762 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 763 | class InE, class OutA> |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 764 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 765 | const Tuple5<InA, InB, InC, InD, InE>& in, |
| 766 | Tuple1<OutA>* out) { |
| 767 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a); |
| 768 | } |
| 769 | |
ojan@google.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 770 | template<class ObjT, class Method, |
| 771 | class InA, class InB, class InC, class InD, class InE, class InF, |
| 772 | class OutA> |
| 773 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 774 | const Tuple6<InA, InB, InC, InD, InE, InF>& in, |
| 775 | Tuple1<OutA>* out) { |
| 776 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a); |
| 777 | } |
| 778 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 779 | // Dispatchers with 2 out params. |
| 780 | |
| 781 | template<class ObjT, class Method, |
| 782 | class OutA, class OutB> |
| 783 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 784 | const Tuple0& in, |
| 785 | Tuple2<OutA, OutB>* out) { |
| 786 | (obj->*method)(&out->a, &out->b); |
| 787 | } |
| 788 | |
| 789 | template<class ObjT, class Method, class InA, |
| 790 | class OutA, class OutB> |
| 791 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 792 | const InA& in, |
| 793 | Tuple2<OutA, OutB>* out) { |
| 794 | (obj->*method)(in, &out->a, &out->b); |
| 795 | } |
| 796 | |
| 797 | template<class ObjT, class Method, class InA, |
| 798 | class OutA, class OutB> |
| 799 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 800 | const Tuple1<InA>& in, |
| 801 | Tuple2<OutA, OutB>* out) { |
| 802 | (obj->*method)(in.a, &out->a, &out->b); |
| 803 | } |
| 804 | |
| 805 | template<class ObjT, class Method, class InA, class InB, |
| 806 | class OutA, class OutB> |
| 807 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 808 | const Tuple2<InA, InB>& in, |
| 809 | Tuple2<OutA, OutB>* out) { |
| 810 | (obj->*method)(in.a, in.b, &out->a, &out->b); |
| 811 | } |
| 812 | |
| 813 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 814 | class OutA, class OutB> |
| 815 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 816 | const Tuple3<InA, InB, InC>& in, |
| 817 | Tuple2<OutA, OutB>* out) { |
| 818 | (obj->*method)(in.a, in.b, in.c, &out->a, &out->b); |
| 819 | } |
| 820 | |
| 821 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 822 | class OutA, class OutB> |
| 823 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 824 | const Tuple4<InA, InB, InC, InD>& in, |
| 825 | Tuple2<OutA, OutB>* out) { |
| 826 | (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b); |
| 827 | } |
| 828 | |
| 829 | template<class ObjT, class Method, |
| 830 | class InA, class InB, class InC, class InD, class InE, |
| 831 | class OutA, class OutB> |
| 832 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 833 | const Tuple5<InA, InB, InC, InD, InE>& in, |
| 834 | Tuple2<OutA, OutB>* out) { |
| 835 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b); |
| 836 | } |
| 837 | |
ojan@google.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 838 | template<class ObjT, class Method, |
| 839 | class InA, class InB, class InC, class InD, class InE, class InF, |
| 840 | class OutA, class OutB> |
| 841 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 842 | const Tuple6<InA, InB, InC, InD, InE, InF>& in, |
| 843 | Tuple2<OutA, OutB>* out) { |
| 844 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b); |
| 845 | } |
| 846 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 847 | // Dispatchers with 3 out params. |
| 848 | |
| 849 | template<class ObjT, class Method, |
| 850 | class OutA, class OutB, class OutC> |
| 851 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 852 | const Tuple0& in, |
| 853 | Tuple3<OutA, OutB, OutC>* out) { |
| 854 | (obj->*method)(&out->a, &out->b, &out->c); |
| 855 | } |
| 856 | |
| 857 | template<class ObjT, class Method, class InA, |
| 858 | class OutA, class OutB, class OutC> |
| 859 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 860 | const InA& in, |
| 861 | Tuple3<OutA, OutB, OutC>* out) { |
| 862 | (obj->*method)(in, &out->a, &out->b, &out->c); |
| 863 | } |
| 864 | |
| 865 | template<class ObjT, class Method, class InA, |
| 866 | class OutA, class OutB, class OutC> |
| 867 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 868 | const Tuple1<InA>& in, |
| 869 | Tuple3<OutA, OutB, OutC>* out) { |
| 870 | (obj->*method)(in.a, &out->a, &out->b, &out->c); |
| 871 | } |
| 872 | |
| 873 | template<class ObjT, class Method, class InA, class InB, |
| 874 | class OutA, class OutB, class OutC> |
| 875 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 876 | const Tuple2<InA, InB>& in, |
| 877 | Tuple3<OutA, OutB, OutC>* out) { |
| 878 | (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c); |
| 879 | } |
| 880 | |
| 881 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 882 | class OutA, class OutB, class OutC> |
| 883 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 884 | const Tuple3<InA, InB, InC>& in, |
| 885 | Tuple3<OutA, OutB, OutC>* out) { |
| 886 | (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c); |
| 887 | } |
| 888 | |
| 889 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 890 | class OutA, class OutB, class OutC> |
| 891 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 892 | const Tuple4<InA, InB, InC, InD>& in, |
| 893 | Tuple3<OutA, OutB, OutC>* out) { |
| 894 | (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c); |
| 895 | } |
| 896 | |
| 897 | template<class ObjT, class Method, |
| 898 | class InA, class InB, class InC, class InD, class InE, |
| 899 | class OutA, class OutB, class OutC> |
| 900 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 901 | const Tuple5<InA, InB, InC, InD, InE>& in, |
| 902 | Tuple3<OutA, OutB, OutC>* out) { |
| 903 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b, &out->c); |
| 904 | } |
| 905 | |
ojan@google.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 906 | template<class ObjT, class Method, |
| 907 | class InA, class InB, class InC, class InD, class InE, class InF, |
| 908 | class OutA, class OutB, class OutC> |
| 909 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 910 | const Tuple6<InA, InB, InC, InD, InE, InF>& in, |
| 911 | Tuple3<OutA, OutB, OutC>* out) { |
| 912 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b, &out->c); |
| 913 | } |
| 914 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 915 | // Dispatchers with 4 out params. |
| 916 | |
| 917 | template<class ObjT, class Method, |
| 918 | class OutA, class OutB, class OutC, class OutD> |
| 919 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 920 | const Tuple0& in, |
| 921 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 922 | (obj->*method)(&out->a, &out->b, &out->c, &out->d); |
| 923 | } |
| 924 | |
| 925 | template<class ObjT, class Method, class InA, |
| 926 | class OutA, class OutB, class OutC, class OutD> |
| 927 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 928 | const InA& in, |
| 929 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 930 | (obj->*method)(in, &out->a, &out->b, &out->c, &out->d); |
| 931 | } |
| 932 | |
| 933 | template<class ObjT, class Method, class InA, |
| 934 | class OutA, class OutB, class OutC, class OutD> |
| 935 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 936 | const Tuple1<InA>& in, |
| 937 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 938 | (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d); |
| 939 | } |
| 940 | |
| 941 | template<class ObjT, class Method, class InA, class InB, |
| 942 | class OutA, class OutB, class OutC, class OutD> |
| 943 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 944 | const Tuple2<InA, InB>& in, |
| 945 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 946 | (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d); |
| 947 | } |
| 948 | |
| 949 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 950 | class OutA, class OutB, class OutC, class OutD> |
| 951 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 952 | const Tuple3<InA, InB, InC>& in, |
| 953 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 954 | (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d); |
| 955 | } |
| 956 | |
| 957 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 958 | class OutA, class OutB, class OutC, class OutD> |
| 959 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 960 | const Tuple4<InA, InB, InC, InD>& in, |
| 961 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 962 | (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d); |
| 963 | } |
| 964 | |
| 965 | template<class ObjT, class Method, |
| 966 | class InA, class InB, class InC, class InD, class InE, |
| 967 | class OutA, class OutB, class OutC, class OutD> |
| 968 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 969 | const Tuple5<InA, InB, InC, InD, InE>& in, |
| 970 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 971 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, |
| 972 | &out->a, &out->b, &out->c, &out->d); |
| 973 | } |
| 974 | |
ojan@google.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 975 | template<class ObjT, class Method, |
| 976 | class InA, class InB, class InC, class InD, class InE, class InF, |
| 977 | class OutA, class OutB, class OutC, class OutD> |
| 978 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 979 | const Tuple6<InA, InB, InC, InD, InE, InF>& in, |
| 980 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 981 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, |
| 982 | &out->a, &out->b, &out->c, &out->d); |
| 983 | } |
| 984 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 985 | // Dispatchers with 5 out params. |
| 986 | |
| 987 | template<class ObjT, class Method, |
| 988 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 989 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 990 | const Tuple0& in, |
| 991 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 992 | (obj->*method)(&out->a, &out->b, &out->c, &out->d, &out->e); |
| 993 | } |
| 994 | |
| 995 | template<class ObjT, class Method, class InA, |
| 996 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 997 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 998 | const InA& in, |
| 999 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 1000 | (obj->*method)(in, &out->a, &out->b, &out->c, &out->d, &out->e); |
| 1001 | } |
| 1002 | |
| 1003 | template<class ObjT, class Method, class InA, |
| 1004 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 1005 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 1006 | const Tuple1<InA>& in, |
| 1007 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 1008 | (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d, &out->e); |
| 1009 | } |
| 1010 | |
| 1011 | template<class ObjT, class Method, class InA, class InB, |
| 1012 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 1013 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 1014 | const Tuple2<InA, InB>& in, |
| 1015 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 1016 | (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d, &out->e); |
| 1017 | } |
| 1018 | |
| 1019 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 1020 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 1021 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 1022 | const Tuple3<InA, InB, InC>& in, |
| 1023 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 1024 | (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d, &out->e); |
| 1025 | } |
| 1026 | |
| 1027 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 1028 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 1029 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 1030 | const Tuple4<InA, InB, InC, InD>& in, |
| 1031 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 1032 | (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d, |
| 1033 | &out->e); |
| 1034 | } |
| 1035 | |
| 1036 | template<class ObjT, class Method, |
| 1037 | class InA, class InB, class InC, class InD, class InE, |
| 1038 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 1039 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 1040 | const Tuple5<InA, InB, InC, InD, InE>& in, |
| 1041 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 1042 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, |
| 1043 | &out->a, &out->b, &out->c, &out->d, &out->e); |
| 1044 | } |
| 1045 | |
ojan@google.com | 3835509 | 2008-10-10 06:58:05 +0900 | [diff] [blame] | 1046 | template<class ObjT, class Method, |
| 1047 | class InA, class InB, class InC, class InD, class InE, class InF, |
| 1048 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 1049 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 1050 | const Tuple6<InA, InB, InC, InD, InE, InF>& in, |
| 1051 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 1052 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, |
| 1053 | &out->a, &out->b, &out->c, &out->d, &out->e); |
| 1054 | } |
| 1055 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 1056 | #endif // BASE_TUPLE_H__ |