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 | |
| 5 | #ifndef BASE_TUPLE_H__ |
| 6 | #define BASE_TUPLE_H__ |
| 7 | |
| 8 | // Traits ---------------------------------------------------------------------- |
| 9 | // |
| 10 | // A simple traits class for tuple arguments. |
| 11 | // |
| 12 | // ValueType: the bare, nonref version of a type (same as the type for nonrefs). |
| 13 | // RefType: the ref version of a type (same as the type for refs). |
| 14 | // ParamType: what type to pass to functions (refs should not be constified). |
| 15 | |
| 16 | template <class P> |
| 17 | struct TupleTraits { |
| 18 | typedef P ValueType; |
| 19 | typedef P& RefType; |
| 20 | typedef const P& ParamType; |
| 21 | }; |
| 22 | |
| 23 | template <class P> |
| 24 | struct TupleTraits<P&> { |
| 25 | typedef P ValueType; |
| 26 | typedef P& RefType; |
| 27 | typedef P& ParamType; |
| 28 | }; |
| 29 | |
| 30 | // Tuple ----------------------------------------------------------------------- |
| 31 | // |
| 32 | // This set of classes is useful for bundling 0 or more heterogeneous data types |
| 33 | // into a single variable. The advantage of this is that it greatly simplifies |
| 34 | // function objects that need to take an arbitrary number of parameters; see |
| 35 | // RunnableMethod and IPC::MessageWithTuple. |
| 36 | // |
deanm@google.com | ff4b729 | 2008-08-21 19:58:08 +0900 | [diff] [blame] | 37 | // Tuple0 is supplied to act as a 'void' type. It can be used, for example, |
| 38 | // when dispatching to a function that accepts no arguments (see the |
| 39 | // Dispatchers below). |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 40 | // Tuple1<A> is rarely useful. One such use is when A is non-const ref that you |
| 41 | // want filled by the dispatchee, and the tuple is merely a container for that |
| 42 | // output (a "tier"). See MakeRefTuple and its usages. |
| 43 | |
| 44 | struct Tuple0 { |
| 45 | typedef Tuple0 ValueTuple; |
| 46 | typedef Tuple0 RefTuple; |
| 47 | }; |
| 48 | |
| 49 | template <class A> |
| 50 | struct Tuple1 { |
| 51 | public: |
| 52 | typedef A TypeA; |
| 53 | typedef Tuple1<typename TupleTraits<A>::ValueType> ValueTuple; |
| 54 | typedef Tuple1<typename TupleTraits<A>::RefType> RefTuple; |
| 55 | |
| 56 | Tuple1() {} |
| 57 | explicit Tuple1(typename TupleTraits<A>::ParamType a) : a(a) {} |
| 58 | |
| 59 | A a; |
| 60 | }; |
| 61 | |
| 62 | template <class A, class B> |
| 63 | struct Tuple2 { |
| 64 | public: |
| 65 | typedef A TypeA; |
| 66 | typedef B TypeB; |
| 67 | typedef Tuple2<typename TupleTraits<A>::ValueType, |
| 68 | typename TupleTraits<B>::ValueType> ValueTuple; |
| 69 | typedef Tuple2<typename TupleTraits<A>::RefType, |
| 70 | typename TupleTraits<B>::RefType> RefTuple; |
| 71 | |
| 72 | Tuple2() {} |
| 73 | Tuple2(typename TupleTraits<A>::ParamType a, |
| 74 | typename TupleTraits<B>::ParamType b) |
| 75 | : a(a), b(b) { |
| 76 | } |
| 77 | |
| 78 | A a; |
| 79 | B b; |
| 80 | }; |
| 81 | |
| 82 | template <class A, class B, class C> |
| 83 | struct Tuple3 { |
| 84 | public: |
| 85 | typedef A TypeA; |
| 86 | typedef B TypeB; |
| 87 | typedef C TypeC; |
| 88 | typedef Tuple3<typename TupleTraits<A>::ValueType, |
| 89 | typename TupleTraits<B>::ValueType, |
| 90 | typename TupleTraits<C>::ValueType> ValueTuple; |
| 91 | typedef Tuple3<typename TupleTraits<A>::RefType, |
| 92 | typename TupleTraits<B>::RefType, |
| 93 | typename TupleTraits<C>::RefType> RefTuple; |
| 94 | |
| 95 | Tuple3() {} |
| 96 | Tuple3(typename TupleTraits<A>::ParamType a, |
| 97 | typename TupleTraits<B>::ParamType b, |
| 98 | typename TupleTraits<C>::ParamType c) |
| 99 | : a(a), b(b), c(c){ |
| 100 | } |
| 101 | |
| 102 | A a; |
| 103 | B b; |
| 104 | C c; |
| 105 | }; |
| 106 | |
| 107 | template <class A, class B, class C, class D> |
| 108 | struct Tuple4 { |
| 109 | public: |
| 110 | typedef A TypeA; |
| 111 | typedef B TypeB; |
| 112 | typedef C TypeC; |
| 113 | typedef D TypeD; |
| 114 | typedef Tuple4<typename TupleTraits<A>::ValueType, |
| 115 | typename TupleTraits<B>::ValueType, |
| 116 | typename TupleTraits<C>::ValueType, |
| 117 | typename TupleTraits<D>::ValueType> ValueTuple; |
| 118 | typedef Tuple4<typename TupleTraits<A>::RefType, |
| 119 | typename TupleTraits<B>::RefType, |
| 120 | typename TupleTraits<C>::RefType, |
| 121 | typename TupleTraits<D>::RefType> RefTuple; |
| 122 | |
| 123 | Tuple4() {} |
| 124 | Tuple4(typename TupleTraits<A>::ParamType a, |
| 125 | typename TupleTraits<B>::ParamType b, |
| 126 | typename TupleTraits<C>::ParamType c, |
| 127 | typename TupleTraits<D>::ParamType d) |
| 128 | : a(a), b(b), c(c), d(d) { |
| 129 | } |
| 130 | |
| 131 | A a; |
| 132 | B b; |
| 133 | C c; |
| 134 | D d; |
| 135 | }; |
| 136 | |
| 137 | template <class A, class B, class C, class D, class E> |
| 138 | struct Tuple5 { |
| 139 | public: |
| 140 | typedef A TypeA; |
| 141 | typedef B TypeB; |
| 142 | typedef C TypeC; |
| 143 | typedef D TypeD; |
| 144 | typedef E TypeE; |
| 145 | typedef Tuple5<typename TupleTraits<A>::ValueType, |
| 146 | typename TupleTraits<B>::ValueType, |
| 147 | typename TupleTraits<C>::ValueType, |
| 148 | typename TupleTraits<D>::ValueType, |
| 149 | typename TupleTraits<E>::ValueType> ValueTuple; |
| 150 | typedef Tuple5<typename TupleTraits<A>::RefType, |
| 151 | typename TupleTraits<B>::RefType, |
| 152 | typename TupleTraits<C>::RefType, |
| 153 | typename TupleTraits<D>::RefType, |
| 154 | typename TupleTraits<E>::RefType> RefTuple; |
| 155 | |
| 156 | Tuple5() {} |
| 157 | Tuple5(typename TupleTraits<A>::ParamType a, |
| 158 | typename TupleTraits<B>::ParamType b, |
| 159 | typename TupleTraits<C>::ParamType c, |
| 160 | typename TupleTraits<D>::ParamType d, |
| 161 | typename TupleTraits<E>::ParamType e) |
| 162 | : a(a), b(b), c(c), d(d), e(e) { |
| 163 | } |
| 164 | |
| 165 | A a; |
| 166 | B b; |
| 167 | C c; |
| 168 | D d; |
| 169 | E e; |
| 170 | }; |
| 171 | |
| 172 | // Tuple creators ------------------------------------------------------------- |
| 173 | // |
| 174 | // Helper functions for constructing tuples while inferring the template |
| 175 | // argument types. |
| 176 | |
| 177 | inline Tuple0 MakeTuple() { |
| 178 | return Tuple0(); |
| 179 | } |
| 180 | |
| 181 | template <class A> |
| 182 | inline Tuple1<A> MakeTuple(const A& a) { |
| 183 | return Tuple1<A>(a); |
| 184 | } |
| 185 | |
| 186 | template <class A, class B> |
| 187 | inline Tuple2<A, B> MakeTuple(const A& a, const B& b) { |
| 188 | return Tuple2<A, B>(a, b); |
| 189 | } |
| 190 | |
| 191 | template <class A, class B, class C> |
| 192 | inline Tuple3<A, B, C> MakeTuple(const A& a, const B& b, const C& c) { |
| 193 | return Tuple3<A, B, C>(a, b, c); |
| 194 | } |
| 195 | |
| 196 | template <class A, class B, class C, class D> |
| 197 | inline Tuple4<A, B, C, D> MakeTuple(const A& a, const B& b, const C& c, |
| 198 | const D& d) { |
| 199 | return Tuple4<A, B, C, D>(a, b, c, d); |
| 200 | } |
| 201 | |
| 202 | template <class A, class B, class C, class D, class E> |
| 203 | inline Tuple5<A, B, C, D, E> MakeTuple(const A& a, const B& b, const C& c, |
| 204 | const D& d, const E& e) { |
| 205 | return Tuple5<A, B, C, D, E>(a, b, c, d, e); |
| 206 | } |
| 207 | |
| 208 | // The following set of helpers make what Boost refers to as "Tiers" - a tuple |
| 209 | // of references. |
| 210 | |
| 211 | template <class A> |
| 212 | inline Tuple1<A&> MakeRefTuple(A& a) { |
| 213 | return Tuple1<A&>(a); |
| 214 | } |
| 215 | |
| 216 | template <class A, class B> |
| 217 | inline Tuple2<A&, B&> MakeRefTuple(A& a, B& b) { |
| 218 | return Tuple2<A&, B&>(a, b); |
| 219 | } |
| 220 | |
| 221 | template <class A, class B, class C> |
| 222 | inline Tuple3<A&, B&, C&> MakeRefTuple(A& a, B& b, C& c) { |
| 223 | return Tuple3<A&, B&, C&>(a, b, c); |
| 224 | } |
| 225 | |
| 226 | template <class A, class B, class C, class D> |
| 227 | inline Tuple4<A&, B&, C&, D&> MakeRefTuple(A& a, B& b, C& c, D& d) { |
| 228 | return Tuple4<A&, B&, C&, D&>(a, b, c, d); |
| 229 | } |
| 230 | |
| 231 | template <class A, class B, class C, class D, class E> |
| 232 | inline Tuple5<A&, B&, C&, D&, E&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e) { |
| 233 | return Tuple5<A&, B&, C&, D&, E&>(a, b, c, d, e); |
| 234 | } |
| 235 | |
| 236 | // Dispatchers ---------------------------------------------------------------- |
| 237 | // |
| 238 | // Helper functions that call the given method on an object, with the unpacked |
| 239 | // tuple arguments. Notice that they all have the same number of arguments, |
| 240 | // so you need only write: |
| 241 | // DispatchToMethod(object, &Object::method, args); |
| 242 | // This is very useful for templated dispatchers, since they don't need to know |
| 243 | // what type |args| is. |
| 244 | |
| 245 | // Non-Static Dispatchers with no out params. |
| 246 | |
| 247 | template <class ObjT, class Method> |
| 248 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple0& arg) { |
| 249 | (obj->*method)(); |
| 250 | } |
| 251 | |
| 252 | template <class ObjT, class Method, class A> |
| 253 | inline void DispatchToMethod(ObjT* obj, Method method, const A& arg) { |
| 254 | (obj->*method)(arg); |
| 255 | } |
| 256 | |
| 257 | template <class ObjT, class Method, class A> |
| 258 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple1<A>& arg) { |
| 259 | (obj->*method)(arg.a); |
| 260 | } |
| 261 | |
| 262 | template<class ObjT, class Method, class A, class B> |
| 263 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple2<A, B>& arg) { |
| 264 | (obj->*method)(arg.a, arg.b); |
| 265 | } |
| 266 | |
| 267 | template<class ObjT, class Method, class A, class B, class C> |
| 268 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 269 | const Tuple3<A, B, C>& arg) { |
| 270 | (obj->*method)(arg.a, arg.b, arg.c); |
| 271 | } |
| 272 | |
| 273 | template<class ObjT, class Method, class A, class B, class C, class D> |
| 274 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 275 | const Tuple4<A, B, C, D>& arg) { |
| 276 | (obj->*method)(arg.a, arg.b, arg.c, arg.d); |
| 277 | } |
| 278 | |
| 279 | template<class ObjT, class Method, class A, class B, class C, class D, class E> |
| 280 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 281 | const Tuple5<A, B, C, D, E>& arg) { |
| 282 | (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e); |
| 283 | } |
| 284 | |
| 285 | // Static Dispatchers with no out params. |
| 286 | |
| 287 | template <class Function> |
| 288 | inline void DispatchToFunction(Function function, const Tuple0& arg) { |
| 289 | (*function)(); |
| 290 | } |
| 291 | |
| 292 | template <class Function, class A> |
| 293 | inline void DispatchToFunction(Function function, const A& arg) { |
| 294 | (*function)(arg); |
| 295 | } |
| 296 | |
| 297 | template <class Function, class A> |
| 298 | inline void DispatchToFunction(Function function, const Tuple1<A>& arg) { |
| 299 | (*function)(arg.a); |
| 300 | } |
| 301 | |
| 302 | template<class Function, class A, class B> |
| 303 | inline void DispatchToFunction(Function function, const Tuple2<A, B>& arg) { |
| 304 | (*function)(arg.a, arg.b); |
| 305 | } |
| 306 | |
| 307 | template<class Function, class A, class B, class C> |
| 308 | inline void DispatchToFunction(Function function, const Tuple3<A, B, C>& arg) { |
| 309 | (*function)(arg.a, arg.b, arg.c); |
| 310 | } |
| 311 | |
| 312 | template<class Function, class A, class B, class C, class D> |
| 313 | inline void DispatchToFunction(Function function, |
| 314 | const Tuple4<A, B, C, D>& arg) { |
| 315 | (*function)(arg.a, arg.b, arg.c, arg.d); |
| 316 | } |
| 317 | |
| 318 | template<class Function, class A, class B, class C, class D, class E> |
| 319 | inline void DispatchToFunction(Function function, |
| 320 | const Tuple5<A, B, C, D, E>& arg) { |
| 321 | (*function)(arg.a, arg.b, arg.c, arg.d, arg.e); |
| 322 | } |
| 323 | |
| 324 | // Dispatchers with 0 out param (as a Tuple0). |
| 325 | |
| 326 | template <class ObjT, class Method> |
| 327 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple0& arg, Tuple0*) { |
| 328 | (obj->*method)(); |
| 329 | } |
| 330 | |
| 331 | template <class ObjT, class Method, class A> |
| 332 | inline void DispatchToMethod(ObjT* obj, Method method, const A& arg, Tuple0*) { |
| 333 | (obj->*method)(arg); |
| 334 | } |
| 335 | |
| 336 | template <class ObjT, class Method, class A> |
| 337 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple1<A>& arg, Tuple0*) { |
| 338 | (obj->*method)(arg.a); |
| 339 | } |
| 340 | |
| 341 | template<class ObjT, class Method, class A, class B> |
| 342 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple2<A, B>& arg, Tuple0*) { |
| 343 | (obj->*method)(arg.a, arg.b); |
| 344 | } |
| 345 | |
| 346 | template<class ObjT, class Method, class A, class B, class C> |
| 347 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 348 | const Tuple3<A, B, C>& arg, Tuple0*) { |
| 349 | (obj->*method)(arg.a, arg.b, arg.c); |
| 350 | } |
| 351 | |
| 352 | template<class ObjT, class Method, class A, class B, class C, class D> |
| 353 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 354 | const Tuple4<A, B, C, D>& arg, Tuple0*) { |
| 355 | (obj->*method)(arg.a, arg.b, arg.c, arg.d); |
| 356 | } |
| 357 | |
| 358 | template<class ObjT, class Method, class A, class B, class C, class D, class E> |
| 359 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 360 | const Tuple5<A, B, C, D, E>& arg, Tuple0*) { |
| 361 | (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e); |
| 362 | } |
| 363 | |
| 364 | // Dispatchers with 1 out param. |
| 365 | |
| 366 | template<class ObjT, class Method, |
| 367 | class OutA> |
| 368 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 369 | const Tuple0& in, |
| 370 | Tuple1<OutA>* out) { |
| 371 | (obj->*method)(&out->a); |
| 372 | } |
| 373 | |
| 374 | template<class ObjT, class Method, class InA, |
| 375 | class OutA> |
| 376 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 377 | const InA& in, |
| 378 | Tuple1<OutA>* out) { |
| 379 | (obj->*method)(in, &out->a); |
| 380 | } |
| 381 | |
| 382 | template<class ObjT, class Method, class InA, |
| 383 | class OutA> |
| 384 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 385 | const Tuple1<InA>& in, |
| 386 | Tuple1<OutA>* out) { |
| 387 | (obj->*method)(in.a, &out->a); |
| 388 | } |
| 389 | |
| 390 | template<class ObjT, class Method, class InA, class InB, |
| 391 | class OutA> |
| 392 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 393 | const Tuple2<InA, InB>& in, |
| 394 | Tuple1<OutA>* out) { |
| 395 | (obj->*method)(in.a, in.b, &out->a); |
| 396 | } |
| 397 | |
| 398 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 399 | class OutA> |
| 400 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 401 | const Tuple3<InA, InB, InC>& in, |
| 402 | Tuple1<OutA>* out) { |
| 403 | (obj->*method)(in.a, in.b, in.c, &out->a); |
| 404 | } |
| 405 | |
| 406 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 407 | class OutA> |
| 408 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 409 | const Tuple4<InA, InB, InC, InD>& in, |
| 410 | Tuple1<OutA>* out) { |
| 411 | (obj->*method)(in.a, in.b, in.c, in.d, &out->a); |
| 412 | } |
| 413 | |
| 414 | template<class ObjT, class Method, |
| 415 | class InA, class InB, class InC, class InD, class InE, |
| 416 | class OutA> |
| 417 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 418 | const Tuple5<InA, InB, InC, InD, InE>& in, |
| 419 | Tuple1<OutA>* out) { |
| 420 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a); |
| 421 | } |
| 422 | |
| 423 | // Dispatchers with 2 out params. |
| 424 | |
| 425 | template<class ObjT, class Method, |
| 426 | class OutA, class OutB> |
| 427 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 428 | const Tuple0& in, |
| 429 | Tuple2<OutA, OutB>* out) { |
| 430 | (obj->*method)(&out->a, &out->b); |
| 431 | } |
| 432 | |
| 433 | template<class ObjT, class Method, class InA, |
| 434 | class OutA, class OutB> |
| 435 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 436 | const InA& in, |
| 437 | Tuple2<OutA, OutB>* out) { |
| 438 | (obj->*method)(in, &out->a, &out->b); |
| 439 | } |
| 440 | |
| 441 | template<class ObjT, class Method, class InA, |
| 442 | class OutA, class OutB> |
| 443 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 444 | const Tuple1<InA>& in, |
| 445 | Tuple2<OutA, OutB>* out) { |
| 446 | (obj->*method)(in.a, &out->a, &out->b); |
| 447 | } |
| 448 | |
| 449 | template<class ObjT, class Method, class InA, class InB, |
| 450 | class OutA, class OutB> |
| 451 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 452 | const Tuple2<InA, InB>& in, |
| 453 | Tuple2<OutA, OutB>* out) { |
| 454 | (obj->*method)(in.a, in.b, &out->a, &out->b); |
| 455 | } |
| 456 | |
| 457 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 458 | class OutA, class OutB> |
| 459 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 460 | const Tuple3<InA, InB, InC>& in, |
| 461 | Tuple2<OutA, OutB>* out) { |
| 462 | (obj->*method)(in.a, in.b, in.c, &out->a, &out->b); |
| 463 | } |
| 464 | |
| 465 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 466 | class OutA, class OutB> |
| 467 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 468 | const Tuple4<InA, InB, InC, InD>& in, |
| 469 | Tuple2<OutA, OutB>* out) { |
| 470 | (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b); |
| 471 | } |
| 472 | |
| 473 | template<class ObjT, class Method, |
| 474 | class InA, class InB, class InC, class InD, class InE, |
| 475 | class OutA, class OutB> |
| 476 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 477 | const Tuple5<InA, InB, InC, InD, InE>& in, |
| 478 | Tuple2<OutA, OutB>* out) { |
| 479 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b); |
| 480 | } |
| 481 | |
| 482 | // Dispatchers with 3 out params. |
| 483 | |
| 484 | template<class ObjT, class Method, |
| 485 | class OutA, class OutB, class OutC> |
| 486 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 487 | const Tuple0& in, |
| 488 | Tuple3<OutA, OutB, OutC>* out) { |
| 489 | (obj->*method)(&out->a, &out->b, &out->c); |
| 490 | } |
| 491 | |
| 492 | template<class ObjT, class Method, class InA, |
| 493 | class OutA, class OutB, class OutC> |
| 494 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 495 | const InA& in, |
| 496 | Tuple3<OutA, OutB, OutC>* out) { |
| 497 | (obj->*method)(in, &out->a, &out->b, &out->c); |
| 498 | } |
| 499 | |
| 500 | template<class ObjT, class Method, class InA, |
| 501 | class OutA, class OutB, class OutC> |
| 502 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 503 | const Tuple1<InA>& in, |
| 504 | Tuple3<OutA, OutB, OutC>* out) { |
| 505 | (obj->*method)(in.a, &out->a, &out->b, &out->c); |
| 506 | } |
| 507 | |
| 508 | template<class ObjT, class Method, class InA, class InB, |
| 509 | class OutA, class OutB, class OutC> |
| 510 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 511 | const Tuple2<InA, InB>& in, |
| 512 | Tuple3<OutA, OutB, OutC>* out) { |
| 513 | (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c); |
| 514 | } |
| 515 | |
| 516 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 517 | class OutA, class OutB, class OutC> |
| 518 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 519 | const Tuple3<InA, InB, InC>& in, |
| 520 | Tuple3<OutA, OutB, OutC>* out) { |
| 521 | (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c); |
| 522 | } |
| 523 | |
| 524 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 525 | class OutA, class OutB, class OutC> |
| 526 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 527 | const Tuple4<InA, InB, InC, InD>& in, |
| 528 | Tuple3<OutA, OutB, OutC>* out) { |
| 529 | (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c); |
| 530 | } |
| 531 | |
| 532 | template<class ObjT, class Method, |
| 533 | class InA, class InB, class InC, class InD, class InE, |
| 534 | class OutA, class OutB, class OutC> |
| 535 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 536 | const Tuple5<InA, InB, InC, InD, InE>& in, |
| 537 | Tuple3<OutA, OutB, OutC>* out) { |
| 538 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b, &out->c); |
| 539 | } |
| 540 | |
| 541 | // Dispatchers with 4 out params. |
| 542 | |
| 543 | template<class ObjT, class Method, |
| 544 | class OutA, class OutB, class OutC, class OutD> |
| 545 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 546 | const Tuple0& in, |
| 547 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 548 | (obj->*method)(&out->a, &out->b, &out->c, &out->d); |
| 549 | } |
| 550 | |
| 551 | template<class ObjT, class Method, class InA, |
| 552 | class OutA, class OutB, class OutC, class OutD> |
| 553 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 554 | const InA& in, |
| 555 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 556 | (obj->*method)(in, &out->a, &out->b, &out->c, &out->d); |
| 557 | } |
| 558 | |
| 559 | template<class ObjT, class Method, class InA, |
| 560 | class OutA, class OutB, class OutC, class OutD> |
| 561 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 562 | const Tuple1<InA>& in, |
| 563 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 564 | (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d); |
| 565 | } |
| 566 | |
| 567 | template<class ObjT, class Method, class InA, class InB, |
| 568 | class OutA, class OutB, class OutC, class OutD> |
| 569 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 570 | const Tuple2<InA, InB>& in, |
| 571 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 572 | (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d); |
| 573 | } |
| 574 | |
| 575 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 576 | class OutA, class OutB, class OutC, class OutD> |
| 577 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 578 | const Tuple3<InA, InB, InC>& in, |
| 579 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 580 | (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d); |
| 581 | } |
| 582 | |
| 583 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 584 | class OutA, class OutB, class OutC, class OutD> |
| 585 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 586 | const Tuple4<InA, InB, InC, InD>& in, |
| 587 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 588 | (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d); |
| 589 | } |
| 590 | |
| 591 | template<class ObjT, class Method, |
| 592 | class InA, class InB, class InC, class InD, class InE, |
| 593 | class OutA, class OutB, class OutC, class OutD> |
| 594 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 595 | const Tuple5<InA, InB, InC, InD, InE>& in, |
| 596 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 597 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, |
| 598 | &out->a, &out->b, &out->c, &out->d); |
| 599 | } |
| 600 | |
| 601 | // Dispatchers with 5 out params. |
| 602 | |
| 603 | template<class ObjT, class Method, |
| 604 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 605 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 606 | const Tuple0& in, |
| 607 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 608 | (obj->*method)(&out->a, &out->b, &out->c, &out->d, &out->e); |
| 609 | } |
| 610 | |
| 611 | template<class ObjT, class Method, class InA, |
| 612 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 613 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 614 | const InA& in, |
| 615 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 616 | (obj->*method)(in, &out->a, &out->b, &out->c, &out->d, &out->e); |
| 617 | } |
| 618 | |
| 619 | template<class ObjT, class Method, class InA, |
| 620 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 621 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 622 | const Tuple1<InA>& in, |
| 623 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 624 | (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d, &out->e); |
| 625 | } |
| 626 | |
| 627 | template<class ObjT, class Method, class InA, class InB, |
| 628 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 629 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 630 | const Tuple2<InA, InB>& in, |
| 631 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 632 | (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d, &out->e); |
| 633 | } |
| 634 | |
| 635 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 636 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 637 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 638 | const Tuple3<InA, InB, InC>& in, |
| 639 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 640 | (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d, &out->e); |
| 641 | } |
| 642 | |
| 643 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 644 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 645 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 646 | const Tuple4<InA, InB, InC, InD>& in, |
| 647 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 648 | (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d, |
| 649 | &out->e); |
| 650 | } |
| 651 | |
| 652 | template<class ObjT, class Method, |
| 653 | class InA, class InB, class InC, class InD, class InE, |
| 654 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 655 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 656 | const Tuple5<InA, InB, InC, InD, InE>& in, |
| 657 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 658 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, |
| 659 | &out->a, &out->b, &out->c, &out->d, &out->e); |
| 660 | } |
| 661 | |
| 662 | #endif // BASE_TUPLE_H__ |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 663 | |