license.bot | bf09a50 | 2008-08-24 00:55:55 | [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 | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 4 | |
[email protected] | 302bdc13 | 2008-08-25 13:42:07 | [diff] [blame] | 5 | // A Tuple is a generic templatized container, similar in concept to std::pair. |
[email protected] | 8a2820a | 2008-10-09 21:58:05 | [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, |
[email protected] | 302bdc13 | 2008-08-25 13:42:07 | [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 | d7cae12 | 2008-07-26 21:49:38 | [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 | // |
[email protected] | 45871198 | 2008-08-21 10:58:08 | [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 | d7cae12 | 2008-07-26 21:49:38 | [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; |
| 71 | }; |
| 72 | |
| 73 | template <class A> |
| 74 | struct Tuple1 { |
| 75 | public: |
| 76 | typedef A TypeA; |
| 77 | typedef Tuple1<typename TupleTraits<A>::ValueType> ValueTuple; |
| 78 | typedef Tuple1<typename TupleTraits<A>::RefType> RefTuple; |
| 79 | |
| 80 | Tuple1() {} |
| 81 | explicit Tuple1(typename TupleTraits<A>::ParamType a) : a(a) {} |
| 82 | |
| 83 | A a; |
| 84 | }; |
| 85 | |
| 86 | template <class A, class B> |
| 87 | struct Tuple2 { |
| 88 | public: |
| 89 | typedef A TypeA; |
| 90 | typedef B TypeB; |
| 91 | typedef Tuple2<typename TupleTraits<A>::ValueType, |
| 92 | typename TupleTraits<B>::ValueType> ValueTuple; |
| 93 | typedef Tuple2<typename TupleTraits<A>::RefType, |
| 94 | typename TupleTraits<B>::RefType> RefTuple; |
| 95 | |
| 96 | Tuple2() {} |
| 97 | Tuple2(typename TupleTraits<A>::ParamType a, |
| 98 | typename TupleTraits<B>::ParamType b) |
| 99 | : a(a), b(b) { |
| 100 | } |
| 101 | |
| 102 | A a; |
| 103 | B b; |
| 104 | }; |
| 105 | |
| 106 | template <class A, class B, class C> |
| 107 | struct Tuple3 { |
| 108 | public: |
| 109 | typedef A TypeA; |
| 110 | typedef B TypeB; |
| 111 | typedef C TypeC; |
| 112 | typedef Tuple3<typename TupleTraits<A>::ValueType, |
| 113 | typename TupleTraits<B>::ValueType, |
| 114 | typename TupleTraits<C>::ValueType> ValueTuple; |
| 115 | typedef Tuple3<typename TupleTraits<A>::RefType, |
| 116 | typename TupleTraits<B>::RefType, |
| 117 | typename TupleTraits<C>::RefType> RefTuple; |
| 118 | |
| 119 | Tuple3() {} |
| 120 | Tuple3(typename TupleTraits<A>::ParamType a, |
| 121 | typename TupleTraits<B>::ParamType b, |
| 122 | typename TupleTraits<C>::ParamType c) |
| 123 | : a(a), b(b), c(c){ |
| 124 | } |
| 125 | |
| 126 | A a; |
| 127 | B b; |
| 128 | C c; |
| 129 | }; |
| 130 | |
| 131 | template <class A, class B, class C, class D> |
| 132 | struct Tuple4 { |
| 133 | public: |
| 134 | typedef A TypeA; |
| 135 | typedef B TypeB; |
| 136 | typedef C TypeC; |
| 137 | typedef D TypeD; |
| 138 | typedef Tuple4<typename TupleTraits<A>::ValueType, |
| 139 | typename TupleTraits<B>::ValueType, |
| 140 | typename TupleTraits<C>::ValueType, |
| 141 | typename TupleTraits<D>::ValueType> ValueTuple; |
| 142 | typedef Tuple4<typename TupleTraits<A>::RefType, |
| 143 | typename TupleTraits<B>::RefType, |
| 144 | typename TupleTraits<C>::RefType, |
| 145 | typename TupleTraits<D>::RefType> RefTuple; |
| 146 | |
| 147 | Tuple4() {} |
| 148 | Tuple4(typename TupleTraits<A>::ParamType a, |
| 149 | typename TupleTraits<B>::ParamType b, |
| 150 | typename TupleTraits<C>::ParamType c, |
| 151 | typename TupleTraits<D>::ParamType d) |
| 152 | : a(a), b(b), c(c), d(d) { |
| 153 | } |
| 154 | |
| 155 | A a; |
| 156 | B b; |
| 157 | C c; |
| 158 | D d; |
| 159 | }; |
| 160 | |
| 161 | template <class A, class B, class C, class D, class E> |
| 162 | struct Tuple5 { |
| 163 | public: |
| 164 | typedef A TypeA; |
| 165 | typedef B TypeB; |
| 166 | typedef C TypeC; |
| 167 | typedef D TypeD; |
| 168 | typedef E TypeE; |
| 169 | typedef Tuple5<typename TupleTraits<A>::ValueType, |
| 170 | typename TupleTraits<B>::ValueType, |
| 171 | typename TupleTraits<C>::ValueType, |
| 172 | typename TupleTraits<D>::ValueType, |
| 173 | typename TupleTraits<E>::ValueType> ValueTuple; |
| 174 | typedef Tuple5<typename TupleTraits<A>::RefType, |
| 175 | typename TupleTraits<B>::RefType, |
| 176 | typename TupleTraits<C>::RefType, |
| 177 | typename TupleTraits<D>::RefType, |
| 178 | typename TupleTraits<E>::RefType> RefTuple; |
| 179 | |
| 180 | Tuple5() {} |
| 181 | Tuple5(typename TupleTraits<A>::ParamType a, |
| 182 | typename TupleTraits<B>::ParamType b, |
| 183 | typename TupleTraits<C>::ParamType c, |
| 184 | typename TupleTraits<D>::ParamType d, |
| 185 | typename TupleTraits<E>::ParamType e) |
| 186 | : a(a), b(b), c(c), d(d), e(e) { |
| 187 | } |
| 188 | |
| 189 | A a; |
| 190 | B b; |
| 191 | C c; |
| 192 | D d; |
| 193 | E e; |
| 194 | }; |
| 195 | |
[email protected] | 8a2820a | 2008-10-09 21:58:05 | [diff] [blame^] | 196 | template <class A, class B, class C, class D, class E, class F> |
| 197 | struct Tuple6 { |
| 198 | public: |
| 199 | typedef A TypeA; |
| 200 | typedef B TypeB; |
| 201 | typedef C TypeC; |
| 202 | typedef D TypeD; |
| 203 | typedef E TypeE; |
| 204 | typedef F TypeF; |
| 205 | typedef Tuple6<typename TupleTraits<A>::ValueType, |
| 206 | typename TupleTraits<B>::ValueType, |
| 207 | typename TupleTraits<C>::ValueType, |
| 208 | typename TupleTraits<D>::ValueType, |
| 209 | typename TupleTraits<E>::ValueType, |
| 210 | typename TupleTraits<F>::ValueType> ValueTuple; |
| 211 | typedef Tuple6<typename TupleTraits<A>::RefType, |
| 212 | typename TupleTraits<B>::RefType, |
| 213 | typename TupleTraits<C>::RefType, |
| 214 | typename TupleTraits<D>::RefType, |
| 215 | typename TupleTraits<E>::RefType, |
| 216 | typename TupleTraits<F>::RefType> RefTuple; |
| 217 | |
| 218 | Tuple6() {} |
| 219 | Tuple6(typename TupleTraits<A>::ParamType a, |
| 220 | typename TupleTraits<B>::ParamType b, |
| 221 | typename TupleTraits<C>::ParamType c, |
| 222 | typename TupleTraits<D>::ParamType d, |
| 223 | typename TupleTraits<E>::ParamType e, |
| 224 | typename TupleTraits<F>::ParamType f) |
| 225 | : a(a), b(b), c(c), d(d), e(e), f(f) { |
| 226 | } |
| 227 | |
| 228 | A a; |
| 229 | B b; |
| 230 | C c; |
| 231 | D d; |
| 232 | E e; |
| 233 | F f; |
| 234 | }; |
| 235 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 236 | // Tuple creators ------------------------------------------------------------- |
| 237 | // |
| 238 | // Helper functions for constructing tuples while inferring the template |
| 239 | // argument types. |
| 240 | |
| 241 | inline Tuple0 MakeTuple() { |
| 242 | return Tuple0(); |
| 243 | } |
| 244 | |
| 245 | template <class A> |
| 246 | inline Tuple1<A> MakeTuple(const A& a) { |
| 247 | return Tuple1<A>(a); |
| 248 | } |
| 249 | |
| 250 | template <class A, class B> |
| 251 | inline Tuple2<A, B> MakeTuple(const A& a, const B& b) { |
| 252 | return Tuple2<A, B>(a, b); |
| 253 | } |
| 254 | |
| 255 | template <class A, class B, class C> |
| 256 | inline Tuple3<A, B, C> MakeTuple(const A& a, const B& b, const C& c) { |
| 257 | return Tuple3<A, B, C>(a, b, c); |
| 258 | } |
| 259 | |
| 260 | template <class A, class B, class C, class D> |
| 261 | inline Tuple4<A, B, C, D> MakeTuple(const A& a, const B& b, const C& c, |
| 262 | const D& d) { |
| 263 | return Tuple4<A, B, C, D>(a, b, c, d); |
| 264 | } |
| 265 | |
| 266 | template <class A, class B, class C, class D, class E> |
| 267 | inline Tuple5<A, B, C, D, E> MakeTuple(const A& a, const B& b, const C& c, |
| 268 | const D& d, const E& e) { |
| 269 | return Tuple5<A, B, C, D, E>(a, b, c, d, e); |
| 270 | } |
| 271 | |
[email protected] | 8a2820a | 2008-10-09 21:58:05 | [diff] [blame^] | 272 | template <class A, class B, class C, class D, class E, class F> |
| 273 | inline Tuple6<A, B, C, D, E, F> MakeTuple(const A& a, const B& b, const C& c, |
| 274 | const D& d, const E& e, const F& f) { |
| 275 | return Tuple6<A, B, C, D, E, F>(a, b, c, d, e, f); |
| 276 | } |
| 277 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 278 | // The following set of helpers make what Boost refers to as "Tiers" - a tuple |
| 279 | // of references. |
| 280 | |
| 281 | template <class A> |
| 282 | inline Tuple1<A&> MakeRefTuple(A& a) { |
| 283 | return Tuple1<A&>(a); |
| 284 | } |
| 285 | |
| 286 | template <class A, class B> |
| 287 | inline Tuple2<A&, B&> MakeRefTuple(A& a, B& b) { |
| 288 | return Tuple2<A&, B&>(a, b); |
| 289 | } |
| 290 | |
| 291 | template <class A, class B, class C> |
| 292 | inline Tuple3<A&, B&, C&> MakeRefTuple(A& a, B& b, C& c) { |
| 293 | return Tuple3<A&, B&, C&>(a, b, c); |
| 294 | } |
| 295 | |
| 296 | template <class A, class B, class C, class D> |
| 297 | inline Tuple4<A&, B&, C&, D&> MakeRefTuple(A& a, B& b, C& c, D& d) { |
| 298 | return Tuple4<A&, B&, C&, D&>(a, b, c, d); |
| 299 | } |
| 300 | |
| 301 | template <class A, class B, class C, class D, class E> |
| 302 | inline Tuple5<A&, B&, C&, D&, E&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e) { |
| 303 | return Tuple5<A&, B&, C&, D&, E&>(a, b, c, d, e); |
| 304 | } |
| 305 | |
[email protected] | 8a2820a | 2008-10-09 21:58:05 | [diff] [blame^] | 306 | template <class A, class B, class C, class D, class E, class F> |
| 307 | inline Tuple6<A&, B&, C&, D&, E&, F&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e, |
| 308 | F& f) { |
| 309 | return Tuple6<A&, B&, C&, D&, E&, F&>(a, b, c, d, e, f); |
| 310 | } |
| 311 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 312 | // Dispatchers ---------------------------------------------------------------- |
| 313 | // |
| 314 | // Helper functions that call the given method on an object, with the unpacked |
| 315 | // tuple arguments. Notice that they all have the same number of arguments, |
| 316 | // so you need only write: |
| 317 | // DispatchToMethod(object, &Object::method, args); |
| 318 | // This is very useful for templated dispatchers, since they don't need to know |
| 319 | // what type |args| is. |
| 320 | |
| 321 | // Non-Static Dispatchers with no out params. |
| 322 | |
| 323 | template <class ObjT, class Method> |
| 324 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple0& arg) { |
| 325 | (obj->*method)(); |
| 326 | } |
| 327 | |
| 328 | template <class ObjT, class Method, class A> |
| 329 | inline void DispatchToMethod(ObjT* obj, Method method, const A& arg) { |
| 330 | (obj->*method)(arg); |
| 331 | } |
| 332 | |
| 333 | template <class ObjT, class Method, class A> |
| 334 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple1<A>& arg) { |
| 335 | (obj->*method)(arg.a); |
| 336 | } |
| 337 | |
| 338 | template<class ObjT, class Method, class A, class B> |
| 339 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple2<A, B>& arg) { |
| 340 | (obj->*method)(arg.a, arg.b); |
| 341 | } |
| 342 | |
| 343 | template<class ObjT, class Method, class A, class B, class C> |
| 344 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 345 | const Tuple3<A, B, C>& arg) { |
| 346 | (obj->*method)(arg.a, arg.b, arg.c); |
| 347 | } |
| 348 | |
| 349 | template<class ObjT, class Method, class A, class B, class C, class D> |
| 350 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 351 | const Tuple4<A, B, C, D>& arg) { |
| 352 | (obj->*method)(arg.a, arg.b, arg.c, arg.d); |
| 353 | } |
| 354 | |
| 355 | template<class ObjT, class Method, class A, class B, class C, class D, class E> |
| 356 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 357 | const Tuple5<A, B, C, D, E>& arg) { |
| 358 | (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e); |
| 359 | } |
| 360 | |
[email protected] | 8a2820a | 2008-10-09 21:58:05 | [diff] [blame^] | 361 | template<class ObjT, class Method, class A, class B, class C, class D, class E, |
| 362 | class F> |
| 363 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 364 | const Tuple6<A, B, C, D, E, F>& arg) { |
| 365 | (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f); |
| 366 | } |
| 367 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 368 | // Static Dispatchers with no out params. |
| 369 | |
| 370 | template <class Function> |
| 371 | inline void DispatchToFunction(Function function, const Tuple0& arg) { |
| 372 | (*function)(); |
| 373 | } |
| 374 | |
| 375 | template <class Function, class A> |
| 376 | inline void DispatchToFunction(Function function, const A& arg) { |
| 377 | (*function)(arg); |
| 378 | } |
| 379 | |
| 380 | template <class Function, class A> |
| 381 | inline void DispatchToFunction(Function function, const Tuple1<A>& arg) { |
| 382 | (*function)(arg.a); |
| 383 | } |
| 384 | |
| 385 | template<class Function, class A, class B> |
| 386 | inline void DispatchToFunction(Function function, const Tuple2<A, B>& arg) { |
| 387 | (*function)(arg.a, arg.b); |
| 388 | } |
| 389 | |
| 390 | template<class Function, class A, class B, class C> |
| 391 | inline void DispatchToFunction(Function function, const Tuple3<A, B, C>& arg) { |
| 392 | (*function)(arg.a, arg.b, arg.c); |
| 393 | } |
| 394 | |
| 395 | template<class Function, class A, class B, class C, class D> |
| 396 | inline void DispatchToFunction(Function function, |
| 397 | const Tuple4<A, B, C, D>& arg) { |
| 398 | (*function)(arg.a, arg.b, arg.c, arg.d); |
| 399 | } |
| 400 | |
| 401 | template<class Function, class A, class B, class C, class D, class E> |
| 402 | inline void DispatchToFunction(Function function, |
| 403 | const Tuple5<A, B, C, D, E>& arg) { |
| 404 | (*function)(arg.a, arg.b, arg.c, arg.d, arg.e); |
| 405 | } |
| 406 | |
[email protected] | 8a2820a | 2008-10-09 21:58:05 | [diff] [blame^] | 407 | template<class Function, class A, class B, class C, class D, class E, class F> |
| 408 | inline void DispatchToFunction(Function function, |
| 409 | const Tuple6<A, B, C, D, E, F>& arg) { |
| 410 | (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f); |
| 411 | } |
| 412 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 413 | // Dispatchers with 0 out param (as a Tuple0). |
| 414 | |
| 415 | template <class ObjT, class Method> |
| 416 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple0& arg, Tuple0*) { |
| 417 | (obj->*method)(); |
| 418 | } |
| 419 | |
| 420 | template <class ObjT, class Method, class A> |
| 421 | inline void DispatchToMethod(ObjT* obj, Method method, const A& arg, Tuple0*) { |
| 422 | (obj->*method)(arg); |
| 423 | } |
| 424 | |
| 425 | template <class ObjT, class Method, class A> |
| 426 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple1<A>& arg, Tuple0*) { |
| 427 | (obj->*method)(arg.a); |
| 428 | } |
| 429 | |
| 430 | template<class ObjT, class Method, class A, class B> |
| 431 | inline void DispatchToMethod(ObjT* obj, Method method, const Tuple2<A, B>& arg, Tuple0*) { |
| 432 | (obj->*method)(arg.a, arg.b); |
| 433 | } |
| 434 | |
| 435 | template<class ObjT, class Method, class A, class B, class C> |
| 436 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 437 | const Tuple3<A, B, C>& arg, Tuple0*) { |
| 438 | (obj->*method)(arg.a, arg.b, arg.c); |
| 439 | } |
| 440 | |
| 441 | template<class ObjT, class Method, class A, class B, class C, class D> |
| 442 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 443 | const Tuple4<A, B, C, D>& arg, Tuple0*) { |
| 444 | (obj->*method)(arg.a, arg.b, arg.c, arg.d); |
| 445 | } |
| 446 | |
| 447 | template<class ObjT, class Method, class A, class B, class C, class D, class E> |
| 448 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 449 | const Tuple5<A, B, C, D, E>& arg, Tuple0*) { |
| 450 | (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e); |
| 451 | } |
| 452 | |
[email protected] | 8a2820a | 2008-10-09 21:58:05 | [diff] [blame^] | 453 | template<class ObjT, class Method, class A, class B, class C, class D, class E, |
| 454 | class F> |
| 455 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 456 | const Tuple6<A, B, C, D, E, F>& arg, Tuple0*) { |
| 457 | (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f); |
| 458 | } |
| 459 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 460 | // Dispatchers with 1 out param. |
| 461 | |
| 462 | template<class ObjT, class Method, |
| 463 | class OutA> |
| 464 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 465 | const Tuple0& in, |
| 466 | Tuple1<OutA>* out) { |
| 467 | (obj->*method)(&out->a); |
| 468 | } |
| 469 | |
| 470 | template<class ObjT, class Method, class InA, |
| 471 | class OutA> |
| 472 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 473 | const InA& in, |
| 474 | Tuple1<OutA>* out) { |
| 475 | (obj->*method)(in, &out->a); |
| 476 | } |
| 477 | |
| 478 | template<class ObjT, class Method, class InA, |
| 479 | class OutA> |
| 480 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 481 | const Tuple1<InA>& in, |
| 482 | Tuple1<OutA>* out) { |
| 483 | (obj->*method)(in.a, &out->a); |
| 484 | } |
| 485 | |
| 486 | template<class ObjT, class Method, class InA, class InB, |
| 487 | class OutA> |
| 488 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 489 | const Tuple2<InA, InB>& in, |
| 490 | Tuple1<OutA>* out) { |
| 491 | (obj->*method)(in.a, in.b, &out->a); |
| 492 | } |
| 493 | |
| 494 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 495 | class OutA> |
| 496 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 497 | const Tuple3<InA, InB, InC>& in, |
| 498 | Tuple1<OutA>* out) { |
| 499 | (obj->*method)(in.a, in.b, in.c, &out->a); |
| 500 | } |
| 501 | |
| 502 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 503 | class OutA> |
| 504 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 505 | const Tuple4<InA, InB, InC, InD>& in, |
| 506 | Tuple1<OutA>* out) { |
| 507 | (obj->*method)(in.a, in.b, in.c, in.d, &out->a); |
| 508 | } |
| 509 | |
| 510 | template<class ObjT, class Method, |
| 511 | class InA, class InB, class InC, class InD, class InE, |
| 512 | class OutA> |
| 513 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 514 | const Tuple5<InA, InB, InC, InD, InE>& in, |
| 515 | Tuple1<OutA>* out) { |
| 516 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a); |
| 517 | } |
| 518 | |
[email protected] | 8a2820a | 2008-10-09 21:58:05 | [diff] [blame^] | 519 | template<class ObjT, class Method, |
| 520 | class InA, class InB, class InC, class InD, class InE, class InF, |
| 521 | class OutA> |
| 522 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 523 | const Tuple6<InA, InB, InC, InD, InE, InF>& in, |
| 524 | Tuple1<OutA>* out) { |
| 525 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a); |
| 526 | } |
| 527 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 528 | // Dispatchers with 2 out params. |
| 529 | |
| 530 | template<class ObjT, class Method, |
| 531 | class OutA, class OutB> |
| 532 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 533 | const Tuple0& in, |
| 534 | Tuple2<OutA, OutB>* out) { |
| 535 | (obj->*method)(&out->a, &out->b); |
| 536 | } |
| 537 | |
| 538 | template<class ObjT, class Method, class InA, |
| 539 | class OutA, class OutB> |
| 540 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 541 | const InA& in, |
| 542 | Tuple2<OutA, OutB>* out) { |
| 543 | (obj->*method)(in, &out->a, &out->b); |
| 544 | } |
| 545 | |
| 546 | template<class ObjT, class Method, class InA, |
| 547 | class OutA, class OutB> |
| 548 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 549 | const Tuple1<InA>& in, |
| 550 | Tuple2<OutA, OutB>* out) { |
| 551 | (obj->*method)(in.a, &out->a, &out->b); |
| 552 | } |
| 553 | |
| 554 | template<class ObjT, class Method, class InA, class InB, |
| 555 | class OutA, class OutB> |
| 556 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 557 | const Tuple2<InA, InB>& in, |
| 558 | Tuple2<OutA, OutB>* out) { |
| 559 | (obj->*method)(in.a, in.b, &out->a, &out->b); |
| 560 | } |
| 561 | |
| 562 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 563 | class OutA, class OutB> |
| 564 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 565 | const Tuple3<InA, InB, InC>& in, |
| 566 | Tuple2<OutA, OutB>* out) { |
| 567 | (obj->*method)(in.a, in.b, in.c, &out->a, &out->b); |
| 568 | } |
| 569 | |
| 570 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 571 | class OutA, class OutB> |
| 572 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 573 | const Tuple4<InA, InB, InC, InD>& in, |
| 574 | Tuple2<OutA, OutB>* out) { |
| 575 | (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b); |
| 576 | } |
| 577 | |
| 578 | template<class ObjT, class Method, |
| 579 | class InA, class InB, class InC, class InD, class InE, |
| 580 | class OutA, class OutB> |
| 581 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 582 | const Tuple5<InA, InB, InC, InD, InE>& in, |
| 583 | Tuple2<OutA, OutB>* out) { |
| 584 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b); |
| 585 | } |
| 586 | |
[email protected] | 8a2820a | 2008-10-09 21:58:05 | [diff] [blame^] | 587 | template<class ObjT, class Method, |
| 588 | class InA, class InB, class InC, class InD, class InE, class InF, |
| 589 | class OutA, class OutB> |
| 590 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 591 | const Tuple6<InA, InB, InC, InD, InE, InF>& in, |
| 592 | Tuple2<OutA, OutB>* out) { |
| 593 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b); |
| 594 | } |
| 595 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 596 | // Dispatchers with 3 out params. |
| 597 | |
| 598 | template<class ObjT, class Method, |
| 599 | class OutA, class OutB, class OutC> |
| 600 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 601 | const Tuple0& in, |
| 602 | Tuple3<OutA, OutB, OutC>* out) { |
| 603 | (obj->*method)(&out->a, &out->b, &out->c); |
| 604 | } |
| 605 | |
| 606 | template<class ObjT, class Method, class InA, |
| 607 | class OutA, class OutB, class OutC> |
| 608 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 609 | const InA& in, |
| 610 | Tuple3<OutA, OutB, OutC>* out) { |
| 611 | (obj->*method)(in, &out->a, &out->b, &out->c); |
| 612 | } |
| 613 | |
| 614 | template<class ObjT, class Method, class InA, |
| 615 | class OutA, class OutB, class OutC> |
| 616 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 617 | const Tuple1<InA>& in, |
| 618 | Tuple3<OutA, OutB, OutC>* out) { |
| 619 | (obj->*method)(in.a, &out->a, &out->b, &out->c); |
| 620 | } |
| 621 | |
| 622 | template<class ObjT, class Method, class InA, class InB, |
| 623 | class OutA, class OutB, class OutC> |
| 624 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 625 | const Tuple2<InA, InB>& in, |
| 626 | Tuple3<OutA, OutB, OutC>* out) { |
| 627 | (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c); |
| 628 | } |
| 629 | |
| 630 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 631 | class OutA, class OutB, class OutC> |
| 632 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 633 | const Tuple3<InA, InB, InC>& in, |
| 634 | Tuple3<OutA, OutB, OutC>* out) { |
| 635 | (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c); |
| 636 | } |
| 637 | |
| 638 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 639 | class OutA, class OutB, class OutC> |
| 640 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 641 | const Tuple4<InA, InB, InC, InD>& in, |
| 642 | Tuple3<OutA, OutB, OutC>* out) { |
| 643 | (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c); |
| 644 | } |
| 645 | |
| 646 | template<class ObjT, class Method, |
| 647 | class InA, class InB, class InC, class InD, class InE, |
| 648 | class OutA, class OutB, class OutC> |
| 649 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 650 | const Tuple5<InA, InB, InC, InD, InE>& in, |
| 651 | Tuple3<OutA, OutB, OutC>* out) { |
| 652 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b, &out->c); |
| 653 | } |
| 654 | |
[email protected] | 8a2820a | 2008-10-09 21:58:05 | [diff] [blame^] | 655 | template<class ObjT, class Method, |
| 656 | class InA, class InB, class InC, class InD, class InE, class InF, |
| 657 | class OutA, class OutB, class OutC> |
| 658 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 659 | const Tuple6<InA, InB, InC, InD, InE, InF>& in, |
| 660 | Tuple3<OutA, OutB, OutC>* out) { |
| 661 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b, &out->c); |
| 662 | } |
| 663 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 664 | // Dispatchers with 4 out params. |
| 665 | |
| 666 | template<class ObjT, class Method, |
| 667 | class OutA, class OutB, class OutC, class OutD> |
| 668 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 669 | const Tuple0& in, |
| 670 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 671 | (obj->*method)(&out->a, &out->b, &out->c, &out->d); |
| 672 | } |
| 673 | |
| 674 | template<class ObjT, class Method, class InA, |
| 675 | class OutA, class OutB, class OutC, class OutD> |
| 676 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 677 | const InA& in, |
| 678 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 679 | (obj->*method)(in, &out->a, &out->b, &out->c, &out->d); |
| 680 | } |
| 681 | |
| 682 | template<class ObjT, class Method, class InA, |
| 683 | class OutA, class OutB, class OutC, class OutD> |
| 684 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 685 | const Tuple1<InA>& in, |
| 686 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 687 | (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d); |
| 688 | } |
| 689 | |
| 690 | template<class ObjT, class Method, class InA, class InB, |
| 691 | class OutA, class OutB, class OutC, class OutD> |
| 692 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 693 | const Tuple2<InA, InB>& in, |
| 694 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 695 | (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d); |
| 696 | } |
| 697 | |
| 698 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 699 | class OutA, class OutB, class OutC, class OutD> |
| 700 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 701 | const Tuple3<InA, InB, InC>& in, |
| 702 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 703 | (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d); |
| 704 | } |
| 705 | |
| 706 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 707 | class OutA, class OutB, class OutC, class OutD> |
| 708 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 709 | const Tuple4<InA, InB, InC, InD>& in, |
| 710 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 711 | (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d); |
| 712 | } |
| 713 | |
| 714 | template<class ObjT, class Method, |
| 715 | class InA, class InB, class InC, class InD, class InE, |
| 716 | class OutA, class OutB, class OutC, class OutD> |
| 717 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 718 | const Tuple5<InA, InB, InC, InD, InE>& in, |
| 719 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 720 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, |
| 721 | &out->a, &out->b, &out->c, &out->d); |
| 722 | } |
| 723 | |
[email protected] | 8a2820a | 2008-10-09 21:58:05 | [diff] [blame^] | 724 | template<class ObjT, class Method, |
| 725 | class InA, class InB, class InC, class InD, class InE, class InF, |
| 726 | class OutA, class OutB, class OutC, class OutD> |
| 727 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 728 | const Tuple6<InA, InB, InC, InD, InE, InF>& in, |
| 729 | Tuple4<OutA, OutB, OutC, OutD>* out) { |
| 730 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, |
| 731 | &out->a, &out->b, &out->c, &out->d); |
| 732 | } |
| 733 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 734 | // Dispatchers with 5 out params. |
| 735 | |
| 736 | template<class ObjT, class Method, |
| 737 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 738 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 739 | const Tuple0& in, |
| 740 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 741 | (obj->*method)(&out->a, &out->b, &out->c, &out->d, &out->e); |
| 742 | } |
| 743 | |
| 744 | template<class ObjT, class Method, class InA, |
| 745 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 746 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 747 | const InA& in, |
| 748 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 749 | (obj->*method)(in, &out->a, &out->b, &out->c, &out->d, &out->e); |
| 750 | } |
| 751 | |
| 752 | template<class ObjT, class Method, class InA, |
| 753 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 754 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 755 | const Tuple1<InA>& in, |
| 756 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 757 | (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d, &out->e); |
| 758 | } |
| 759 | |
| 760 | template<class ObjT, class Method, class InA, class InB, |
| 761 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 762 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 763 | const Tuple2<InA, InB>& in, |
| 764 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 765 | (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d, &out->e); |
| 766 | } |
| 767 | |
| 768 | template<class ObjT, class Method, class InA, class InB, class InC, |
| 769 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 770 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 771 | const Tuple3<InA, InB, InC>& in, |
| 772 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 773 | (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d, &out->e); |
| 774 | } |
| 775 | |
| 776 | template<class ObjT, class Method, class InA, class InB, class InC, class InD, |
| 777 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 778 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 779 | const Tuple4<InA, InB, InC, InD>& in, |
| 780 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 781 | (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d, |
| 782 | &out->e); |
| 783 | } |
| 784 | |
| 785 | template<class ObjT, class Method, |
| 786 | class InA, class InB, class InC, class InD, class InE, |
| 787 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 788 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 789 | const Tuple5<InA, InB, InC, InD, InE>& in, |
| 790 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 791 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, |
| 792 | &out->a, &out->b, &out->c, &out->d, &out->e); |
| 793 | } |
| 794 | |
[email protected] | 8a2820a | 2008-10-09 21:58:05 | [diff] [blame^] | 795 | template<class ObjT, class Method, |
| 796 | class InA, class InB, class InC, class InD, class InE, class InF, |
| 797 | class OutA, class OutB, class OutC, class OutD, class OutE> |
| 798 | inline void DispatchToMethod(ObjT* obj, Method method, |
| 799 | const Tuple6<InA, InB, InC, InD, InE, InF>& in, |
| 800 | Tuple5<OutA, OutB, OutC, OutD, OutE>* out) { |
| 801 | (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, |
| 802 | &out->a, &out->b, &out->c, &out->d, &out->e); |
| 803 | } |
| 804 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 805 | #endif // BASE_TUPLE_H__ |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 806 | |