00001
00006 #ifndef BOOST_PP_IS_ITERATING
00007
00008 # ifndef CMT_DELEGATE_IMPL_HPP_INCLUDED
00009 # define CMT_DELEGATE_IMPL_HPP_INCLUDED
00010
00011 # include <boost/future/future.hpp>
00012 # include <boost/preprocessor/repetition.hpp>
00013 # include <boost/preprocessor/arithmetic/sub.hpp>
00014 # include <boost/preprocessor/punctuation/comma_if.hpp>
00015
00016 # ifndef MAX_CMT_ASYNC_DELEGATE_PARAM
00017 # define MAX_CMT_ASYNC_DELEGATE_PARAM 8
00018 # endif
00019
00020
00021 namespace boost {
00022 namespace detail {
00023
00025
00028 template<int N, typename Signature>
00029 struct async_delegate_impl{};
00031 #define PARAM_TYPE(z,n,type) BOOST_PP_CAT(BOOST_PP_CAT(typename traits::arg,BOOST_PP_ADD(n,1)),_type)
00032 #define PARAM_NAME(z,n,type) BOOST_PP_CAT(a,n)
00033 #define PARAM_ARG(z,n,type) PARAM_TYPE(z,n,type) PARAM_NAME(z,n,type)
00034
00035 # include <boost/preprocessor/iteration/iterate.hpp>
00036 # define BOOST_PP_ITERATION_LIMITS (0, MAX_CMT_ASYNC_DELEGATE_PARAM )
00037 # define BOOST_PP_FILENAME_1 <boost/cmt/detail/async_delegate_impl.hpp>
00038 # include BOOST_PP_ITERATE()
00039
00040 #undef PARAM_TYPE
00041 #undef PARAM_NAME
00042 #undef PARAM_ARG
00043 }
00044 }
00045
00046 # endif // CMT_DELEGATE_IMPL_HPP_INCLUDED
00047
00048 #else // BOOST_PP_IS_ITERATING
00049
00050 # define n BOOST_PP_ITERATION()
00051 #define PARAM_TYPES BOOST_PP_ENUM(n,PARAM_TYPE,A) // TYPE_N
00052 #define PARAM_NAMES BOOST_PP_ENUM(n,PARAM_NAME,A) // name_N
00053 #define PARAM_ARGS BOOST_PP_ENUM(n,PARAM_ARG,A) // TYPE_N name_N
00054
00055 template<typename Signature>
00056 class async_delegate_impl<n, Signature >
00057 {
00058 public:
00059 typedef boost::function_traits<Signature> traits;
00060 future<typename traits::result_type> operator()(PARAM_ARGS)
00061 {
00062 return m_thr.async<typename traits::result_type>( boost::bind(m_del,PARAM_NAMES) );
00063 }
00064
00065 template<typename Functor>
00066 async_delegate_impl( Functor f, thread& t )
00067 :m_del(f),m_thr(t)
00068 {
00069 }
00070
00071 private:
00072 boost::function<Signature> m_del;
00073 thread& m_thr;
00074 };
00075
00076
00077 #undef n
00078 #undef PARAM_TYPES
00079 #undef PARAM_NAMES
00080 #undef PARAM_ARGS
00081
00082 #endif // BOOST_PP_IS_ITERATING
00083