ipc/chromium/src/base/tuple.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/tuple.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,878 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +// A Tuple is a generic templatized container, similar in concept to std::pair.
     1.9 +// There are classes Tuple0 to Tuple6, cooresponding to the number of elements
    1.10 +// it contains.  The convenient MakeTuple() function takes 0 to 6 arguments,
    1.11 +// and will construct and return the appropriate Tuple object.  The functions
    1.12 +// DispatchToMethod and DispatchToFunction take a function pointer or instance
    1.13 +// and method pointer, and unpack a tuple into arguments to the call.
    1.14 +//
    1.15 +// Tuple elements are copied by value, and stored in the tuple.  See the unit
    1.16 +// tests for more details of how/when the values are copied.
    1.17 +//
    1.18 +// Example usage:
    1.19 +//   // These two methods of creating a Tuple are identical.
    1.20 +//   Tuple2<int, const char*> tuple_a(1, "wee");
    1.21 +//   Tuple2<int, const char*> tuple_b = MakeTuple(1, "wee");
    1.22 +//
    1.23 +//   void SomeFunc(int a, const char* b) { }
    1.24 +//   DispatchToFunction(&SomeFunc, tuple_a);  // SomeFunc(1, "wee")
    1.25 +//   DispatchToFunction(
    1.26 +//       &SomeFunc, MakeTuple(10, "foo"));    // SomeFunc(10, "foo")
    1.27 +//
    1.28 +//   struct { void SomeMeth(int a, int b, int c) { } } foo;
    1.29 +//   DispatchToMethod(&foo, &Foo::SomeMeth, MakeTuple(1, 2, 3));
    1.30 +//   // foo->SomeMeth(1, 2, 3);
    1.31 +
    1.32 +#ifndef BASE_TUPLE_H__
    1.33 +#define BASE_TUPLE_H__
    1.34 +
    1.35 +// Traits ----------------------------------------------------------------------
    1.36 +//
    1.37 +// A simple traits class for tuple arguments.
    1.38 +//
    1.39 +// ValueType: the bare, nonref version of a type (same as the type for nonrefs).
    1.40 +// RefType: the ref version of a type (same as the type for refs).
    1.41 +// ParamType: what type to pass to functions (refs should not be constified).
    1.42 +
    1.43 +template <class P>
    1.44 +struct TupleTraits {
    1.45 +  typedef P ValueType;
    1.46 +  typedef P& RefType;
    1.47 +  typedef const P& ParamType;
    1.48 +};
    1.49 +
    1.50 +template <class P>
    1.51 +struct TupleTraits<P&> {
    1.52 +  typedef P ValueType;
    1.53 +  typedef P& RefType;
    1.54 +  typedef P& ParamType;
    1.55 +};
    1.56 +
    1.57 +// Tuple -----------------------------------------------------------------------
    1.58 +//
    1.59 +// This set of classes is useful for bundling 0 or more heterogeneous data types
    1.60 +// into a single variable.  The advantage of this is that it greatly simplifies
    1.61 +// function objects that need to take an arbitrary number of parameters; see
    1.62 +// RunnableMethod and IPC::MessageWithTuple.
    1.63 +//
    1.64 +// Tuple0 is supplied to act as a 'void' type.  It can be used, for example,
    1.65 +// when dispatching to a function that accepts no arguments (see the
    1.66 +// Dispatchers below).
    1.67 +// Tuple1<A> is rarely useful.  One such use is when A is non-const ref that you
    1.68 +// want filled by the dispatchee, and the tuple is merely a container for that
    1.69 +// output (a "tier").  See MakeRefTuple and its usages.
    1.70 +
    1.71 +struct Tuple0 {
    1.72 +  typedef Tuple0 ValueTuple;
    1.73 +  typedef Tuple0 RefTuple;
    1.74 +};
    1.75 +
    1.76 +template <class A>
    1.77 +struct Tuple1 {
    1.78 + public:
    1.79 +  typedef A TypeA;
    1.80 +  typedef Tuple1<typename TupleTraits<A>::ValueType> ValueTuple;
    1.81 +  typedef Tuple1<typename TupleTraits<A>::RefType> RefTuple;
    1.82 +
    1.83 +  Tuple1() {}
    1.84 +  explicit Tuple1(typename TupleTraits<A>::ParamType a) : a(a) {}
    1.85 +
    1.86 +  A a;
    1.87 +};
    1.88 +
    1.89 +template <class A, class B>
    1.90 +struct Tuple2 {
    1.91 + public:
    1.92 +  typedef A TypeA;
    1.93 +  typedef B TypeB;
    1.94 +  typedef Tuple2<typename TupleTraits<A>::ValueType,
    1.95 +                 typename TupleTraits<B>::ValueType> ValueTuple;
    1.96 +  typedef Tuple2<typename TupleTraits<A>::RefType,
    1.97 +                 typename TupleTraits<B>::RefType> RefTuple;
    1.98 +
    1.99 +  Tuple2() {}
   1.100 +  Tuple2(typename TupleTraits<A>::ParamType a,
   1.101 +         typename TupleTraits<B>::ParamType b)
   1.102 +      : a(a), b(b) {
   1.103 +  }
   1.104 +
   1.105 +  A a;
   1.106 +  B b;
   1.107 +};
   1.108 +
   1.109 +template <class A, class B, class C>
   1.110 +struct Tuple3 {
   1.111 + public:
   1.112 +  typedef A TypeA;
   1.113 +  typedef B TypeB;
   1.114 +  typedef C TypeC;
   1.115 +  typedef Tuple3<typename TupleTraits<A>::ValueType,
   1.116 +                 typename TupleTraits<B>::ValueType,
   1.117 +                 typename TupleTraits<C>::ValueType> ValueTuple;
   1.118 +  typedef Tuple3<typename TupleTraits<A>::RefType,
   1.119 +                 typename TupleTraits<B>::RefType,
   1.120 +                 typename TupleTraits<C>::RefType> RefTuple;
   1.121 +
   1.122 +  Tuple3() {}
   1.123 +  Tuple3(typename TupleTraits<A>::ParamType a,
   1.124 +         typename TupleTraits<B>::ParamType b,
   1.125 +         typename TupleTraits<C>::ParamType c)
   1.126 +      : a(a), b(b), c(c){
   1.127 +  }
   1.128 +
   1.129 +  A a;
   1.130 +  B b;
   1.131 +  C c;
   1.132 +};
   1.133 +
   1.134 +template <class A, class B, class C, class D>
   1.135 +struct Tuple4 {
   1.136 + public:
   1.137 +  typedef A TypeA;
   1.138 +  typedef B TypeB;
   1.139 +  typedef C TypeC;
   1.140 +  typedef D TypeD;
   1.141 +  typedef Tuple4<typename TupleTraits<A>::ValueType,
   1.142 +                 typename TupleTraits<B>::ValueType,
   1.143 +                 typename TupleTraits<C>::ValueType,
   1.144 +                 typename TupleTraits<D>::ValueType> ValueTuple;
   1.145 +  typedef Tuple4<typename TupleTraits<A>::RefType,
   1.146 +                 typename TupleTraits<B>::RefType,
   1.147 +                 typename TupleTraits<C>::RefType,
   1.148 +                 typename TupleTraits<D>::RefType> RefTuple;
   1.149 +
   1.150 +  Tuple4() {}
   1.151 +  Tuple4(typename TupleTraits<A>::ParamType a,
   1.152 +         typename TupleTraits<B>::ParamType b,
   1.153 +         typename TupleTraits<C>::ParamType c,
   1.154 +         typename TupleTraits<D>::ParamType d)
   1.155 +      : a(a), b(b), c(c), d(d) {
   1.156 +  }
   1.157 +
   1.158 +  A a;
   1.159 +  B b;
   1.160 +  C c;
   1.161 +  D d;
   1.162 +};
   1.163 +
   1.164 +template <class A, class B, class C, class D, class E>
   1.165 +struct Tuple5 {
   1.166 +public:
   1.167 +  typedef A TypeA;
   1.168 +  typedef B TypeB;
   1.169 +  typedef C TypeC;
   1.170 +  typedef D TypeD;
   1.171 +  typedef E TypeE;
   1.172 +  typedef Tuple5<typename TupleTraits<A>::ValueType,
   1.173 +    typename TupleTraits<B>::ValueType,
   1.174 +    typename TupleTraits<C>::ValueType,
   1.175 +    typename TupleTraits<D>::ValueType,
   1.176 +    typename TupleTraits<E>::ValueType> ValueTuple;
   1.177 +  typedef Tuple5<typename TupleTraits<A>::RefType,
   1.178 +    typename TupleTraits<B>::RefType,
   1.179 +    typename TupleTraits<C>::RefType,
   1.180 +    typename TupleTraits<D>::RefType,
   1.181 +    typename TupleTraits<E>::RefType> RefTuple;
   1.182 +
   1.183 +  Tuple5() {}
   1.184 +  Tuple5(typename TupleTraits<A>::ParamType a,
   1.185 +    typename TupleTraits<B>::ParamType b,
   1.186 +    typename TupleTraits<C>::ParamType c,
   1.187 +    typename TupleTraits<D>::ParamType d,
   1.188 +    typename TupleTraits<E>::ParamType e)
   1.189 +    : a(a), b(b), c(c), d(d), e(e) {
   1.190 +  }
   1.191 +
   1.192 +  A a;
   1.193 +  B b;
   1.194 +  C c;
   1.195 +  D d;
   1.196 +  E e;
   1.197 +};
   1.198 +
   1.199 +template <class A, class B, class C, class D, class E, class F>
   1.200 +struct Tuple6 {
   1.201 +public:
   1.202 +  typedef A TypeA;
   1.203 +  typedef B TypeB;
   1.204 +  typedef C TypeC;
   1.205 +  typedef D TypeD;
   1.206 +  typedef E TypeE;
   1.207 +  typedef F TypeF;
   1.208 +  typedef Tuple6<typename TupleTraits<A>::ValueType,
   1.209 +    typename TupleTraits<B>::ValueType,
   1.210 +    typename TupleTraits<C>::ValueType,
   1.211 +    typename TupleTraits<D>::ValueType,
   1.212 +    typename TupleTraits<E>::ValueType,
   1.213 +    typename TupleTraits<F>::ValueType> ValueTuple;
   1.214 +  typedef Tuple6<typename TupleTraits<A>::RefType,
   1.215 +    typename TupleTraits<B>::RefType,
   1.216 +    typename TupleTraits<C>::RefType,
   1.217 +    typename TupleTraits<D>::RefType,
   1.218 +    typename TupleTraits<E>::RefType,
   1.219 +    typename TupleTraits<F>::RefType> RefTuple;
   1.220 +
   1.221 +  Tuple6() {}
   1.222 +  Tuple6(typename TupleTraits<A>::ParamType a,
   1.223 +    typename TupleTraits<B>::ParamType b,
   1.224 +    typename TupleTraits<C>::ParamType c,
   1.225 +    typename TupleTraits<D>::ParamType d,
   1.226 +    typename TupleTraits<E>::ParamType e,
   1.227 +    typename TupleTraits<F>::ParamType f)
   1.228 +    : a(a), b(b), c(c), d(d), e(e), f(f) {
   1.229 +  }
   1.230 +
   1.231 +  A a;
   1.232 +  B b;
   1.233 +  C c;
   1.234 +  D d;
   1.235 +  E e;
   1.236 +  F f;
   1.237 +};
   1.238 +
   1.239 +template <class A, class B, class C, class D, class E, class F, class G>
   1.240 +struct Tuple7 {
   1.241 +public:
   1.242 +  typedef A TypeA;
   1.243 +  typedef B TypeB;
   1.244 +  typedef C TypeC;
   1.245 +  typedef D TypeD;
   1.246 +  typedef E TypeE;
   1.247 +  typedef F TypeF;
   1.248 +  typedef G TypeG;
   1.249 +  typedef Tuple7<typename TupleTraits<A>::ValueType,
   1.250 +    typename TupleTraits<B>::ValueType,
   1.251 +    typename TupleTraits<C>::ValueType,
   1.252 +    typename TupleTraits<D>::ValueType,
   1.253 +    typename TupleTraits<E>::ValueType,
   1.254 +    typename TupleTraits<F>::ValueType,
   1.255 +    typename TupleTraits<G>::ValueType> ValueTuple;
   1.256 +  typedef Tuple7<typename TupleTraits<A>::RefType,
   1.257 +    typename TupleTraits<B>::RefType,
   1.258 +    typename TupleTraits<C>::RefType,
   1.259 +    typename TupleTraits<D>::RefType,
   1.260 +    typename TupleTraits<E>::RefType,
   1.261 +    typename TupleTraits<F>::RefType,
   1.262 +    typename TupleTraits<G>::RefType> RefTuple;
   1.263 +
   1.264 +  Tuple7() {}
   1.265 +  Tuple7(typename TupleTraits<A>::ParamType a,
   1.266 +    typename TupleTraits<B>::ParamType b,
   1.267 +    typename TupleTraits<C>::ParamType c,
   1.268 +    typename TupleTraits<D>::ParamType d,
   1.269 +    typename TupleTraits<E>::ParamType e,
   1.270 +    typename TupleTraits<F>::ParamType f,
   1.271 +    typename TupleTraits<G>::ParamType g)
   1.272 +    : a(a), b(b), c(c), d(d), e(e), f(f), g(g) {
   1.273 +  }
   1.274 +
   1.275 +  A a;
   1.276 +  B b;
   1.277 +  C c;
   1.278 +  D d;
   1.279 +  E e;
   1.280 +  F f;
   1.281 +  G g;
   1.282 +};
   1.283 +
   1.284 +// Tuple creators -------------------------------------------------------------
   1.285 +//
   1.286 +// Helper functions for constructing tuples while inferring the template
   1.287 +// argument types.
   1.288 +
   1.289 +inline Tuple0 MakeTuple() {
   1.290 +  return Tuple0();
   1.291 +}
   1.292 +
   1.293 +template <class A>
   1.294 +inline Tuple1<A> MakeTuple(const A& a) {
   1.295 +  return Tuple1<A>(a);
   1.296 +}
   1.297 +
   1.298 +template <class A, class B>
   1.299 +inline Tuple2<A, B> MakeTuple(const A& a, const B& b) {
   1.300 +  return Tuple2<A, B>(a, b);
   1.301 +}
   1.302 +
   1.303 +template <class A, class B, class C>
   1.304 +inline Tuple3<A, B, C> MakeTuple(const A& a, const B& b, const C& c) {
   1.305 +  return Tuple3<A, B, C>(a, b, c);
   1.306 +}
   1.307 +
   1.308 +template <class A, class B, class C, class D>
   1.309 +inline Tuple4<A, B, C, D> MakeTuple(const A& a, const B& b, const C& c,
   1.310 +                                    const D& d) {
   1.311 +  return Tuple4<A, B, C, D>(a, b, c, d);
   1.312 +}
   1.313 +
   1.314 +template <class A, class B, class C, class D, class E>
   1.315 +inline Tuple5<A, B, C, D, E> MakeTuple(const A& a, const B& b, const C& c,
   1.316 +                                       const D& d, const E& e) {
   1.317 +  return Tuple5<A, B, C, D, E>(a, b, c, d, e);
   1.318 +}
   1.319 +
   1.320 +template <class A, class B, class C, class D, class E, class F>
   1.321 +inline Tuple6<A, B, C, D, E, F> MakeTuple(const A& a, const B& b, const C& c,
   1.322 +                                          const D& d, const E& e, const F& f) {
   1.323 +  return Tuple6<A, B, C, D, E, F>(a, b, c, d, e, f);
   1.324 +}
   1.325 +
   1.326 +template <class A, class B, class C, class D, class E, class F, class G>
   1.327 +inline Tuple7<A, B, C, D, E, F, G> MakeTuple(const A& a, const B& b, const C& c,
   1.328 +                                             const D& d, const E& e, const F& f,
   1.329 +                                             const G& g) {
   1.330 +  return Tuple7<A, B, C, D, E, F, G>(a, b, c, d, e, f, g);
   1.331 +}
   1.332 +
   1.333 +// The following set of helpers make what Boost refers to as "Tiers" - a tuple
   1.334 +// of references.
   1.335 +
   1.336 +template <class A>
   1.337 +inline Tuple1<A&> MakeRefTuple(A& a) {
   1.338 +  return Tuple1<A&>(a);
   1.339 +}
   1.340 +
   1.341 +template <class A, class B>
   1.342 +inline Tuple2<A&, B&> MakeRefTuple(A& a, B& b) {
   1.343 +  return Tuple2<A&, B&>(a, b);
   1.344 +}
   1.345 +
   1.346 +template <class A, class B, class C>
   1.347 +inline Tuple3<A&, B&, C&> MakeRefTuple(A& a, B& b, C& c) {
   1.348 +  return Tuple3<A&, B&, C&>(a, b, c);
   1.349 +}
   1.350 +
   1.351 +template <class A, class B, class C, class D>
   1.352 +inline Tuple4<A&, B&, C&, D&> MakeRefTuple(A& a, B& b, C& c, D& d) {
   1.353 +  return Tuple4<A&, B&, C&, D&>(a, b, c, d);
   1.354 +}
   1.355 +
   1.356 +template <class A, class B, class C, class D, class E>
   1.357 +inline Tuple5<A&, B&, C&, D&, E&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e) {
   1.358 +  return Tuple5<A&, B&, C&, D&, E&>(a, b, c, d, e);
   1.359 +}
   1.360 +
   1.361 +template <class A, class B, class C, class D, class E, class F>
   1.362 +inline Tuple6<A&, B&, C&, D&, E&, F&> MakeRefTuple(A& a, B& b, C& c, D& d, E& e,
   1.363 +                                                   F& f) {
   1.364 +  return Tuple6<A&, B&, C&, D&, E&, F&>(a, b, c, d, e, f);
   1.365 +}
   1.366 +
   1.367 +template <class A, class B, class C, class D, class E, class F, class G>
   1.368 +inline Tuple7<A&, B&, C&, D&, E&, F&, G&> MakeRefTuple(A& a, B& b, C& c, D& d,
   1.369 +                                                       E& e, F& f, G& g) {
   1.370 +  return Tuple7<A&, B&, C&, D&, E&, F&, G&>(a, b, c, d, e, f, g);
   1.371 +}
   1.372 +
   1.373 +// Dispatchers ----------------------------------------------------------------
   1.374 +//
   1.375 +// Helper functions that call the given method on an object, with the unpacked
   1.376 +// tuple arguments.  Notice that they all have the same number of arguments,
   1.377 +// so you need only write:
   1.378 +//   DispatchToMethod(object, &Object::method, args);
   1.379 +// This is very useful for templated dispatchers, since they don't need to know
   1.380 +// what type |args| is.
   1.381 +
   1.382 +// Non-Static Dispatchers with no out params.
   1.383 +
   1.384 +template <class ObjT, class Method>
   1.385 +inline void DispatchToMethod(ObjT* obj, Method method, const Tuple0& arg) {
   1.386 +  (obj->*method)();
   1.387 +}
   1.388 +
   1.389 +template <class ObjT, class Method, class A>
   1.390 +inline void DispatchToMethod(ObjT* obj, Method method, const A& arg) {
   1.391 +  (obj->*method)(arg);
   1.392 +}
   1.393 +
   1.394 +template <class ObjT, class Method, class A>
   1.395 +inline void DispatchToMethod(ObjT* obj, Method method, const Tuple1<A>& arg) {
   1.396 +  (obj->*method)(arg.a);
   1.397 +}
   1.398 +
   1.399 +template<class ObjT, class Method, class A, class B>
   1.400 +inline void DispatchToMethod(ObjT* obj,
   1.401 +                             Method method,
   1.402 +                             const Tuple2<A, B>& arg) {
   1.403 +  (obj->*method)(arg.a, arg.b);
   1.404 +}
   1.405 +
   1.406 +template<class ObjT, class Method, class A, class B, class C>
   1.407 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.408 +                             const Tuple3<A, B, C>& arg) {
   1.409 +  (obj->*method)(arg.a, arg.b, arg.c);
   1.410 +}
   1.411 +
   1.412 +template<class ObjT, class Method, class A, class B, class C, class D>
   1.413 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.414 +                             const Tuple4<A, B, C, D>& arg) {
   1.415 +  (obj->*method)(arg.a, arg.b, arg.c, arg.d);
   1.416 +}
   1.417 +
   1.418 +template<class ObjT, class Method, class A, class B, class C, class D, class E>
   1.419 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.420 +                             const Tuple5<A, B, C, D, E>& arg) {
   1.421 +  (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e);
   1.422 +}
   1.423 +
   1.424 +template<class ObjT, class Method, class A, class B, class C, class D, class E,
   1.425 +         class F>
   1.426 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.427 +                             const Tuple6<A, B, C, D, E, F>& arg) {
   1.428 +  (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
   1.429 +}
   1.430 +
   1.431 +template<class ObjT, class Method, class A, class B, class C, class D, class E,
   1.432 +         class F, class G>
   1.433 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.434 +                             const Tuple7<A, B, C, D, E, F, G>& arg) {
   1.435 +  (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f, arg.g);
   1.436 +}
   1.437 +
   1.438 +// Static Dispatchers with no out params.
   1.439 +
   1.440 +template <class Function>
   1.441 +inline void DispatchToFunction(Function function, const Tuple0& arg) {
   1.442 +  (*function)();
   1.443 +}
   1.444 +
   1.445 +template <class Function, class A>
   1.446 +inline void DispatchToFunction(Function function, const A& arg) {
   1.447 +  (*function)(arg);
   1.448 +}
   1.449 +
   1.450 +template <class Function, class A>
   1.451 +inline void DispatchToFunction(Function function, const Tuple1<A>& arg) {
   1.452 +  (*function)(arg.a);
   1.453 +}
   1.454 +
   1.455 +template<class Function, class A, class B>
   1.456 +inline void DispatchToFunction(Function function, const Tuple2<A, B>& arg) {
   1.457 +  (*function)(arg.a, arg.b);
   1.458 +}
   1.459 +
   1.460 +template<class Function, class A, class B, class C>
   1.461 +inline void DispatchToFunction(Function function, const Tuple3<A, B, C>& arg) {
   1.462 +  (*function)(arg.a, arg.b, arg.c);
   1.463 +}
   1.464 +
   1.465 +template<class Function, class A, class B, class C, class D>
   1.466 +inline void DispatchToFunction(Function function,
   1.467 +                               const Tuple4<A, B, C, D>& arg) {
   1.468 +  (*function)(arg.a, arg.b, arg.c, arg.d);
   1.469 +}
   1.470 +
   1.471 +template<class Function, class A, class B, class C, class D, class E>
   1.472 +inline void DispatchToFunction(Function function,
   1.473 +                               const Tuple5<A, B, C, D, E>& arg) {
   1.474 +  (*function)(arg.a, arg.b, arg.c, arg.d, arg.e);
   1.475 +}
   1.476 +
   1.477 +template<class Function, class A, class B, class C, class D, class E, class F>
   1.478 +inline void DispatchToFunction(Function function,
   1.479 +                               const Tuple6<A, B, C, D, E, F>& arg) {
   1.480 +  (*function)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
   1.481 +}
   1.482 +
   1.483 +// Dispatchers with 0 out param (as a Tuple0).
   1.484 +
   1.485 +template <class ObjT, class Method>
   1.486 +inline void DispatchToMethod(ObjT* obj,
   1.487 +                             Method method,
   1.488 +                             const Tuple0& arg, Tuple0*) {
   1.489 +  (obj->*method)();
   1.490 +}
   1.491 +
   1.492 +template <class ObjT, class Method, class A>
   1.493 +inline void DispatchToMethod(ObjT* obj, Method method, const A& arg, Tuple0*) {
   1.494 +  (obj->*method)(arg);
   1.495 +}
   1.496 +
   1.497 +template <class ObjT, class Method, class A>
   1.498 +inline void DispatchToMethod(ObjT* obj,
   1.499 +                             Method method,
   1.500 +                             const Tuple1<A>& arg, Tuple0*) {
   1.501 +  (obj->*method)(arg.a);
   1.502 +}
   1.503 +
   1.504 +template<class ObjT, class Method, class A, class B>
   1.505 +inline void DispatchToMethod(ObjT* obj,
   1.506 +                             Method method,
   1.507 +                             const Tuple2<A, B>& arg, Tuple0*) {
   1.508 +  (obj->*method)(arg.a, arg.b);
   1.509 +}
   1.510 +
   1.511 +template<class ObjT, class Method, class A, class B, class C>
   1.512 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.513 +                             const Tuple3<A, B, C>& arg, Tuple0*) {
   1.514 +  (obj->*method)(arg.a, arg.b, arg.c);
   1.515 +}
   1.516 +
   1.517 +template<class ObjT, class Method, class A, class B, class C, class D>
   1.518 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.519 +                             const Tuple4<A, B, C, D>& arg, Tuple0*) {
   1.520 +  (obj->*method)(arg.a, arg.b, arg.c, arg.d);
   1.521 +}
   1.522 +
   1.523 +template<class ObjT, class Method, class A, class B, class C, class D, class E>
   1.524 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.525 +                             const Tuple5<A, B, C, D, E>& arg, Tuple0*) {
   1.526 +  (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e);
   1.527 +}
   1.528 +
   1.529 +template<class ObjT, class Method, class A, class B, class C, class D, class E,
   1.530 +         class F>
   1.531 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.532 +                             const Tuple6<A, B, C, D, E, F>& arg, Tuple0*) {
   1.533 +  (obj->*method)(arg.a, arg.b, arg.c, arg.d, arg.e, arg.f);
   1.534 +}
   1.535 +
   1.536 +// Dispatchers with 1 out param.
   1.537 +
   1.538 +template<class ObjT, class Method,
   1.539 +         class OutA>
   1.540 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.541 +                             const Tuple0& in,
   1.542 +                             Tuple1<OutA>* out) {
   1.543 +  (obj->*method)(&out->a);
   1.544 +}
   1.545 +
   1.546 +template<class ObjT, class Method, class InA,
   1.547 +         class OutA>
   1.548 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.549 +                             const InA& in,
   1.550 +                             Tuple1<OutA>* out) {
   1.551 +  (obj->*method)(in, &out->a);
   1.552 +}
   1.553 +
   1.554 +template<class ObjT, class Method, class InA,
   1.555 +         class OutA>
   1.556 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.557 +                             const Tuple1<InA>& in,
   1.558 +                             Tuple1<OutA>* out) {
   1.559 +  (obj->*method)(in.a, &out->a);
   1.560 +}
   1.561 +
   1.562 +template<class ObjT, class Method, class InA, class InB,
   1.563 +         class OutA>
   1.564 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.565 +                             const Tuple2<InA, InB>& in,
   1.566 +                             Tuple1<OutA>* out) {
   1.567 +  (obj->*method)(in.a, in.b, &out->a);
   1.568 +}
   1.569 +
   1.570 +template<class ObjT, class Method, class InA, class InB, class InC,
   1.571 +         class OutA>
   1.572 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.573 +                             const Tuple3<InA, InB, InC>& in,
   1.574 +                             Tuple1<OutA>* out) {
   1.575 +  (obj->*method)(in.a, in.b, in.c, &out->a);
   1.576 +}
   1.577 +
   1.578 +template<class ObjT, class Method, class InA, class InB, class InC, class InD,
   1.579 +         class OutA>
   1.580 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.581 +                             const Tuple4<InA, InB, InC, InD>& in,
   1.582 +                             Tuple1<OutA>* out) {
   1.583 +  (obj->*method)(in.a, in.b, in.c, in.d, &out->a);
   1.584 +}
   1.585 +
   1.586 +template<class ObjT, class Method,
   1.587 +         class InA, class InB, class InC, class InD, class InE,
   1.588 +         class OutA>
   1.589 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.590 +                             const Tuple5<InA, InB, InC, InD, InE>& in,
   1.591 +                             Tuple1<OutA>* out) {
   1.592 +  (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a);
   1.593 +}
   1.594 +
   1.595 +template<class ObjT, class Method,
   1.596 +         class InA, class InB, class InC, class InD, class InE, class InF,
   1.597 +         class OutA>
   1.598 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.599 +                             const Tuple6<InA, InB, InC, InD, InE, InF>& in,
   1.600 +                             Tuple1<OutA>* out) {
   1.601 +  (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a);
   1.602 +}
   1.603 +
   1.604 +// Dispatchers with 2 out params.
   1.605 +
   1.606 +template<class ObjT, class Method,
   1.607 +         class OutA, class OutB>
   1.608 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.609 +                             const Tuple0& in,
   1.610 +                             Tuple2<OutA, OutB>* out) {
   1.611 +  (obj->*method)(&out->a, &out->b);
   1.612 +}
   1.613 +
   1.614 +template<class ObjT, class Method, class InA,
   1.615 +         class OutA, class OutB>
   1.616 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.617 +                             const InA& in,
   1.618 +                             Tuple2<OutA, OutB>* out) {
   1.619 +  (obj->*method)(in, &out->a, &out->b);
   1.620 +}
   1.621 +
   1.622 +template<class ObjT, class Method, class InA,
   1.623 +         class OutA, class OutB>
   1.624 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.625 +                             const Tuple1<InA>& in,
   1.626 +                             Tuple2<OutA, OutB>* out) {
   1.627 +  (obj->*method)(in.a, &out->a, &out->b);
   1.628 +}
   1.629 +
   1.630 +template<class ObjT, class Method, class InA, class InB,
   1.631 +         class OutA, class OutB>
   1.632 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.633 +                             const Tuple2<InA, InB>& in,
   1.634 +                             Tuple2<OutA, OutB>* out) {
   1.635 +  (obj->*method)(in.a, in.b, &out->a, &out->b);
   1.636 +}
   1.637 +
   1.638 +template<class ObjT, class Method, class InA, class InB, class InC,
   1.639 +         class OutA, class OutB>
   1.640 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.641 +                             const Tuple3<InA, InB, InC>& in,
   1.642 +                             Tuple2<OutA, OutB>* out) {
   1.643 +  (obj->*method)(in.a, in.b, in.c, &out->a, &out->b);
   1.644 +}
   1.645 +
   1.646 +template<class ObjT, class Method, class InA, class InB, class InC, class InD,
   1.647 +         class OutA, class OutB>
   1.648 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.649 +                             const Tuple4<InA, InB, InC, InD>& in,
   1.650 +                             Tuple2<OutA, OutB>* out) {
   1.651 +  (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b);
   1.652 +}
   1.653 +
   1.654 +template<class ObjT, class Method,
   1.655 +         class InA, class InB, class InC, class InD, class InE,
   1.656 +         class OutA, class OutB>
   1.657 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.658 +                             const Tuple5<InA, InB, InC, InD, InE>& in,
   1.659 +                             Tuple2<OutA, OutB>* out) {
   1.660 +  (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b);
   1.661 +}
   1.662 +
   1.663 +template<class ObjT, class Method,
   1.664 +         class InA, class InB, class InC, class InD, class InE, class InF,
   1.665 +         class OutA, class OutB>
   1.666 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.667 +                             const Tuple6<InA, InB, InC, InD, InE, InF>& in,
   1.668 +                             Tuple2<OutA, OutB>* out) {
   1.669 +  (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b);
   1.670 +}
   1.671 +
   1.672 +// Dispatchers with 3 out params.
   1.673 +
   1.674 +template<class ObjT, class Method,
   1.675 +         class OutA, class OutB, class OutC>
   1.676 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.677 +                             const Tuple0& in,
   1.678 +                             Tuple3<OutA, OutB, OutC>* out) {
   1.679 +  (obj->*method)(&out->a, &out->b, &out->c);
   1.680 +}
   1.681 +
   1.682 +template<class ObjT, class Method, class InA,
   1.683 +         class OutA, class OutB, class OutC>
   1.684 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.685 +                             const InA& in,
   1.686 +                             Tuple3<OutA, OutB, OutC>* out) {
   1.687 +  (obj->*method)(in, &out->a, &out->b, &out->c);
   1.688 +}
   1.689 +
   1.690 +template<class ObjT, class Method, class InA,
   1.691 +         class OutA, class OutB, class OutC>
   1.692 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.693 +                             const Tuple1<InA>& in,
   1.694 +                             Tuple3<OutA, OutB, OutC>* out) {
   1.695 +  (obj->*method)(in.a, &out->a, &out->b, &out->c);
   1.696 +}
   1.697 +
   1.698 +template<class ObjT, class Method, class InA, class InB,
   1.699 +         class OutA, class OutB, class OutC>
   1.700 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.701 +                             const Tuple2<InA, InB>& in,
   1.702 +                             Tuple3<OutA, OutB, OutC>* out) {
   1.703 +  (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c);
   1.704 +}
   1.705 +
   1.706 +template<class ObjT, class Method, class InA, class InB, class InC,
   1.707 +         class OutA, class OutB, class OutC>
   1.708 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.709 +                             const Tuple3<InA, InB, InC>& in,
   1.710 +                             Tuple3<OutA, OutB, OutC>* out) {
   1.711 +  (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c);
   1.712 +}
   1.713 +
   1.714 +template<class ObjT, class Method, class InA, class InB, class InC, class InD,
   1.715 +         class OutA, class OutB, class OutC>
   1.716 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.717 +                             const Tuple4<InA, InB, InC, InD>& in,
   1.718 +                             Tuple3<OutA, OutB, OutC>* out) {
   1.719 +  (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c);
   1.720 +}
   1.721 +
   1.722 +template<class ObjT, class Method,
   1.723 +         class InA, class InB, class InC, class InD, class InE,
   1.724 +         class OutA, class OutB, class OutC>
   1.725 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.726 +                             const Tuple5<InA, InB, InC, InD, InE>& in,
   1.727 +                             Tuple3<OutA, OutB, OutC>* out) {
   1.728 +  (obj->*method)(in.a, in.b, in.c, in.d, in.e, &out->a, &out->b, &out->c);
   1.729 +}
   1.730 +
   1.731 +template<class ObjT, class Method,
   1.732 +         class InA, class InB, class InC, class InD, class InE, class InF,
   1.733 +         class OutA, class OutB, class OutC>
   1.734 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.735 +                             const Tuple6<InA, InB, InC, InD, InE, InF>& in,
   1.736 +                             Tuple3<OutA, OutB, OutC>* out) {
   1.737 +  (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f, &out->a, &out->b, &out->c);
   1.738 +}
   1.739 +
   1.740 +// Dispatchers with 4 out params.
   1.741 +
   1.742 +template<class ObjT, class Method,
   1.743 +         class OutA, class OutB, class OutC, class OutD>
   1.744 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.745 +                             const Tuple0& in,
   1.746 +                             Tuple4<OutA, OutB, OutC, OutD>* out) {
   1.747 +  (obj->*method)(&out->a, &out->b, &out->c, &out->d);
   1.748 +}
   1.749 +
   1.750 +template<class ObjT, class Method, class InA,
   1.751 +         class OutA, class OutB, class OutC, class OutD>
   1.752 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.753 +                             const InA& in,
   1.754 +                             Tuple4<OutA, OutB, OutC, OutD>* out) {
   1.755 +  (obj->*method)(in, &out->a, &out->b, &out->c, &out->d);
   1.756 +}
   1.757 +
   1.758 +template<class ObjT, class Method, class InA,
   1.759 +         class OutA, class OutB, class OutC, class OutD>
   1.760 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.761 +                             const Tuple1<InA>& in,
   1.762 +                             Tuple4<OutA, OutB, OutC, OutD>* out) {
   1.763 +  (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d);
   1.764 +}
   1.765 +
   1.766 +template<class ObjT, class Method, class InA, class InB,
   1.767 +         class OutA, class OutB, class OutC, class OutD>
   1.768 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.769 +                             const Tuple2<InA, InB>& in,
   1.770 +                             Tuple4<OutA, OutB, OutC, OutD>* out) {
   1.771 +  (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d);
   1.772 +}
   1.773 +
   1.774 +template<class ObjT, class Method, class InA, class InB, class InC,
   1.775 +         class OutA, class OutB, class OutC, class OutD>
   1.776 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.777 +                             const Tuple3<InA, InB, InC>& in,
   1.778 +                             Tuple4<OutA, OutB, OutC, OutD>* out) {
   1.779 +  (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d);
   1.780 +}
   1.781 +
   1.782 +template<class ObjT, class Method, class InA, class InB, class InC, class InD,
   1.783 +         class OutA, class OutB, class OutC, class OutD>
   1.784 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.785 +                             const Tuple4<InA, InB, InC, InD>& in,
   1.786 +                             Tuple4<OutA, OutB, OutC, OutD>* out) {
   1.787 +  (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d);
   1.788 +}
   1.789 +
   1.790 +template<class ObjT, class Method,
   1.791 +         class InA, class InB, class InC, class InD, class InE,
   1.792 +         class OutA, class OutB, class OutC, class OutD>
   1.793 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.794 +                             const Tuple5<InA, InB, InC, InD, InE>& in,
   1.795 +                             Tuple4<OutA, OutB, OutC, OutD>* out) {
   1.796 +  (obj->*method)(in.a, in.b, in.c, in.d, in.e,
   1.797 +                 &out->a, &out->b, &out->c, &out->d);
   1.798 +}
   1.799 +
   1.800 +template<class ObjT, class Method,
   1.801 +         class InA, class InB, class InC, class InD, class InE, class InF,
   1.802 +         class OutA, class OutB, class OutC, class OutD>
   1.803 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.804 +                             const Tuple6<InA, InB, InC, InD, InE, InF>& in,
   1.805 +                             Tuple4<OutA, OutB, OutC, OutD>* out) {
   1.806 +  (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f,
   1.807 +                 &out->a, &out->b, &out->c, &out->d);
   1.808 +}
   1.809 +
   1.810 +// Dispatchers with 5 out params.
   1.811 +
   1.812 +template<class ObjT, class Method,
   1.813 +         class OutA, class OutB, class OutC, class OutD, class OutE>
   1.814 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.815 +                             const Tuple0& in,
   1.816 +                             Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
   1.817 +  (obj->*method)(&out->a, &out->b, &out->c, &out->d, &out->e);
   1.818 +}
   1.819 +
   1.820 +template<class ObjT, class Method, class InA,
   1.821 +         class OutA, class OutB, class OutC, class OutD, class OutE>
   1.822 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.823 +                             const InA& in,
   1.824 +                             Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
   1.825 +  (obj->*method)(in, &out->a, &out->b, &out->c, &out->d, &out->e);
   1.826 +}
   1.827 +
   1.828 +template<class ObjT, class Method, class InA,
   1.829 +         class OutA, class OutB, class OutC, class OutD, class OutE>
   1.830 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.831 +                             const Tuple1<InA>& in,
   1.832 +                             Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
   1.833 +  (obj->*method)(in.a, &out->a, &out->b, &out->c, &out->d, &out->e);
   1.834 +}
   1.835 +
   1.836 +template<class ObjT, class Method, class InA, class InB,
   1.837 +         class OutA, class OutB, class OutC, class OutD, class OutE>
   1.838 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.839 +                             const Tuple2<InA, InB>& in,
   1.840 +                             Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
   1.841 +  (obj->*method)(in.a, in.b, &out->a, &out->b, &out->c, &out->d, &out->e);
   1.842 +}
   1.843 +
   1.844 +template<class ObjT, class Method, class InA, class InB, class InC,
   1.845 +         class OutA, class OutB, class OutC, class OutD, class OutE>
   1.846 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.847 +                             const Tuple3<InA, InB, InC>& in,
   1.848 +                             Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
   1.849 +  (obj->*method)(in.a, in.b, in.c, &out->a, &out->b, &out->c, &out->d, &out->e);
   1.850 +}
   1.851 +
   1.852 +template<class ObjT, class Method, class InA, class InB, class InC, class InD,
   1.853 +         class OutA, class OutB, class OutC, class OutD, class OutE>
   1.854 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.855 +                             const Tuple4<InA, InB, InC, InD>& in,
   1.856 +                             Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
   1.857 +  (obj->*method)(in.a, in.b, in.c, in.d, &out->a, &out->b, &out->c, &out->d,
   1.858 +                 &out->e);
   1.859 +}
   1.860 +
   1.861 +template<class ObjT, class Method,
   1.862 +         class InA, class InB, class InC, class InD, class InE,
   1.863 +         class OutA, class OutB, class OutC, class OutD, class OutE>
   1.864 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.865 +                             const Tuple5<InA, InB, InC, InD, InE>& in,
   1.866 +                             Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
   1.867 +  (obj->*method)(in.a, in.b, in.c, in.d, in.e,
   1.868 +                 &out->a, &out->b, &out->c, &out->d, &out->e);
   1.869 +}
   1.870 +
   1.871 +template<class ObjT, class Method,
   1.872 +         class InA, class InB, class InC, class InD, class InE, class InF,
   1.873 +         class OutA, class OutB, class OutC, class OutD, class OutE>
   1.874 +inline void DispatchToMethod(ObjT* obj, Method method,
   1.875 +                             const Tuple6<InA, InB, InC, InD, InE, InF>& in,
   1.876 +                             Tuple5<OutA, OutB, OutC, OutD, OutE>* out) {
   1.877 +  (obj->*method)(in.a, in.b, in.c, in.d, in.e, in.f,
   1.878 +                 &out->a, &out->b, &out->c, &out->d, &out->e);
   1.879 +}
   1.880 +
   1.881 +#endif  // BASE_TUPLE_H__

mercurial