X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=libs%2Fgeneric%2Fcallback.h;h=9a1c9b1718aa262dbb0a2ae706cbecddceb69168;hb=18d60f90d7603cb420150739251cf98519c57406;hp=1e8cd46d5be4a944e39218d2df10adcb37be7ac5;hpb=f6b4543bd54926411cb71a776bc5b37eea846c4f;p=xonotic%2Fnetradiant.git diff --git a/libs/generic/callback.h b/libs/generic/callback.h index 1e8cd46d..9a1c9b17 100644 --- a/libs/generic/callback.h +++ b/libs/generic/callback.h @@ -151,12 +151,12 @@ using BindFirstOpaque = BindFirstOpaqueN>; /// \brief Combines a void pointer with a pointer to a function which operates on a void pointer. /// -/// Use with the callback constructors MemberCaller, ConstMemberCaller, ReferenceCaller, ConstReferenceCaller, PointerCaller, ConstPointerCaller and FreeCaller. +/// Use with the callback constructors MemberCaller0, ConstMemberCaller0, ReferenceCaller0, ConstReferenceCaller0, PointerCaller0, ConstPointerCaller0 and FreeCaller0. template -class CallbackN; +class Callback; template -class CallbackN : public CallbackBase { +class Callback : public CallbackBase { using Base = CallbackBase; static R nullThunk(void *, Ts...) { @@ -165,14 +165,14 @@ class CallbackN : public CallbackBase { public: using func = R(Ts...); - CallbackN() : Base(0, nullThunk) { + Callback() : Base(0, nullThunk) { } template - CallbackN(const BindFirstOpaque &caller) : Base(caller.getEnvironment(), BindFirstOpaque::thunk) { + Callback(const BindFirstOpaque &caller) : Base(caller.getEnvironment(), BindFirstOpaque::thunk) { } - CallbackN(void *environment, typename Base::Thunk function) : Base(environment, function) { + Callback(void *environment, typename Base::Thunk function) : Base(environment, function) { } R operator()(Ts... args) const { @@ -204,81 +204,64 @@ namespace detail { } template -inline CallbackN>::shift::type> makeCallbackN(const Caller &caller, get_argument callee) { - return CallbackN>::shift::type>(BindFirstOpaque(callee)); +inline Callback>::shift::type> makeCallback(const Caller &caller, get_argument callee) { + return Callback>::shift::type>(BindFirstOpaque(callee)); } template -inline CallbackN> makeStatelessCallbackN(const Caller &caller) { - return makeCallbackN(CallerShiftFirst>::template unshift::type>(), nullptr); +inline Callback> makeStatelessCallback(const Caller &caller) { + return makeCallback(CallerShiftFirst>::template unshift::type>(), nullptr); } -namespace detail { - template - struct MemberFunction; - - template - struct MemberFunction { - using type = R(Object::*)(Ts...); - using type_const = R(Object::*)(Ts...) const; - }; -} - -template -using MemberFunction = typename detail::MemberFunction::type; - -template -using ConstMemberFunction = typename detail::MemberFunction::type_const; - /// \brief Forms a Callback from a non-const Environment reference and a non-const Environment member-function. /// /// \dontinclude generic/callback.cpp -/// \skipline MemberCaller example +/// \skipline MemberCaller0 example /// \until end example template member> -using MemberCallerN = BindFirstOpaque::template instance>; +using MemberCaller = BindFirstOpaque::template instance>; /// \brief Forms a Callback from a const Environment reference and a const Environment member-function. /// /// \dontinclude generic/callback.cpp -/// \skipline MemberCaller example +/// \skipline MemberCaller0 example /// \until end example template member> -using ConstMemberCallerN = BindFirstOpaque::template instance>; +using ConstMemberCaller = BindFirstOpaque::template instance>; /// \brief Forms a Callback from a non-const Environment reference and a free function which operates on a non-const Environment reference. /// /// \dontinclude generic/callback.cpp -/// \skipline ReferenceCaller example +/// \skipline ReferenceCaller0 example /// \until end example template::template unshift::type *func> -using ReferenceCallerN = BindFirstOpaque::template unshift::type>::template instance>; +using ReferenceCaller = BindFirstOpaque::template unshift::type>::template instance>; /// \brief Forms a Callback from a const Environment reference and a free function which operates on a const Environment reference. /// /// \dontinclude generic/callback.cpp -/// \skipline ReferenceCaller example +/// \skipline ReferenceCaller0 example /// \until end example template::template unshift::type *func> -using ConstReferenceCallerN = BindFirstOpaque::template unshift::type>::template instance>; +using ConstReferenceCaller = BindFirstOpaque::template unshift::type>::template instance>; /// \brief Forms a Callback from a non-const Environment pointer and a free function which operates on a non-const Environment pointer. template::template unshift::type *func> -using PointerCallerN = BindFirstOpaque::template unshift::type>::template instance>; +using PointerCaller = BindFirstOpaque::template unshift::type>::template instance>; /// \brief Forms a Callback from a const Environment pointer and a free function which operates on a const Environment pointer. template::template unshift::type *func> -using ConstPointerCallerN = BindFirstOpaque::template unshift::type>::template instance>; +using ConstPointerCaller = BindFirstOpaque::template unshift::type>::template instance>; /// \brief Forms a Callback from a free function template -class FreeCallerN : public BindFirstOpaque::template instance, typename detail::Arglist::template unshift::type >> { public: - FreeCallerN() + FreeCaller() : BindFirstOpaque::template instance, typename detail::Arglist::template unshift::type @@ -290,109 +273,31 @@ public: /// /// \param Functor Must define \c first_argument_type and \c operator()(first_argument_type). template -inline CallbackN> makeCallbackN(Functor &functor) { - return CallbackN>(MemberCallerN, &Functor::operator()>(functor)); +inline Callback> makeCallback(Functor &functor) { + return Callback>(MemberCaller, &Functor::operator()>(functor)); } /// \brief Constructs a Callback1 from a const \p functor /// /// \param Functor Must define \c first_argument_type and const \c operator()(first_argument_type). template -inline CallbackN> makeCallbackN(const Functor &functor) { - return CallbackN>(ConstMemberCallerN, &Functor::operator()>(functor)); +inline Callback> makeCallback(const Functor &functor) { + return Callback>(ConstMemberCaller, &Functor::operator()>(functor)); } -// todo: inline - -#define makeCallback makeCallbackN - -using Callback = CallbackN; - -template -using Callback0 = CallbackN; - -template -using Callback1 = CallbackN; - -template -using Callback2 = CallbackN; - -template -using Callback3 = CallbackN; - -#define makeCallback0 makeCallbackN -#define makeStatelessCallback0 makeStatelessCallbackN - -#define makeCallback1 makeCallbackN -#define makeStatelessCallback1 makeStatelessCallbackN - -#define makeCallback2 makeCallbackN -#define makeStatelessCallback2 makeStatelessCallbackN - -#define makeCallback3 makeCallbackN -#define makeStatelessCallback3 makeStatelessCallbackN - -template -using MemberCaller = MemberCallerN; - -template -using ConstMemberCaller = ConstMemberCallerN; - -template -using MemberCaller1 = MemberCallerN; - -template -using ConstMemberCaller1 = ConstMemberCallerN; - -template -using ReferenceCaller = ReferenceCallerN; - -template -using ConstReferenceCaller = ConstReferenceCallerN; - -/// \brief Forms a Callback from a non-const Environment reference and a free function which operates on a non-const Environment reference and one other argument. -template -using ReferenceCaller1 = ReferenceCallerN; - -/// \brief Forms a Callback from a const Environment reference and a free function which operates on a const Environment reference and one other argument. -template -using ConstReferenceCaller1 = ConstReferenceCallerN; - -/// \brief Forms a Callback from a non-const Environment pointer and a free function which operates on a non-const Environment pointer. -template -using PointerCaller = PointerCallerN; - -/// \brief Forms a Callback from a const Environment pointer and a free function which operates on a const Environment pointer. -template -using ConstPointerCaller = ConstPointerCallerN; - -/// \brief Forms a Callback from a non-const Environment pointer and a free function which operates on a non-const Environment pointer and one other argument. -template -using PointerCaller1 = PointerCallerN; - -/// \brief Forms a Callback from a const Environment pointer and a free function which operates on a const Environment pointer and one other argument. -template -using ConstPointerCaller1 = ConstPointerCallerN; - -template -using FreeCaller = FreeCallerN; - -template -using FreeCaller1 = FreeCallerN; - -typedef Callback1 BoolImportCallback; -typedef Callback1 BoolExportCallback; +using BoolImportCallback = Callback; +using BoolExportCallback = Callback; -typedef Callback1 IntImportCallback; -typedef Callback1 IntExportCallback; +using IntImportCallback = Callback; +using IntExportCallback = Callback; -typedef Callback1 FloatImportCallback; -typedef Callback1 FloatExportCallback; +using FloatImportCallback = Callback; +using FloatExportCallback = Callback; -typedef Callback1 StringImportCallback; -typedef Callback1 StringExportCallback; +using StringImportCallback = Callback; +using StringExportCallback = Callback; -typedef Callback1 SizeImportCallback; -typedef Callback1 SizeExportCallback; +using SizeImportCallback = Callback; +using SizeExportCallback = Callback; #endif