зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1163320 - Variadic implementation of nsRunnableMethodArguments. r=froydnj
MozReview-Commit-ID: 13YyOyiionD --HG-- extra : rebase_source : 89a0ad0877ed3290a41288523fe9b13d9c5bac7d extra : source : ed761807105b30069d5a7412f8dacf75429eeeb6
This commit is contained in:
Родитель
8c83eea5af
Коммит
5a57a5b196
|
@ -18,7 +18,9 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "mozilla/IndexSequence.h"
|
||||
#include "mozilla/Likely.h"
|
||||
#include "mozilla/Tuple.h"
|
||||
#include "mozilla/TypeTraits.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -369,7 +371,7 @@ struct StoreCopyPassByValue
|
|||
typedef T passed_type;
|
||||
stored_type m;
|
||||
template <typename A>
|
||||
explicit StoreCopyPassByValue(A&& a) : m(mozilla::Forward<A>(a)) {}
|
||||
MOZ_IMPLICIT StoreCopyPassByValue(A&& a) : m(mozilla::Forward<A>(a)) {}
|
||||
passed_type PassAsParameter() { return m; }
|
||||
};
|
||||
template<typename S>
|
||||
|
@ -383,7 +385,7 @@ struct StoreCopyPassByConstLRef
|
|||
typedef const T& passed_type;
|
||||
stored_type m;
|
||||
template <typename A>
|
||||
explicit StoreCopyPassByConstLRef(A&& a) : m(mozilla::Forward<A>(a)) {}
|
||||
MOZ_IMPLICIT StoreCopyPassByConstLRef(A&& a) : m(mozilla::Forward<A>(a)) {}
|
||||
passed_type PassAsParameter() { return m; }
|
||||
};
|
||||
template<typename S>
|
||||
|
@ -397,7 +399,7 @@ struct StoreCopyPassByLRef
|
|||
typedef T& passed_type;
|
||||
stored_type m;
|
||||
template <typename A>
|
||||
explicit StoreCopyPassByLRef(A&& a) : m(mozilla::Forward<A>(a)) {}
|
||||
MOZ_IMPLICIT StoreCopyPassByLRef(A&& a) : m(mozilla::Forward<A>(a)) {}
|
||||
passed_type PassAsParameter() { return m; }
|
||||
};
|
||||
template<typename S>
|
||||
|
@ -411,7 +413,7 @@ struct StoreCopyPassByRRef
|
|||
typedef T&& passed_type;
|
||||
stored_type m;
|
||||
template <typename A>
|
||||
explicit StoreCopyPassByRRef(A&& a) : m(mozilla::Forward<A>(a)) {}
|
||||
MOZ_IMPLICIT StoreCopyPassByRRef(A&& a) : m(mozilla::Forward<A>(a)) {}
|
||||
passed_type PassAsParameter() { return mozilla::Move(m); }
|
||||
};
|
||||
template<typename S>
|
||||
|
@ -425,7 +427,7 @@ struct StoreRefPassByLRef
|
|||
typedef T& passed_type;
|
||||
stored_type m;
|
||||
template <typename A>
|
||||
explicit StoreRefPassByLRef(A& a) : m(a) {}
|
||||
MOZ_IMPLICIT StoreRefPassByLRef(A& a) : m(a) {}
|
||||
passed_type PassAsParameter() { return m; }
|
||||
};
|
||||
template<typename S>
|
||||
|
@ -439,7 +441,7 @@ struct StoreConstRefPassByConstLRef
|
|||
typedef const T& passed_type;
|
||||
stored_type m;
|
||||
template <typename A>
|
||||
explicit StoreConstRefPassByConstLRef(const A& a) : m(a) {}
|
||||
MOZ_IMPLICIT StoreConstRefPassByConstLRef(const A& a) : m(a) {}
|
||||
passed_type PassAsParameter() { return m; }
|
||||
};
|
||||
template<typename S>
|
||||
|
@ -453,7 +455,7 @@ struct StorensRefPtrPassByPtr
|
|||
typedef T* passed_type;
|
||||
stored_type m;
|
||||
template <typename A>
|
||||
explicit StorensRefPtrPassByPtr(A&& a) : m(mozilla::Forward<A>(a)) {}
|
||||
MOZ_IMPLICIT StorensRefPtrPassByPtr(A&& a) : m(mozilla::Forward<A>(a)) {}
|
||||
passed_type PassAsParameter() { return m.get(); }
|
||||
};
|
||||
template<typename S>
|
||||
|
@ -467,7 +469,7 @@ struct StorePtrPassByPtr
|
|||
typedef T* passed_type;
|
||||
stored_type m;
|
||||
template <typename A>
|
||||
explicit StorePtrPassByPtr(A a) : m(a) {}
|
||||
MOZ_IMPLICIT StorePtrPassByPtr(A a) : m(a) {}
|
||||
passed_type PassAsParameter() { return m; }
|
||||
};
|
||||
template<typename S>
|
||||
|
@ -481,7 +483,7 @@ struct StoreConstPtrPassByConstPtr
|
|||
typedef const T* passed_type;
|
||||
stored_type m;
|
||||
template <typename A>
|
||||
explicit StoreConstPtrPassByConstPtr(A a) : m(a) {}
|
||||
MOZ_IMPLICIT StoreConstPtrPassByConstPtr(A a) : m(a) {}
|
||||
passed_type PassAsParameter() { return m; }
|
||||
};
|
||||
template<typename S>
|
||||
|
@ -495,7 +497,7 @@ struct StoreCopyPassByConstPtr
|
|||
typedef const T* passed_type;
|
||||
stored_type m;
|
||||
template <typename A>
|
||||
explicit StoreCopyPassByConstPtr(A&& a) : m(mozilla::Forward<A>(a)) {}
|
||||
MOZ_IMPLICIT StoreCopyPassByConstPtr(A&& a) : m(mozilla::Forward<A>(a)) {}
|
||||
passed_type PassAsParameter() { return &m; }
|
||||
};
|
||||
template<typename S>
|
||||
|
@ -509,7 +511,7 @@ struct StoreCopyPassByPtr
|
|||
typedef T* passed_type;
|
||||
stored_type m;
|
||||
template <typename A>
|
||||
explicit StoreCopyPassByPtr(A&& a) : m(mozilla::Forward<A>(a)) {}
|
||||
MOZ_IMPLICIT StoreCopyPassByPtr(A&& a) : m(mozilla::Forward<A>(a)) {}
|
||||
passed_type PassAsParameter() { return &m; }
|
||||
};
|
||||
template<typename S>
|
||||
|
@ -651,196 +653,28 @@ struct ParameterStorage
|
|||
} /* namespace detail */
|
||||
|
||||
// struct used to store arguments and later apply them to a method.
|
||||
template <typename... Ts> struct nsRunnableMethodArguments;
|
||||
|
||||
// Specializations for 0-8 arguments, add more as required.
|
||||
// TODO Use tuple instead; And/or use lambdas (see bug 1152753)
|
||||
template <>
|
||||
struct nsRunnableMethodArguments<>
|
||||
template <typename... Ts>
|
||||
struct nsRunnableMethodArguments
|
||||
{
|
||||
template<class C, typename M> void apply(C* o, M m)
|
||||
{
|
||||
((*o).*m)();
|
||||
}
|
||||
};
|
||||
template <typename T0>
|
||||
struct nsRunnableMethodArguments<T0>
|
||||
{
|
||||
typename ::detail::ParameterStorage<T0>::Type m0;
|
||||
template<typename A0>
|
||||
explicit nsRunnableMethodArguments(A0&& a0)
|
||||
: m0(mozilla::Forward<A0>(a0))
|
||||
mozilla::Tuple<typename ::detail::ParameterStorage<Ts>::Type...> mArguments;
|
||||
template <typename... As>
|
||||
explicit nsRunnableMethodArguments(As&&... aArguments)
|
||||
: mArguments(mozilla::Forward<As>(aArguments)...)
|
||||
{}
|
||||
template<class C, typename M> void apply(C* o, M m)
|
||||
template<typename C, typename M, typename... Args, size_t... Indices>
|
||||
static auto
|
||||
applyImpl(C* o, M m, mozilla::Tuple<Args...>& args,
|
||||
mozilla::IndexSequence<Indices...>)
|
||||
-> decltype(((*o).*m)(mozilla::Get<Indices>(args).PassAsParameter()...))
|
||||
{
|
||||
((*o).*m)(m0.PassAsParameter());
|
||||
return ((*o).*m)(mozilla::Get<Indices>(args).PassAsParameter()...);
|
||||
}
|
||||
};
|
||||
template <typename T0, typename T1>
|
||||
struct nsRunnableMethodArguments<T0, T1>
|
||||
{
|
||||
typename ::detail::ParameterStorage<T0>::Type m0;
|
||||
typename ::detail::ParameterStorage<T1>::Type m1;
|
||||
template<typename A0, typename A1>
|
||||
nsRunnableMethodArguments(A0&& a0, A1&& a1)
|
||||
: m0(mozilla::Forward<A0>(a0))
|
||||
, m1(mozilla::Forward<A1>(a1))
|
||||
{}
|
||||
template<class C, typename M> void apply(C* o, M m)
|
||||
template<class C, typename M> auto apply(C* o, M m)
|
||||
-> decltype(applyImpl(o, m, mArguments,
|
||||
typename mozilla::IndexSequenceFor<Ts...>::Type()))
|
||||
{
|
||||
((*o).*m)(m0.PassAsParameter(), m1.PassAsParameter());
|
||||
}
|
||||
};
|
||||
template <typename T0, typename T1, typename T2>
|
||||
struct nsRunnableMethodArguments<T0, T1, T2>
|
||||
{
|
||||
typename ::detail::ParameterStorage<T0>::Type m0;
|
||||
typename ::detail::ParameterStorage<T1>::Type m1;
|
||||
typename ::detail::ParameterStorage<T2>::Type m2;
|
||||
template<typename A0, typename A1, typename A2>
|
||||
nsRunnableMethodArguments(A0&& a0, A1&& a1, A2&& a2)
|
||||
: m0(mozilla::Forward<A0>(a0))
|
||||
, m1(mozilla::Forward<A1>(a1))
|
||||
, m2(mozilla::Forward<A2>(a2))
|
||||
{}
|
||||
template<class C, typename M> void apply(C* o, M m)
|
||||
{
|
||||
((*o).*m)(m0.PassAsParameter(), m1.PassAsParameter(), m2.PassAsParameter());
|
||||
}
|
||||
};
|
||||
template <typename T0, typename T1, typename T2, typename T3>
|
||||
struct nsRunnableMethodArguments<T0, T1, T2, T3>
|
||||
{
|
||||
typename ::detail::ParameterStorage<T0>::Type m0;
|
||||
typename ::detail::ParameterStorage<T1>::Type m1;
|
||||
typename ::detail::ParameterStorage<T2>::Type m2;
|
||||
typename ::detail::ParameterStorage<T3>::Type m3;
|
||||
template<typename A0, typename A1, typename A2, typename A3>
|
||||
nsRunnableMethodArguments(A0&& a0, A1&& a1, A2&& a2, A3&& a3)
|
||||
: m0(mozilla::Forward<A0>(a0))
|
||||
, m1(mozilla::Forward<A1>(a1))
|
||||
, m2(mozilla::Forward<A2>(a2))
|
||||
, m3(mozilla::Forward<A3>(a3))
|
||||
{}
|
||||
template<class C, typename M> void apply(C* o, M m)
|
||||
{
|
||||
((*o).*m)(m0.PassAsParameter(), m1.PassAsParameter(),
|
||||
m2.PassAsParameter(), m3.PassAsParameter());
|
||||
}
|
||||
};
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4>
|
||||
struct nsRunnableMethodArguments<T0, T1, T2, T3, T4>
|
||||
{
|
||||
typename ::detail::ParameterStorage<T0>::Type m0;
|
||||
typename ::detail::ParameterStorage<T1>::Type m1;
|
||||
typename ::detail::ParameterStorage<T2>::Type m2;
|
||||
typename ::detail::ParameterStorage<T3>::Type m3;
|
||||
typename ::detail::ParameterStorage<T4>::Type m4;
|
||||
template<typename A0, typename A1, typename A2, typename A3, typename A4>
|
||||
nsRunnableMethodArguments(A0&& a0, A1&& a1, A2&& a2, A3&& a3, A4&& a4)
|
||||
: m0(mozilla::Forward<A0>(a0))
|
||||
, m1(mozilla::Forward<A1>(a1))
|
||||
, m2(mozilla::Forward<A2>(a2))
|
||||
, m3(mozilla::Forward<A3>(a3))
|
||||
, m4(mozilla::Forward<A4>(a4))
|
||||
{}
|
||||
template<class C, typename M> void apply(C* o, M m)
|
||||
{
|
||||
((*o).*m)(m0.PassAsParameter(), m1.PassAsParameter(),
|
||||
m2.PassAsParameter(), m3.PassAsParameter(),
|
||||
m4.PassAsParameter());
|
||||
}
|
||||
};
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5>
|
||||
struct nsRunnableMethodArguments<T0, T1, T2, T3, T4, T5>
|
||||
{
|
||||
typename ::detail::ParameterStorage<T0>::Type m0;
|
||||
typename ::detail::ParameterStorage<T1>::Type m1;
|
||||
typename ::detail::ParameterStorage<T2>::Type m2;
|
||||
typename ::detail::ParameterStorage<T3>::Type m3;
|
||||
typename ::detail::ParameterStorage<T4>::Type m4;
|
||||
typename ::detail::ParameterStorage<T5>::Type m5;
|
||||
template<typename A0, typename A1, typename A2, typename A3, typename A4,
|
||||
typename A5>
|
||||
nsRunnableMethodArguments(A0&& a0, A1&& a1, A2&& a2, A3&& a3, A4&& a4,
|
||||
A5&& a5)
|
||||
: m0(mozilla::Forward<A0>(a0))
|
||||
, m1(mozilla::Forward<A1>(a1))
|
||||
, m2(mozilla::Forward<A2>(a2))
|
||||
, m3(mozilla::Forward<A3>(a3))
|
||||
, m4(mozilla::Forward<A4>(a4))
|
||||
, m5(mozilla::Forward<A5>(a5))
|
||||
{}
|
||||
template<class C, typename M> void apply(C* o, M m)
|
||||
{
|
||||
((*o).*m)(m0.PassAsParameter(), m1.PassAsParameter(),
|
||||
m2.PassAsParameter(), m3.PassAsParameter(),
|
||||
m4.PassAsParameter(), m5.PassAsParameter());
|
||||
}
|
||||
};
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6>
|
||||
struct nsRunnableMethodArguments<T0, T1, T2, T3, T4, T5, T6>
|
||||
{
|
||||
typename ::detail::ParameterStorage<T0>::Type m0;
|
||||
typename ::detail::ParameterStorage<T1>::Type m1;
|
||||
typename ::detail::ParameterStorage<T2>::Type m2;
|
||||
typename ::detail::ParameterStorage<T3>::Type m3;
|
||||
typename ::detail::ParameterStorage<T4>::Type m4;
|
||||
typename ::detail::ParameterStorage<T5>::Type m5;
|
||||
typename ::detail::ParameterStorage<T6>::Type m6;
|
||||
template<typename A0, typename A1, typename A2, typename A3, typename A4,
|
||||
typename A5, typename A6>
|
||||
nsRunnableMethodArguments(A0&& a0, A1&& a1, A2&& a2, A3&& a3, A4&& a4,
|
||||
A5&& a5, A6&& a6)
|
||||
: m0(mozilla::Forward<A0>(a0))
|
||||
, m1(mozilla::Forward<A1>(a1))
|
||||
, m2(mozilla::Forward<A2>(a2))
|
||||
, m3(mozilla::Forward<A3>(a3))
|
||||
, m4(mozilla::Forward<A4>(a4))
|
||||
, m5(mozilla::Forward<A5>(a5))
|
||||
, m6(mozilla::Forward<A6>(a6))
|
||||
{}
|
||||
template<class C, typename M> void apply(C* o, M m)
|
||||
{
|
||||
((*o).*m)(m0.PassAsParameter(), m1.PassAsParameter(),
|
||||
m2.PassAsParameter(), m3.PassAsParameter(),
|
||||
m4.PassAsParameter(), m5.PassAsParameter(),
|
||||
m6.PassAsParameter());
|
||||
}
|
||||
};
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7>
|
||||
struct nsRunnableMethodArguments<T0, T1, T2, T3, T4, T5, T6, T7>
|
||||
{
|
||||
typename ::detail::ParameterStorage<T0>::Type m0;
|
||||
typename ::detail::ParameterStorage<T1>::Type m1;
|
||||
typename ::detail::ParameterStorage<T2>::Type m2;
|
||||
typename ::detail::ParameterStorage<T3>::Type m3;
|
||||
typename ::detail::ParameterStorage<T4>::Type m4;
|
||||
typename ::detail::ParameterStorage<T5>::Type m5;
|
||||
typename ::detail::ParameterStorage<T6>::Type m6;
|
||||
typename ::detail::ParameterStorage<T7>::Type m7;
|
||||
template<typename A0, typename A1, typename A2, typename A3, typename A4,
|
||||
typename A5, typename A6, typename A7>
|
||||
nsRunnableMethodArguments(A0&& a0, A1&& a1, A2&& a2, A3&& a3, A4&& a4,
|
||||
A5&& a5, A6&& a6, A7&& a7)
|
||||
: m0(mozilla::Forward<A0>(a0))
|
||||
, m1(mozilla::Forward<A1>(a1))
|
||||
, m2(mozilla::Forward<A2>(a2))
|
||||
, m3(mozilla::Forward<A3>(a3))
|
||||
, m4(mozilla::Forward<A4>(a4))
|
||||
, m5(mozilla::Forward<A5>(a5))
|
||||
, m6(mozilla::Forward<A6>(a6))
|
||||
, m7(mozilla::Forward<A7>(a7))
|
||||
{}
|
||||
template<class C, typename M> void apply(C* o, M m)
|
||||
{
|
||||
((*o).*m)(m0.PassAsParameter(), m1.PassAsParameter(),
|
||||
m2.PassAsParameter(), m3.PassAsParameter(),
|
||||
m4.PassAsParameter(), m5.PassAsParameter(),
|
||||
m6.PassAsParameter(), m7.PassAsParameter());
|
||||
return applyImpl(o, m, mArguments,
|
||||
typename mozilla::IndexSequenceFor<Ts...>::Type());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче