#include "boost/type_traits/function_traits.hpp" namespace rbx { // icallable and callable are a lightweight wrapper similar to boost::function, // but with more efficient storage. Because the instances are special-cased for // the functor involved you can't treat callable generically - it has to be // used in the context of template code that knows what to do with it. // See rbx::signals for an implementation that uses this in lieu of boost::function template class icallable; template class icallable<0, Signature> { public: virtual void call() = 0; }; template class icallable<1, Signature> { public: virtual void call(typename boost::function_traits::arg1_type arg1) = 0; }; template class icallable<2, Signature> { public: virtual void call(typename boost::function_traits::arg1_type arg1, typename boost::function_traits::arg2_type arg2) = 0; }; template class icallable<3, Signature> { public: virtual void call(typename boost::function_traits::arg1_type arg1, typename boost::function_traits::arg2_type arg2, typename boost::function_traits::arg3_type arg3) = 0; }; template class icallable<4, Signature> { public: virtual void call(typename boost::function_traits::arg1_type arg1, typename boost::function_traits::arg2_type arg2, typename boost::function_traits::arg3_type arg3, typename boost::function_traits::arg4_type arg4) = 0; }; template class icallable<5, Signature> { public: virtual void call(typename boost::function_traits::arg1_type arg1, typename boost::function_traits::arg2_type arg2, typename boost::function_traits::arg3_type arg3, typename boost::function_traits::arg4_type arg4, typename boost::function_traits::arg5_type arg5) = 0; }; template class icallable<6, Signature> { public: virtual void call(typename boost::function_traits::arg1_type arg1, typename boost::function_traits::arg2_type arg2, typename boost::function_traits::arg3_type arg3, typename boost::function_traits::arg4_type arg4, typename boost::function_traits::arg5_type arg5, typename boost::function_traits::arg6_type arg6) = 0; }; template class icallable<7, Signature> { public: virtual void call(typename boost::function_traits::arg1_type arg1, typename boost::function_traits::arg2_type arg2, typename boost::function_traits::arg3_type arg3, typename boost::function_traits::arg4_type arg4, typename boost::function_traits::arg5_type arg5, typename boost::function_traits::arg6_type arg6, typename boost::function_traits::arg7_type arg7) = 0; }; template class callable; template class callable : public Base { Delegate deleg; public: template callable(const Delegate& d, Arg1 arg1) :Base(arg1) ,deleg(d) {} virtual void call() { deleg(); } }; template class callable : public Base { Delegate deleg; public: template callable(const Delegate& deleg, Arg1 arg1):Base(arg1),deleg(deleg) {} virtual void call(typename boost::function_traits::arg1_type arg1) { deleg(arg1); } }; template class callable : public Base { Delegate deleg; public: template callable(const Delegate& deleg, Arg1 arg1):Base(arg1),deleg(deleg) {} virtual void call( typename boost::function_traits::arg1_type arg1, typename boost::function_traits::arg2_type arg2 ) { deleg(arg1, arg2); } }; template class callable : public Base { Delegate deleg; public: template callable(const Delegate& deleg, Arg1 arg1):Base(arg1),deleg(deleg) {} virtual void call( typename boost::function_traits::arg1_type arg1, typename boost::function_traits::arg2_type arg2, typename boost::function_traits::arg3_type arg3 ) { deleg(arg1, arg2, arg3); } }; template class callable : public Base { Delegate deleg; public: template callable(const Delegate& deleg, Arg1 arg1):Base(arg1),deleg(deleg) {} virtual void call( typename boost::function_traits::arg1_type arg1, typename boost::function_traits::arg2_type arg2, typename boost::function_traits::arg3_type arg3, typename boost::function_traits::arg4_type arg4 ) { deleg(arg1, arg2, arg3, arg4); } }; template class callable : public Base { Delegate deleg; public: template callable(const Delegate& deleg, Arg1 arg1):Base(arg1),deleg(deleg) {} virtual void call( typename boost::function_traits::arg1_type arg1, typename boost::function_traits::arg2_type arg2, typename boost::function_traits::arg3_type arg3, typename boost::function_traits::arg4_type arg4, typename boost::function_traits::arg5_type arg5 ) { deleg(arg1, arg2, arg3, arg4, arg5); } }; template class callable : public Base { Delegate deleg; public: template callable(const Delegate& deleg, Arg1 arg1):Base(arg1),deleg(deleg) {} virtual void call( typename boost::function_traits::arg1_type arg1, typename boost::function_traits::arg2_type arg2, typename boost::function_traits::arg3_type arg3, typename boost::function_traits::arg4_type arg4, typename boost::function_traits::arg5_type arg5, typename boost::function_traits::arg6_type arg6 ) { deleg(arg1, arg2, arg3, arg4, arg5, arg6); } }; template class callable : public Base { Delegate deleg; public: template callable(const Delegate& deleg, Arg1 arg1):Base(arg1),deleg(deleg) {} virtual void call( typename boost::function_traits::arg1_type arg1, typename boost::function_traits::arg2_type arg2, typename boost::function_traits::arg3_type arg3, typename boost::function_traits::arg4_type arg4, typename boost::function_traits::arg5_type arg5, typename boost::function_traits::arg6_type arg6, typename boost::function_traits::arg7_type arg7 ) { deleg(arg1, arg2, arg3, arg4, arg5, arg6, arg7); } }; }