diff --git a/include/icamera.h b/include/icamera.h index 98f13e58..3dda5386 100644 --- a/include/icamera.h +++ b/include/icamera.h @@ -28,7 +28,7 @@ #pragma once #include "generic/constant.h" -#include "generic/callbackfwd.h" +#include "generic/callback.h" class Matrix4; diff --git a/include/ifilesystem.h b/include/ifilesystem.h index 5ec621a5..e87687f6 100644 --- a/include/ifilesystem.h +++ b/include/ifilesystem.h @@ -23,7 +23,7 @@ #include #include "generic/constant.h" -#include "generic/callbackfwd.h" +#include "generic/callback.h" typedef Callback1 ArchiveNameCallback; typedef Callback1 FileNameCallback; diff --git a/include/irender.h b/include/irender.h index 49589941..9cdd73c3 100644 --- a/include/irender.h +++ b/include/irender.h @@ -22,7 +22,7 @@ #pragma once #include "generic/constant.h" -#include "generic/callbackfwd.h" +#include "generic/callback.h" #include "generic/vector.h" diff --git a/include/iselection.h b/include/iselection.h index 09bb5ed6..6804abe1 100644 --- a/include/iselection.h +++ b/include/iselection.h @@ -23,7 +23,7 @@ #include #include "generic/constant.h" -#include "generic/callbackfwd.h" +#include "generic/callback.h" #include "signal/signalfwd.h" class Renderer; diff --git a/include/ishaders.h b/include/ishaders.h index 7ab5ac43..07ad4004 100644 --- a/include/ishaders.h +++ b/include/ishaders.h @@ -22,7 +22,7 @@ #pragma once #include "generic/constant.h" -#include "generic/callbackfwd.h" +#include "generic/callback.h" enum { diff --git a/include/iundo.h b/include/iundo.h index 050bb241..b5ec00d8 100644 --- a/include/iundo.h +++ b/include/iundo.h @@ -26,7 +26,7 @@ #include #include "generic/constant.h" -#include "generic/callbackfwd.h" +#include "generic/callback.h" class UndoMemento { diff --git a/include/mapfile.h b/include/mapfile.h index d20a957e..db3d4831 100644 --- a/include/mapfile.h +++ b/include/mapfile.h @@ -24,7 +24,7 @@ #include #include "iscenegraph.h" -#include "generic/callbackfwd.h" +#include "generic/callback.h" const std::size_t MAPFILE_MAX_CHANGES = std::numeric_limits::max(); diff --git a/include/modelskin.h b/include/modelskin.h index 68ab79d0..a08c95b2 100644 --- a/include/modelskin.h +++ b/include/modelskin.h @@ -22,7 +22,7 @@ #pragma once #include "generic/constant.h" -#include "generic/callbackfwd.h" +#include "generic/callback.h" class SkinRemap { diff --git a/include/nameable.h b/include/nameable.h index 856352a2..f357b388 100644 --- a/include/nameable.h +++ b/include/nameable.h @@ -22,7 +22,7 @@ #pragma once #include "generic/constant.h" -#include "generic/callbackfwd.h" +#include "generic/callback.h" typedef Callback1 NameCallback; diff --git a/include/namespace.h b/include/namespace.h index 1301d63f..7f515fbd 100644 --- a/include/namespace.h +++ b/include/namespace.h @@ -22,7 +22,7 @@ #pragma once #include "generic/constant.h" -#include "generic/callbackfwd.h" +#include "generic/callback.h" typedef Callback1 NameCallback; typedef Callback1 NameCallbackCallback; diff --git a/include/preferencesystem.h b/include/preferencesystem.h index 64b2ccb9..ac2cde31 100644 --- a/include/preferencesystem.h +++ b/include/preferencesystem.h @@ -22,7 +22,7 @@ #pragma once #include "generic/constant.h" -#include "generic/callbackfwd.h" +#include "generic/callback.h" typedef Callback1 StringImportCallback; typedef Callback1 StringExportCallback; diff --git a/include/selectable.h b/include/selectable.h index 92f7dcf9..b7905b99 100644 --- a/include/selectable.h +++ b/include/selectable.h @@ -25,7 +25,7 @@ #include "generic/vector.h" #include "scenelib.h" -#include "generic/callbackfwd.h" +#include "generic/callback.h" class SelectionIntersection { diff --git a/libs/generic/callback.h b/libs/generic/callback.h index d5c96715..12e3b0c3 100644 --- a/libs/generic/callback.h +++ b/libs/generic/callback.h @@ -26,7 +26,6 @@ #include #include "functional.h" -#include "callbackfwd.h" template inline void* convertToOpaque( Type* t ){ @@ -150,6 +149,9 @@ public: template 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. template class CallbackN; @@ -179,269 +181,214 @@ public: } }; -/// \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. -template -class Callback0 : public CallbackN -{ -public: - using CallbackN::CallbackN; -}; +namespace detail { + template + struct Arglist; -template -inline Callback0> makeCallback0( const Caller& caller, get_argument callee ){ - return Callback0>( BindFirstOpaque( callee ) ); -} -template -inline Callback0> makeStatelessCallback0( const Caller& caller ){ - return makeCallback0( Caller0To1(), 0 ); + template + struct Arglist + { + using type = R(Head, Ts...); + + template + using unshift = Arglist; + + using shift = Arglist; + }; + + template + struct Arglist + { + using type = R(Ts...); + + template + using unshift = Arglist; + }; } -typedef Callback0 Callback; - - - -/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and one other argument. -/// -/// Use with the callback constructors MemberCaller1, ConstMemberCaller1, ReferenceCaller1, ConstReferenceCaller1, PointerCaller1, ConstPointerCaller1 and FreeCaller1. -template -class Callback1 : public CallbackN -{ -public: - using CallbackN::CallbackN; -}; - template -inline Callback1, get_result_type> -makeCallback1( const Caller& caller, get_argument callee ){ - return Callback1, get_result_type>( BindFirstOpaque( callee ) ); -} -template -inline Callback1, get_result_type> makeStatelessCallback1( const Caller& caller ){ - return makeCallback1( Caller1To2(), 0 ); +inline CallbackN>::shift::type> makeCallbackN( const Caller& caller, get_argument callee ){ + return CallbackN>::shift::type>( BindFirstOpaque( callee ) ); } - -/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and two other arguments. -/// -template -class Callback2 : public CallbackN -{ -public: - using CallbackN::CallbackN; -}; - template -inline Callback2< - get_argument, - get_argument, - get_result_type -> makeCallback2( const Caller& caller, get_argument callee ){ - return Callback2< - get_argument, - get_argument, - get_result_type - >( BindFirstOpaque( callee ) ); -} -template -inline Callback2< - get_argument, - get_argument, - get_result_type -> makeStatelessCallback2( const Caller& caller){ - return makeCallback2( Caller2To3(), 0 ); +inline CallbackN> makeStatelessCallbackN( const Caller& caller ){ + return makeCallbackN( CallerShiftFirst>::template unshift::type>(), nullptr ); } +namespace detail { + template + struct MemberFunction; -/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and three other arguments. -/// -template -class Callback3 : public CallbackN -{ -public: - using CallbackN::CallbackN; -}; - -template -inline Callback3< - get_argument, - get_argument, - get_argument, - get_result_type -> makeCallback3( const Caller& caller, get_argument callee ){ - return Callback3< - get_argument, - get_argument, - get_argument, - get_result_type - >( BindFirstOpaque( callee ) ); -} -template -inline Callback3< - get_argument, - get_argument, - get_argument, - get_result_type -> makeStatelessCallback3( const Caller& caller ){ - return makeCallback3( Caller3To4(), 0 ); + template + struct MemberFunction + { + using type = R(Object::*)(Ts...); + using type_const = R(Object::*)(Ts...) const; + }; } +template +using MemberFunction = typename detail::MemberFunction::type; -/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and four other arguments. -/// -template -class Callback4 : public CallbackN -{ -public: - using CallbackN::CallbackN; -}; - -template -inline Callback4< - get_argument, - get_argument, - get_argument, - get_argument, - get_result_type -> makeCallback4( const Caller& caller, get_argument callee ){ - return Callback4< - get_argument, - get_argument, - get_argument, - get_argument, - get_result_type - >( BindFirstOpaque( callee ) ); -} -template -inline Callback4< - get_argument, - get_argument, - get_argument, - get_argument, - get_result_type -> makeStatelessCallback4( const Caller& caller ){ - return makeCallback4( Caller4To5(), 0 ); -} - +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 /// \until end example -template -using MemberCaller = BindFirstOpaque>; + +template member> +using MemberCallerN = 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 /// \until end example -template -using ConstMemberCaller = BindFirstOpaque>; - -/// \brief Forms a Callback from a non-const Environment reference and a const Environment member-function which takes one argument. -template -using MemberCaller1 = BindFirstOpaque>; - -/// \brief Forms a Callback from a const Environment reference and a const Environment member-function which takes one argument. -template -using ConstMemberCaller1 = BindFirstOpaque>; +template member> +using ConstMemberCallerN = 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 /// \until end example -template -using ReferenceCaller = BindFirstOpaque>; +template::template unshift::type *func> +using ReferenceCallerN = 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 /// \until end example -template -using ConstReferenceCaller = BindFirstOpaque>; - -/// \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 = BindFirstOpaque>; - -/// \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 = BindFirstOpaque>; +template::template unshift::type *func> +using ConstReferenceCallerN = 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 -using PointerCaller = BindFirstOpaque>; +template::template unshift::type *func> +using PointerCallerN = 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 -using ConstPointerCaller = BindFirstOpaque>; +template::template unshift::type *func> +using ConstPointerCallerN = 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 and one other argument. -template -using PointerCaller1 = BindFirstOpaque>; - -/// \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 = BindFirstOpaque>; - -/// \brief Forms a Callback from a free function which takes no arguments. -template -class FreeCaller : public BindFirstOpaque>> -{ +/// \brief Forms a Callback from a free function +template +class FreeCallerN : public BindFirstOpaque::template instance, + typename detail::Arglist::template unshift::type +>> { public: - FreeCaller() : BindFirstOpaque>>( 0 ){ + FreeCallerN() + : BindFirstOpaque::template instance, + typename detail::Arglist::template unshift::type + >>( nullptr ) { } }; -/// \brief Forms a Callback from a free function which takes a single argument. -template -class FreeCaller1 : public BindFirstOpaque>> -{ -public: - FreeCaller1() : BindFirstOpaque>>( 0 ){ - } -}; - - -/// \brief Constructs a Callback from a non-const \p functor with zero arguments. -/// -/// \param Functor Must define \c operator()(). -template -inline Callback makeCallback( Functor& functor ){ - return Callback( MemberCaller( functor ) ); -} - -/// \brief Constructs a Callback from a const \p functor with zero arguments. -/// -/// \param Functor Must define const \c operator()(). -template -inline Callback makeCallback( const Functor& functor ){ - return Callback( ConstMemberCaller( functor ) ); -} - -/// \brief Constructs a Callback1 from a non-const \p functor with one argument. +/// \brief Constructs a Callback1 from a non-const \p functor /// /// \param Functor Must define \c operator()(argument) and its signature as \c func. template -inline Callback1> makeCallback1( Functor& functor ){ - typedef get_argument FirstArgument; - return Callback1( MemberCaller1( functor ) ); +inline CallbackN> makeCallbackN( Functor& functor ){ + return CallbackN>( MemberCallerN, &Functor::operator()>( functor ) ); } -/// \brief Constructs a Callback1 from a const \p functor with one argument. +/// \brief Constructs a Callback1 from a const \p functor /// /// \param Functor Must define const \c operator()(argument) and its signature as \c func. template -inline Callback1> makeCallback1( const Functor& functor ){ - typedef get_argument FirstArgument; - return Callback1( ConstMemberCaller1( functor ) ); +inline CallbackN> makeCallbackN( const Functor& functor ){ + return CallbackN>( ConstMemberCallerN, &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; + +template +using Callback4 = 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 + +#define makeCallback4 makeCallbackN +#define makeStatelessCallback4 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; diff --git a/libs/generic/callbackfwd.h b/libs/generic/callbackfwd.h deleted file mode 100644 index 89ddb2d4..00000000 --- a/libs/generic/callbackfwd.h +++ /dev/null @@ -1,15 +0,0 @@ - -#pragma once - -template -class Callback0; -typedef Callback0 Callback; - -template -class Callback1; - -template -class Callback2; - -template -class Callback3; diff --git a/libs/generic/functional.h b/libs/generic/functional.h index c0252360..50ccdad1 100644 --- a/libs/generic/functional.h +++ b/libs/generic/functional.h @@ -197,6 +197,8 @@ public: template using FunctorInvoke = FunctorNInvoke>; +// todo: inline + template using Member = typename MemberN::template instance; @@ -238,38 +240,3 @@ using Function4 = typename FunctionN::template instance template using Function5 = typename FunctionN::template instance; - -template -using Caller0To1 = CallerShiftFirst( - FirstArgument -)>; - -template -using Caller1To2 = CallerShiftFirst( - FirstArgument, - get_argument -)>; - -template -using Caller2To3 = CallerShiftFirst( - FirstArgument, - get_argument, - get_argument -)>; - -template -using Caller3To4 = CallerShiftFirst( - FirstArgument, - get_argument, - get_argument, - get_argument -)>; - -template -using Caller4To5 = CallerShiftFirst( - FirstArgument, - get_argument, - get_argument, - get_argument, - get_argument -)>; diff --git a/libs/gtkutil/menu.h b/libs/gtkutil/menu.h index 69635cfb..936bc29e 100644 --- a/libs/gtkutil/menu.h +++ b/libs/gtkutil/menu.h @@ -21,7 +21,7 @@ #pragma once -#include "generic/callbackfwd.h" +#include "generic/callback.h" #include diff --git a/libs/gtkutil/toolbar.h b/libs/gtkutil/toolbar.h index d2341b40..ca88e943 100644 --- a/libs/gtkutil/toolbar.h +++ b/libs/gtkutil/toolbar.h @@ -21,7 +21,7 @@ #pragma once -#include "generic/callbackfwd.h" +#include "generic/callback.h" #include QAction* toolbar_append_button( QToolBar* toolbar, const char* description, const char* icon, const Callback& callback ); diff --git a/radiant/brushmanip.h b/radiant/brushmanip.h index 222ed58e..3c18ea1b 100644 --- a/radiant/brushmanip.h +++ b/radiant/brushmanip.h @@ -23,7 +23,7 @@ #include #include "string/stringfwd.h" -#include "generic/callbackfwd.h" +#include "generic/callback.h" enum class EBrushPrefab { diff --git a/radiant/selection.h b/radiant/selection.h index 1b37316f..29741084 100644 --- a/radiant/selection.h +++ b/radiant/selection.h @@ -22,7 +22,7 @@ #pragma once #include "windowobserver.h" -#include "generic/callbackfwd.h" +#include "generic/callback.h" #include "rect_t.h" typedef Callback1 RectangleCallback; diff --git a/radiant/textures.h b/radiant/textures.h index f9b64860..6bbff126 100644 --- a/radiant/textures.h +++ b/radiant/textures.h @@ -21,7 +21,7 @@ #pragma once -#include "generic/callbackfwd.h" +#include "generic/callback.h" void Textures_Realise(); void Textures_Unrealise(); diff --git a/radiant/texwindow.h b/radiant/texwindow.h index f02aea71..7ac72d51 100644 --- a/radiant/texwindow.h +++ b/radiant/texwindow.h @@ -21,7 +21,7 @@ #pragma once -#include "generic/callbackfwd.h" +#include "generic/callback.h" #include "signal/signalfwd.h" class QWidget; @@ -36,8 +36,6 @@ void TextureBrowser_Destroy(); typedef Callback1 StringImportCallback; -template -class FreeCaller1; extern QWidget* g_page_textures; void TextureBrowser_exportTitle( const StringImportCallback& importer );