ipc/chromium/src/base/tuple.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 // A Tuple is a generic templatized container, similar in concept to std::pair.
michael@0 6 // There are classes Tuple0 to Tuple6, cooresponding to the number of elements
michael@0 7 // it contains. The convenient MakeTuple() function takes 0 to 6 arguments,
michael@0 8 // and will construct and return the appropriate Tuple object. The functions
michael@0 9 // DispatchToMethod and DispatchToFunction take a function pointer or instance
michael@0 10 // and method pointer, and unpack a tuple into arguments to the call.
michael@0 11 //
michael@0 12 // Tuple elements are copied by value, and stored in the tuple. See the unit
michael@0 13 // tests for more details of how/when the values are copied.
michael@0 14 //
michael@0 15 // Example usage:
michael@0 16 // // These two methods of creating a Tuple are identical.
michael@0 17 // Tuple2<int, const char*> tuple_a(1, "wee");
michael@0 18 // Tuple2<int, const char*> tuple_b = MakeTuple(1, "wee");
michael@0 19 //
michael@0 20 // void SomeFunc(int a, const char* b) { }
michael@0 21 // DispatchToFunction(&SomeFunc, tuple_a); // SomeFunc(1, "wee")
michael@0 22 // DispatchToFunction(
michael@0 23 // &SomeFunc, MakeTuple(10, "foo")); // SomeFunc(10, "foo")
michael@0 24 //
michael@0 25 // struct { void SomeMeth(int a, int b, int c) { } } foo;
michael@0 26 // DispatchToMethod(&foo, &Foo::SomeMeth, MakeTuple(1, 2, 3));
michael@0 27 // // foo->SomeMeth(1, 2, 3);
michael@0 28
michael@0 29 #ifndef BASE_TUPLE_H__
michael@0 30 #define BASE_TUPLE_H__
michael@0 31
michael@0 32 // Traits ----------------------------------------------------------------------
michael@0 33 //
michael@0 34 // A simple traits class for tuple arguments.
michael@0 35 //
michael@0 36 // ValueType: the bare, nonref version of a type (same as the type for nonrefs).
michael@0 37 // RefType: the ref version of a type (same as the type for refs).
michael@0 38 // ParamType: what type to pass to functions (refs should not be constified).
michael@0 39
michael@0 40 template <class P>
michael@0 41 struct TupleTraits {
michael@0 42 typedef P ValueType;
michael@0 43 typedef P& RefType;
michael@0 44 typedef const P& ParamType;
michael@0 45 };
michael@0 46
michael@0 47 template <class P>
michael@0 48 struct TupleTraits<P&> {
michael@0 49 typedef P ValueType;
michael@0 50 typedef P& RefType;
michael@0 51 typedef P& ParamType;
michael@0 52 };
michael@0 53
michael@0 54 // Tuple -----------------------------------------------------------------------
michael@0 55 //
michael@0 56 // This set of classes is useful for bundling 0 or more heterogeneous data types
michael@0 57 // into a single variable. The advantage of this is that it greatly simplifies
michael@0 58 // function objects that need to take an arbitrary number of parameters; see
michael@0 59 // RunnableMethod and IPC::MessageWithTuple.
michael@0 60 //
michael@0 61 // Tuple0 is supplied to act as a 'void' type. It can be used, for example,
michael@0 62 // when dispatching to a function that accepts no arguments (see the
michael@0 63 // Dispatchers below).
michael@0 64 // Tuple1<A> is rarely useful. One such use is when A is non-const ref that you
michael@0 65 // want filled by the dispatchee, and the tuple is merely a container for that
michael@0 66 // output (a "tier"). See MakeRefTuple and its usages.
michael@0 67
michael@0 68 struct Tuple0 {
michael@0 69 typedef Tuple0 ValueTuple;
michael@0 70 typedef Tuple0 RefTuple;
michael@0 71 };
michael@0 72
michael@0 73 template <class A>
michael@0 74 struct Tuple1 {
michael@0 75 public:
michael@0 76 typedef A TypeA;
michael@0 77 typedef Tuple1<typename TupleTraits<A>::ValueType> ValueTuple;
michael@0 78 typedef Tuple1<typename TupleTraits<A>::RefType> RefTuple;
michael@0 79
michael@0 80 Tuple1() {}
michael@0 81 explicit Tuple1(typename TupleTraits<A>::ParamType a) : a(a) {}
michael@0 82
michael@0 83 A a;
michael@0 84 };
michael@0 85
michael@0 86 template <class A, class B>
michael@0 87 struct Tuple2 {
michael@0 88 public:
michael@0 89 typedef A TypeA;
michael@0 90 typedef B TypeB;
michael@0 91 typedef Tuple2<typename TupleTraits<A>::ValueType,
michael@0 92 typename TupleTraits<B>::ValueType> ValueTuple;
michael@0 93 typedef Tuple2<typename TupleTraits<A>::RefType,
michael@0 94 typename TupleTraits<B>::RefType> RefTuple;
michael@0 95
michael@0 96 Tuple2() {}
michael@0 97 Tuple2(typename TupleTraits<A>::ParamType a,
michael@0 98 typename TupleTraits<B>::ParamType b)
michael@0 99 : a(a), b(b) {
michael@0 100 }
michael@0 101
michael@0 102 A a;
michael@0 103 B b;
michael@0 104 };
michael@0 105
michael@0 106 template <class A, class B, class C>
michael@0 107 struct Tuple3 {
michael@0 108 public:
michael@0 109 typedef A TypeA;
michael@0 110 typedef B TypeB;
michael@0 111 typedef C TypeC;
michael@0 112 typedef Tuple3<typename TupleTraits<A>::ValueType,
michael@0 113 typename TupleTraits<B>::ValueType,
michael@0 114 typename TupleTraits<C>::ValueType> ValueTuple;
michael@0 115 typedef Tuple3<typename TupleTraits<A>::RefType,
michael@0 116 typename TupleTraits<B>::RefType,
michael@0 117 typename TupleTraits<C>::RefType> RefTuple;
michael@0 118
michael@0 119 Tuple3() {}
michael@0 120 Tuple3(typename TupleTraits<A>::ParamType a,
michael@0 121 typename TupleTraits<B>::ParamType b,
michael@0 122 typename TupleTraits<C>::ParamType c)
michael@0 123 : a(a), b(b), c(c){
michael@0 124 }
michael@0 125
michael@0 126 A a;
michael@0 127 B b;
michael@0 128 C c;
michael@0 129 };
michael@0 130
michael@0 131 template <class A, class B, class C, class D>
michael@0 132 struct Tuple4 {
michael@0 133 public:
michael@0 134 typedef A TypeA;
michael@0 135 typedef B TypeB;
michael@0 136 typedef C TypeC;
michael@0 137 typedef D TypeD;
michael@0 138 typedef Tuple4<typename TupleTraits<A>::ValueType,
michael@0 139 typename TupleTraits<B>::ValueType,
michael@0 140 typename TupleTraits<C>::ValueType,
michael@0 141 typename TupleTraits<D>::ValueType> ValueTuple;
michael@0 142 typedef Tuple4<typename TupleTraits<A>::RefType,
michael@0 143 typename TupleTraits<B>::RefType,
michael@0 144 typename TupleTraits<C>::RefType,
michael@0 145 typename TupleTraits<D>::RefType> RefTuple;
michael@0 146
michael@0 147 Tuple4() {}
michael@0 148 Tuple4(typename TupleTraits<A>::ParamType a,
michael@0 149 typename TupleTraits<B>::ParamType b,
michael@0 150 typename TupleTraits<C>::ParamType c,
michael@0 151 typename TupleTraits<D>::ParamType d)
michael@0 152 : a(a), b(b), c(c), d(d) {
michael@0 153 }
michael@0 154
michael@0 155 A a;
michael@0 156 B b;
michael@0 157 C c;
michael@0 158 D d;
michael@0 159 };
michael@0 160
michael@0 161 template <class A, class B, class C, class D, class E>
michael@0 162 struct Tuple5 {
michael@0 163 public:
michael@0 164 typedef A TypeA;
michael@0 165 typedef B TypeB;
michael@0 166 typedef C TypeC;
michael@0 167 typedef D TypeD;
michael@0 168 typedef E TypeE;
michael@0 169 typedef Tuple5<typename TupleTraits<A>::ValueType,
michael@0 170 typename TupleTraits<B>::ValueType,
michael@0 171 typename TupleTraits<C>::ValueType,
michael@0 172 typename TupleTraits<D>::ValueType,
michael@0 173 typename TupleTraits<E>::ValueType> ValueTuple;
michael@0 174 typedef Tuple5<typename TupleTraits<A>::RefType,
michael@0 175 typename TupleTraits<B>::RefType,
michael@0 176 typename TupleTraits<C>::RefType,
michael@0 177 typename TupleTraits<D>::RefType,
michael@0 178 typename TupleTraits<E>::RefType> RefTuple;
michael@0 179
michael@0 180 Tuple5() {}
michael@0 181 Tuple5(typename TupleTraits<A>::ParamType a,
michael@0 182 typename TupleTraits<B>::ParamType b,
michael@0 183 typename TupleTraits<C>::ParamType c,
michael@0 184 typename TupleTraits<D>::ParamType d,
michael@0 185 typename TupleTraits<E>::ParamType e)
michael@0 186 : a(a), b(b), c(c), d(d), e(e) {
michael@0 187 }
michael@0 188
michael@0 189 A a;
michael@0 190 B b;
michael@0 191 C c;
michael@0 192 D d;
michael@0 193 E e;
michael@0 194 };
michael@0 195
michael@0 196 template <class A, class B, class C, class D, class E, class F>
michael@0 197 struct Tuple6 {
michael@0 198 public:
michael@0 199 typedef A TypeA;
michael@0 200 typedef B TypeB;
michael@0 201 typedef C TypeC;
michael@0 202 typedef D TypeD;
michael@0 203 typedef E TypeE;
michael@0 204 typedef F TypeF;
michael@0 205 typedef Tuple6<typename TupleTraits<A>::ValueType,
michael@0 206 typename TupleTraits<B>::ValueType,
michael@0 207 typename TupleTraits<C>::ValueType,
michael@0 208 typename TupleTraits<D>::ValueType,
michael@0 209 typename TupleTraits<E>::ValueType,
michael@0 210 typename TupleTraits<F>::ValueType> ValueTuple;
michael@0 211 typedef Tuple6<typename TupleTraits<A>::RefType,
michael@0 212 typename TupleTraits<B>::RefType,
michael@0 213 typename TupleTraits<C>::RefType,
michael@0 214 typename TupleTraits<D>::RefType,
michael@0 215 typename TupleTraits<E>::RefType,
michael@0 216 typename TupleTraits<F>::RefType> RefTuple;
michael@0 217
michael@0 218 Tuple6() {}
michael@0 219 Tuple6(typename TupleTraits<A>::ParamType a,
michael@0 220 typename TupleTraits<B>::ParamType b,
michael@0 221 typename TupleTraits<C>::ParamType c,
michael@0 222 typename TupleTraits<D>::ParamType d,
michael@0 223 typename TupleTraits<E>::ParamType e,
michael@0 224 typename TupleTraits<F>::ParamType f)
michael@0 225 : a(a), b(b), c(c), d(d), e(e), f(f) {
michael@0 226 }
michael@0 227
michael@0 228 A a;
michael@0 229 B b;
michael@0 230 C c;
michael@0 231 D d;
michael@0 232 E e;
michael@0 233 F f;
michael@0 234 };
michael@0 235
michael@0 236 template <class A, class B, class C, class D, class E, class F, class G>
michael@0 237 struct Tuple7 {
michael@0 238 public:
michael@0 239 typedef A TypeA;
michael@0 240 typedef B TypeB;
michael@0 241 typedef C TypeC;
michael@0 242 typedef D TypeD;
michael@0 243 typedef E TypeE;
michael@0 244 typedef F TypeF;
michael@0 245 typedef G TypeG;
michael@0 246 typedef Tuple7<typename TupleTraits<A>::ValueType,
michael@0 247 typename TupleTraits<B>::ValueType,
michael@0 248 typename TupleTraits<C>::ValueType,
michael@0 249 typename TupleTraits<D>::ValueType,
michael@0 250 typename TupleTraits<E>::ValueType,
michael@0 251 typename TupleTraits<F>::ValueType,
michael@0 252 typename TupleTraits<G>::ValueType> ValueTuple;
michael@0 253 typedef Tuple7<typename TupleTraits<A>::RefType,
michael@0 254 typename TupleTraits<B>::RefType,
michael@0 255 typename TupleTraits<C>::RefType,
michael@0 256 typename TupleTraits<D>::RefType,
michael@0 257 typename TupleTraits<E>::RefType,
michael@0 258 typename TupleTraits<F>::RefType,
michael@0 259 typename TupleTraits<G>::RefType> RefTuple;
michael@0 260
michael@0 261 Tuple7() {}
michael@0 262 Tuple7(typename TupleTraits<A>::ParamType a,
michael@0 263 typename TupleTraits<B>::ParamType b,
michael@0 264 typename TupleTraits<C>::ParamType c,
michael@0 265 typename TupleTraits<D>::ParamType d,
michael@0 266 typename TupleTraits<E>::ParamType e,
michael@0 267 typename TupleTraits<F>::ParamType f,
michael@0 268 typename TupleTraits<G>::ParamType g)
michael@0 269 : a(a), b(b), c(c), d(d), e(e), f(f), g(g) {
michael@0 270 }
michael@0 271
michael@0 272 A a;
michael@0 273 B b;
michael@0 274 C c;
michael@0 275 D d;
michael@0 276 E e;
michael@0 277 F f;
michael@0 278 G g;
michael@0 279 };
michael@0 280
michael@0 281 // Tuple creators -------------------------------------------------------------
michael@0 282 //
michael@0 283 // Helper functions for constructing tuples while inferring the template
michael@0 284 // argument types.
michael@0 285
michael@0 286 inline Tuple0 MakeTuple() {
michael@0 287 return Tuple0();
michael@0 288 }
michael@0 289
michael@0 290 template <class A>
michael@0 291 inline Tuple1<A> MakeTuple(const A& a) {
michael@0 292 return Tuple1<A>(a);
michael@0 293 }
michael@0 294
michael@0 295 template <class A, class B>
michael@0 296 inline Tuple2<A, B> MakeTuple(const A& a, const B& b) {
michael@0 297 return Tuple2<A, B>(a, b);
michael@0 298 }
michael@0 299
michael@0 300 template <class A, class B, class C>
michael@0 301 inline Tuple3<A, B, C> MakeTuple(const A& a, const B& b, const C& c) {
michael@0 302 return Tuple3<A, B, C>(a, b, c);
michael@0 303 }
michael@0 304
michael@0 305 template <class A, class B, class C, class D>
michael@0 306 inline Tuple4<A, B, C, D> MakeTuple(const A& a, const B& b, const C& c,
michael@0 307 const D& d) {
michael@0 308 return Tuple4<A, B, C, D>(a, b, c, d);
michael@0 309 }
michael@0 310
michael@0 311 template <class A, class B, class C, class D, class E>
michael@0 312 inline Tuple5<A, B, C, D, E> MakeTuple(const A& a, const B& b, const C& c,
michael@0 313 const D& d, const E& e) {
michael@0 314 return Tuple5<A, B, C, D, E>(a, b, c, d, e);
michael@0 315 }
michael@0 316
michael@0 317 template <class A, class B, class C, class D, class E, class F>
michael@0 318 inline Tuple6<A, B, C, D, E, F> MakeTuple(const A& a, const B& b, const C& c,
michael@0 319 const D& d, const E& e, const F& f) {
michael@0 320 return Tuple6<A, B, C, D, E, F>(a, b, c, d, e, f);
michael@0 321 }
michael@0 322
michael@0 323 template <class A, class B, class C, class D, class E, class F, class G>
michael@0 324 inline Tuple7<A, B, C, D, E, F, G> MakeTuple(const A& a, const B& b, const C& c,
michael@0 325 const D& d, const E& e, const F& f,
michael@0 326 const G& g) {
michael@0 327 return Tuple7<A, B, C, D, E, F, G>(a, b, c, d, e, f, g);
michael@0 328 }
michael@0 329
michael@0 330 // The following set of helpers make what Boost refers to as "Tiers" - a tuple
michael@0 331 // of references.
michael@0 332
michael@0 333 template <class A>
michael@0 334 inline Tuple1<A&> MakeRefTuple(A& a) {
michael@0 335 return Tuple1<A&>(a);
michael@0 336 }
michael@0 337
michael@0 338 template <class A, class B>
michael@0 339 inline Tuple2<A&, B&> MakeRefTuple(A& a, B& b) {
michael@0 340 return Tuple2<A&, B&>(a, b);
michael@0 341 }
michael@0 342
michael@0 343 template <class A, class B, class C>
michael@0 344 inline Tuple3<A&, B&, C&> MakeRefTuple(A& a, B& b, C& c) {
michael@0 345 return Tuple3<A&, B&, C&>(a, b, c);
michael@0 346 }
michael@0 347
michael@0 348 template <class A, class B, class C, class D>
michael@0 349 inline Tuple4<A&, B&, C&, D&> MakeRefTuple(A& a, B& b, C& c, D& d) {
michael@0 350 return Tuple4<A&, B&, C&, D&>(a, b, c, d);
michael@0 351 }
michael@0 352
michael@0 353 template <class A, class B, class C, class D, class E>
michael@0 354 inline Tuple5<A&, B&, C&, D&, E&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e) {
michael@0 355 return Tuple5<A&, B&, C&, D&, E&>(a, b, c, d, e);
michael@0 356 }
michael@0 357
michael@0 358 template <class A, class B, class C, class D, class E, class F>
michael@0 359 inline Tuple6<A&, B&, C&, D&, E&, F&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e,
michael@0 360 F& f) {
michael@0 361 return Tuple6<A&, B&, C&, D&, E&, F&>(a, b, c, d, e, f);
michael@0 362 }
michael@0 363
michael@0 364 template <class A, class B, class C, class D, class E, class F, class G>
michael@0 365 inline Tuple7<A&, B&, C&, D&, E&, F&, G&> MakeRefTuple(A& a, B& b, C& c, D& d,
michael@0 366 E& e, F& f, G& g) {
michael@0 367 return Tuple7<A&, B&, C&, D&, E&, F&, G&>(a, b, c, d, e, f, g);
michael@0 368 }
michael@0 369
michael@0 370 // Dispatchers ----------------------------------------------------------------
michael@0 371 //
michael@0 372 // Helper functions that call the given method on an object, with the unpacked
michael@0 373 // tuple arguments. Notice that they all have the same number of arguments,
michael@0 374 // so you need only write:
michael@0 375 // DispatchToMethod(object, &Object::method, args);
michael@0 376 // This is very useful for templated dispatchers, since they don't need to know
michael@0 377 // what type |args| is.
michael@0 378
michael@0 379 // Non-Static Dispatchers with no out params.
michael@0 380
michael@0 381 template <class ObjT, class Method>
michael@0 382 inline void DispatchToMethod(ObjT* obj, Method method, const Tuple0& arg) {
michael@0 383 (obj->*method)();
michael@0 384 }
michael@0 385
michael@0 386 template <class ObjT, class Method, class A>
michael@0 387 inline void DispatchToMethod(ObjT* obj, Method method, const A& arg) {
michael@0 388 (obj->*method)(arg);
michael@0 389 }
michael@0 390
michael@0 391 template <class ObjT, class Method, class A>
michael@0 392 inline void DispatchToMethod(ObjT* obj, Method method, const Tuple1<A>& arg) {
michael@0 393 (obj->*method)(arg.a);
michael@0 394 }
michael@0 395
michael@0 396 template<class ObjT, class Method, class A, class B>
michael@0 397 inline void DispatchToMethod(ObjT* obj,
michael@0 398 Method method,
michael@0 399 const Tuple2<A, B>& arg) {
michael@0 400 (obj->*method)(arg.a, arg.b);
michael@0 401 }
michael@0 402
michael@0 403 template<class ObjT, class Method, class A, class B, class C>
michael@0 404 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 405 const Tuple3<A, B, C>& arg) {
michael@0 406 (obj->*method)(arg.a, arg.b, arg.c);
michael@0 407 }
michael@0 408
michael@0 409 template<class ObjT, class Method, class A, class B, class C, class D>
michael@0 410 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 411 const Tuple4<A, B, C, D>& arg) {
michael@0 412 (obj->*method)(arg.a, arg.b, arg.c, arg.d);
michael@0 413 }
michael@0 414
michael@0 415 template<class ObjT, class Method, class A, class B, class C, class D, class E>
michael@0 416 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 417 const Tuple5<A, B, C, D, E>& arg) {
michael@0 418 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e);
michael@0 419 }
michael@0 420
michael@0 421 template<class ObjT, class Method, class A, class B, class C, class D, class E,
michael@0 422 class F>
michael@0 423 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 424 const Tuple6<A, B, C, D, E, F>& arg) {
michael@0 425 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
michael@0 426 }
michael@0 427
michael@0 428 template<class ObjT, class Method, class A, class B, class C, class D, class E,
michael@0 429 class F, class G>
michael@0 430 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 431 const Tuple7<A, B, C, D, E, F, G>& arg) {
michael@0 432 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g);
michael@0 433 }
michael@0 434
michael@0 435 // Static Dispatchers with no out params.
michael@0 436
michael@0 437 template <class Function>
michael@0 438 inline void DispatchToFunction(Function function, const Tuple0& arg) {
michael@0 439 (*function)();
michael@0 440 }
michael@0 441
michael@0 442 template <class Function, class A>
michael@0 443 inline void DispatchToFunction(Function function, const A& arg) {
michael@0 444 (*function)(arg);
michael@0 445 }
michael@0 446
michael@0 447 template <class Function, class A>
michael@0 448 inline void DispatchToFunction(Function function, const Tuple1<A>& arg) {
michael@0 449 (*function)(arg.a);
michael@0 450 }
michael@0 451
michael@0 452 template<class Function, class A, class B>
michael@0 453 inline void DispatchToFunction(Function function, const Tuple2<A, B>& arg) {
michael@0 454 (*function)(arg.a, arg.b);
michael@0 455 }
michael@0 456
michael@0 457 template<class Function, class A, class B, class C>
michael@0 458 inline void DispatchToFunction(Function function, const Tuple3<A, B, C>& arg) {
michael@0 459 (*function)(arg.a, arg.b, arg.c);
michael@0 460 }
michael@0 461
michael@0 462 template<class Function, class A, class B, class C, class D>
michael@0 463 inline void DispatchToFunction(Function function,
michael@0 464 const Tuple4<A, B, C, D>& arg) {
michael@0 465 (*function)(arg.a, arg.b, arg.c, arg.d);
michael@0 466 }
michael@0 467
michael@0 468 template<class Function, class A, class B, class C, class D, class E>
michael@0 469 inline void DispatchToFunction(Function function,
michael@0 470 const Tuple5<A, B, C, D, E>& arg) {
michael@0 471 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e);
michael@0 472 }
michael@0 473
michael@0 474 template<class Function, class A, class B, class C, class D, class E, class F>
michael@0 475 inline void DispatchToFunction(Function function,
michael@0 476 const Tuple6<A, B, C, D, E, F>& arg) {
michael@0 477 (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
michael@0 478 }
michael@0 479
michael@0 480 // Dispatchers with 0 out param (as a Tuple0).
michael@0 481
michael@0 482 template <class ObjT, class Method>
michael@0 483 inline void DispatchToMethod(ObjT* obj,
michael@0 484 Method method,
michael@0 485 const Tuple0& arg, Tuple0*) {
michael@0 486 (obj->*method)();
michael@0 487 }
michael@0 488
michael@0 489 template <class ObjT, class Method, class A>
michael@0 490 inline void DispatchToMethod(ObjT* obj, Method method, const A& arg, Tuple0*) {
michael@0 491 (obj->*method)(arg);
michael@0 492 }
michael@0 493
michael@0 494 template <class ObjT, class Method, class A>
michael@0 495 inline void DispatchToMethod(ObjT* obj,
michael@0 496 Method method,
michael@0 497 const Tuple1<A>& arg, Tuple0*) {
michael@0 498 (obj->*method)(arg.a);
michael@0 499 }
michael@0 500
michael@0 501 template<class ObjT, class Method, class A, class B>
michael@0 502 inline void DispatchToMethod(ObjT* obj,
michael@0 503 Method method,
michael@0 504 const Tuple2<A, B>& arg, Tuple0*) {
michael@0 505 (obj->*method)(arg.a, arg.b);
michael@0 506 }
michael@0 507
michael@0 508 template<class ObjT, class Method, class A, class B, class C>
michael@0 509 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 510 const Tuple3<A, B, C>& arg, Tuple0*) {
michael@0 511 (obj->*method)(arg.a, arg.b, arg.c);
michael@0 512 }
michael@0 513
michael@0 514 template<class ObjT, class Method, class A, class B, class C, class D>
michael@0 515 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 516 const Tuple4<A, B, C, D>& arg, Tuple0*) {
michael@0 517 (obj->*method)(arg.a, arg.b, arg.c, arg.d);
michael@0 518 }
michael@0 519
michael@0 520 template<class ObjT, class Method, class A, class B, class C, class D, class E>
michael@0 521 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 522 const Tuple5<A, B, C, D, E>& arg, Tuple0*) {
michael@0 523 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e);
michael@0 524 }
michael@0 525
michael@0 526 template<class ObjT, class Method, class A, class B, class C, class D, class E,
michael@0 527 class F>
michael@0 528 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 529 const Tuple6<A, B, C, D, E, F>& arg, Tuple0*) {
michael@0 530 (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
michael@0 531 }
michael@0 532
michael@0 533 // Dispatchers with 1 out param.
michael@0 534
michael@0 535 template<class ObjT, class Method,
michael@0 536 class OutA>
michael@0 537 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 538 const Tuple0& in,
michael@0 539 Tuple1<OutA>* out) {
michael@0 540 (obj->*method)(&out->a);
michael@0 541 }
michael@0 542
michael@0 543 template<class ObjT, class Method, class InA,
michael@0 544 class OutA>
michael@0 545 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 546 const InA& in,
michael@0 547 Tuple1<OutA>* out) {
michael@0 548 (obj->*method)(in, &out->a);
michael@0 549 }
michael@0 550
michael@0 551 template<class ObjT, class Method, class InA,
michael@0 552 class OutA>
michael@0 553 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 554 const Tuple1<InA>& in,
michael@0 555 Tuple1<OutA>* out) {
michael@0 556 (obj->*method)(in.a, &out->a);
michael@0 557 }
michael@0 558
michael@0 559 template<class ObjT, class Method, class InA, class InB,
michael@0 560 class OutA>
michael@0 561 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 562 const Tuple2<InA, InB>& in,
michael@0 563 Tuple1<OutA>* out) {
michael@0 564 (obj->*method)(in.a, in.b, &out->a);
michael@0 565 }
michael@0 566
michael@0 567 template<class ObjT, class Method, class InA, class InB, class InC,
michael@0 568 class OutA>
michael@0 569 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 570 const Tuple3<InA, InB, InC>& in,
michael@0 571 Tuple1<OutA>* out) {
michael@0 572 (obj->*method)(in.a, in.b, in.c, &out->a);
michael@0 573 }
michael@0 574
michael@0 575 template<class ObjT, class Method, class InA, class InB, class InC, class InD,
michael@0 576 class OutA>
michael@0 577 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 578 const Tuple4<InA, InB, InC, InD>& in,
michael@0 579 Tuple1<OutA>* out) {
michael@0 580 (obj->*method)(in.a, in.b, in.c, in.d, &out->a);
michael@0 581 }
michael@0 582
michael@0 583 template<class ObjT, class Method,
michael@0 584 class InA, class InB, class InC, class InD, class InE,
michael@0 585 class OutA>
michael@0 586 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 587 const Tuple5<InA, InB, InC, InD, InE>& in,
michael@0 588 Tuple1<OutA>* out) {
michael@0 589 (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a);
michael@0 590 }
michael@0 591
michael@0 592 template<class ObjT, class Method,
michael@0 593 class InA, class InB, class InC, class InD, class InE, class InF,
michael@0 594 class OutA>
michael@0 595 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 596 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
michael@0 597 Tuple1<OutA>* out) {
michael@0 598 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a);
michael@0 599 }
michael@0 600
michael@0 601 // Dispatchers with 2 out params.
michael@0 602
michael@0 603 template<class ObjT, class Method,
michael@0 604 class OutA, class OutB>
michael@0 605 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 606 const Tuple0& in,
michael@0 607 Tuple2<OutA, OutB>* out) {
michael@0 608 (obj->*method)(&out->a, &out->b);
michael@0 609 }
michael@0 610
michael@0 611 template<class ObjT, class Method, class InA,
michael@0 612 class OutA, class OutB>
michael@0 613 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 614 const InA& in,
michael@0 615 Tuple2<OutA, OutB>* out) {
michael@0 616 (obj->*method)(in, &out->a, &out->b);
michael@0 617 }
michael@0 618
michael@0 619 template<class ObjT, class Method, class InA,
michael@0 620 class OutA, class OutB>
michael@0 621 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 622 const Tuple1<InA>& in,
michael@0 623 Tuple2<OutA, OutB>* out) {
michael@0 624 (obj->*method)(in.a, &out->a, &out->b);
michael@0 625 }
michael@0 626
michael@0 627 template<class ObjT, class Method, class InA, class InB,
michael@0 628 class OutA, class OutB>
michael@0 629 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 630 const Tuple2<InA, InB>& in,
michael@0 631 Tuple2<OutA, OutB>* out) {
michael@0 632 (obj->*method)(in.a, in.b, &out->a, &out->b);
michael@0 633 }
michael@0 634
michael@0 635 template<class ObjT, class Method, class InA, class InB, class InC,
michael@0 636 class OutA, class OutB>
michael@0 637 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 638 const Tuple3<InA, InB, InC>& in,
michael@0 639 Tuple2<OutA, OutB>* out) {
michael@0 640 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b);
michael@0 641 }
michael@0 642
michael@0 643 template<class ObjT, class Method, class InA, class InB, class InC, class InD,
michael@0 644 class OutA, class OutB>
michael@0 645 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 646 const Tuple4<InA, InB, InC, InD>& in,
michael@0 647 Tuple2<OutA, OutB>* out) {
michael@0 648 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b);
michael@0 649 }
michael@0 650
michael@0 651 template<class ObjT, class Method,
michael@0 652 class InA, class InB, class InC, class InD, class InE,
michael@0 653 class OutA, class OutB>
michael@0 654 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 655 const Tuple5<InA, InB, InC, InD, InE>& in,
michael@0 656 Tuple2<OutA, OutB>* out) {
michael@0 657 (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b);
michael@0 658 }
michael@0 659
michael@0 660 template<class ObjT, class Method,
michael@0 661 class InA, class InB, class InC, class InD, class InE, class InF,
michael@0 662 class OutA, class OutB>
michael@0 663 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 664 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
michael@0 665 Tuple2<OutA, OutB>* out) {
michael@0 666 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b);
michael@0 667 }
michael@0 668
michael@0 669 // Dispatchers with 3 out params.
michael@0 670
michael@0 671 template<class ObjT, class Method,
michael@0 672 class OutA, class OutB, class OutC>
michael@0 673 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 674 const Tuple0& in,
michael@0 675 Tuple3<OutA, OutB, OutC>* out) {
michael@0 676 (obj->*method)(&out->a, &out->b, &out->c);
michael@0 677 }
michael@0 678
michael@0 679 template<class ObjT, class Method, class InA,
michael@0 680 class OutA, class OutB, class OutC>
michael@0 681 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 682 const InA& in,
michael@0 683 Tuple3<OutA, OutB, OutC>* out) {
michael@0 684 (obj->*method)(in, &out->a, &out->b, &out->c);
michael@0 685 }
michael@0 686
michael@0 687 template<class ObjT, class Method, class InA,
michael@0 688 class OutA, class OutB, class OutC>
michael@0 689 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 690 const Tuple1<InA>& in,
michael@0 691 Tuple3<OutA, OutB, OutC>* out) {
michael@0 692 (obj->*method)(in.a, &out->a, &out->b, &out->c);
michael@0 693 }
michael@0 694
michael@0 695 template<class ObjT, class Method, class InA, class InB,
michael@0 696 class OutA, class OutB, class OutC>
michael@0 697 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 698 const Tuple2<InA, InB>& in,
michael@0 699 Tuple3<OutA, OutB, OutC>* out) {
michael@0 700 (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c);
michael@0 701 }
michael@0 702
michael@0 703 template<class ObjT, class Method, class InA, class InB, class InC,
michael@0 704 class OutA, class OutB, class OutC>
michael@0 705 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 706 const Tuple3<InA, InB, InC>& in,
michael@0 707 Tuple3<OutA, OutB, OutC>* out) {
michael@0 708 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c);
michael@0 709 }
michael@0 710
michael@0 711 template<class ObjT, class Method, class InA, class InB, class InC, class InD,
michael@0 712 class OutA, class OutB, class OutC>
michael@0 713 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 714 const Tuple4<InA, InB, InC, InD>& in,
michael@0 715 Tuple3<OutA, OutB, OutC>* out) {
michael@0 716 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c);
michael@0 717 }
michael@0 718
michael@0 719 template<class ObjT, class Method,
michael@0 720 class InA, class InB, class InC, class InD, class InE,
michael@0 721 class OutA, class OutB, class OutC>
michael@0 722 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 723 const Tuple5<InA, InB, InC, InD, InE>& in,
michael@0 724 Tuple3<OutA, OutB, OutC>* out) {
michael@0 725 (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b, &out->c);
michael@0 726 }
michael@0 727
michael@0 728 template<class ObjT, class Method,
michael@0 729 class InA, class InB, class InC, class InD, class InE, class InF,
michael@0 730 class OutA, class OutB, class OutC>
michael@0 731 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 732 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
michael@0 733 Tuple3<OutA, OutB, OutC>* out) {
michael@0 734 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b, &out->c);
michael@0 735 }
michael@0 736
michael@0 737 // Dispatchers with 4 out params.
michael@0 738
michael@0 739 template<class ObjT, class Method,
michael@0 740 class OutA, class OutB, class OutC, class OutD>
michael@0 741 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 742 const Tuple0& in,
michael@0 743 Tuple4<OutA, OutB, OutC, OutD>* out) {
michael@0 744 (obj->*method)(&out->a, &out->b, &out->c, &out->d);
michael@0 745 }
michael@0 746
michael@0 747 template<class ObjT, class Method, class InA,
michael@0 748 class OutA, class OutB, class OutC, class OutD>
michael@0 749 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 750 const InA& in,
michael@0 751 Tuple4<OutA, OutB, OutC, OutD>* out) {
michael@0 752 (obj->*method)(in, &out->a, &out->b, &out->c, &out->d);
michael@0 753 }
michael@0 754
michael@0 755 template<class ObjT, class Method, class InA,
michael@0 756 class OutA, class OutB, class OutC, class OutD>
michael@0 757 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 758 const Tuple1<InA>& in,
michael@0 759 Tuple4<OutA, OutB, OutC, OutD>* out) {
michael@0 760 (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d);
michael@0 761 }
michael@0 762
michael@0 763 template<class ObjT, class Method, class InA, class InB,
michael@0 764 class OutA, class OutB, class OutC, class OutD>
michael@0 765 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 766 const Tuple2<InA, InB>& in,
michael@0 767 Tuple4<OutA, OutB, OutC, OutD>* out) {
michael@0 768 (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d);
michael@0 769 }
michael@0 770
michael@0 771 template<class ObjT, class Method, class InA, class InB, class InC,
michael@0 772 class OutA, class OutB, class OutC, class OutD>
michael@0 773 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 774 const Tuple3<InA, InB, InC>& in,
michael@0 775 Tuple4<OutA, OutB, OutC, OutD>* out) {
michael@0 776 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d);
michael@0 777 }
michael@0 778
michael@0 779 template<class ObjT, class Method, class InA, class InB, class InC, class InD,
michael@0 780 class OutA, class OutB, class OutC, class OutD>
michael@0 781 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 782 const Tuple4<InA, InB, InC, InD>& in,
michael@0 783 Tuple4<OutA, OutB, OutC, OutD>* out) {
michael@0 784 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d);
michael@0 785 }
michael@0 786
michael@0 787 template<class ObjT, class Method,
michael@0 788 class InA, class InB, class InC, class InD, class InE,
michael@0 789 class OutA, class OutB, class OutC, class OutD>
michael@0 790 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 791 const Tuple5<InA, InB, InC, InD, InE>& in,
michael@0 792 Tuple4<OutA, OutB, OutC, OutD>* out) {
michael@0 793 (obj->*method)(in.a, in.b, in.c, in.d, in.e,
michael@0 794 &out->a, &out->b, &out->c, &out->d);
michael@0 795 }
michael@0 796
michael@0 797 template<class ObjT, class Method,
michael@0 798 class InA, class InB, class InC, class InD, class InE, class InF,
michael@0 799 class OutA, class OutB, class OutC, class OutD>
michael@0 800 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 801 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
michael@0 802 Tuple4<OutA, OutB, OutC, OutD>* out) {
michael@0 803 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f,
michael@0 804 &out->a, &out->b, &out->c, &out->d);
michael@0 805 }
michael@0 806
michael@0 807 // Dispatchers with 5 out params.
michael@0 808
michael@0 809 template<class ObjT, class Method,
michael@0 810 class OutA, class OutB, class OutC, class OutD, class OutE>
michael@0 811 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 812 const Tuple0& in,
michael@0 813 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
michael@0 814 (obj->*method)(&out->a, &out->b, &out->c, &out->d, &out->e);
michael@0 815 }
michael@0 816
michael@0 817 template<class ObjT, class Method, class InA,
michael@0 818 class OutA, class OutB, class OutC, class OutD, class OutE>
michael@0 819 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 820 const InA& in,
michael@0 821 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
michael@0 822 (obj->*method)(in, &out->a, &out->b, &out->c, &out->d, &out->e);
michael@0 823 }
michael@0 824
michael@0 825 template<class ObjT, class Method, class InA,
michael@0 826 class OutA, class OutB, class OutC, class OutD, class OutE>
michael@0 827 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 828 const Tuple1<InA>& in,
michael@0 829 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
michael@0 830 (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d, &out->e);
michael@0 831 }
michael@0 832
michael@0 833 template<class ObjT, class Method, class InA, class InB,
michael@0 834 class OutA, class OutB, class OutC, class OutD, class OutE>
michael@0 835 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 836 const Tuple2<InA, InB>& in,
michael@0 837 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
michael@0 838 (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d, &out->e);
michael@0 839 }
michael@0 840
michael@0 841 template<class ObjT, class Method, class InA, class InB, class InC,
michael@0 842 class OutA, class OutB, class OutC, class OutD, class OutE>
michael@0 843 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 844 const Tuple3<InA, InB, InC>& in,
michael@0 845 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
michael@0 846 (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d, &out->e);
michael@0 847 }
michael@0 848
michael@0 849 template<class ObjT, class Method, class InA, class InB, class InC, class InD,
michael@0 850 class OutA, class OutB, class OutC, class OutD, class OutE>
michael@0 851 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 852 const Tuple4<InA, InB, InC, InD>& in,
michael@0 853 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
michael@0 854 (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d,
michael@0 855 &out->e);
michael@0 856 }
michael@0 857
michael@0 858 template<class ObjT, class Method,
michael@0 859 class InA, class InB, class InC, class InD, class InE,
michael@0 860 class OutA, class OutB, class OutC, class OutD, class OutE>
michael@0 861 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 862 const Tuple5<InA, InB, InC, InD, InE>& in,
michael@0 863 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
michael@0 864 (obj->*method)(in.a, in.b, in.c, in.d, in.e,
michael@0 865 &out->a, &out->b, &out->c, &out->d, &out->e);
michael@0 866 }
michael@0 867
michael@0 868 template<class ObjT, class Method,
michael@0 869 class InA, class InB, class InC, class InD, class InE, class InF,
michael@0 870 class OutA, class OutB, class OutC, class OutD, class OutE>
michael@0 871 inline void DispatchToMethod(ObjT* obj, Method method,
michael@0 872 const Tuple6<InA, InB, InC, InD, InE, InF>& in,
michael@0 873 Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
michael@0 874 (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f,
michael@0 875 &out->a, &out->b, &out->c, &out->d, &out->e);
michael@0 876 }
michael@0 877
michael@0 878 #endif // BASE_TUPLE_H__

mercurial