SAGA Adaptor CPI v.1.0
|
00001 // Copyright (c) 2005-2006 Stephan Hirmer (shirmer@cct.lsu.edu) 00002 // 00003 // Distributed under the Boost Software License, Version 1.0. (See accompanying 00004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 00005 00006 #if !defined(BOOST_PP_IS_ITERATING) 00007 00008 #if !defined(SAGA_ADAPTOR_BULK_CONTAINER_IMPL_HPP) 00009 #define SAGA_ADAPTOR_BULK_CONTAINER_IMPL_HPP 00010 00011 #include <saga/impl/config.hpp> 00012 00013 #include <boost/preprocessor/iterate.hpp> 00014 #include <boost/preprocessor/repetition/enum_params.hpp> 00015 #include <boost/preprocessor/repetition/enum_binary_params.hpp> 00016 #include <boost/preprocessor/repetition/repeat.hpp> 00017 #include <boost/preprocessor/comma_if.hpp> 00018 00019 #define BOOST_PP_ITERATION_PARAMS_1 \ 00020 (3, (1, SAGA_ARGUMENT_LIMIT, \ 00021 "saga/saga/adaptors/bulk_container_impl.hpp")) \ 00022 00023 00024 #include BOOST_PP_ITERATE() 00025 00026 #endif // SAGA_ADAPTOR_BULK_CONTAINER_IMPL_HPP 00027 00029 // 00030 // Preprocessor vertical repetition code 00031 // 00033 #else // defined(BOOST_PP_IS_ITERATING) 00034 00035 #define O BOOST_PP_ITERATION() 00036 00037 #define GET_PARAM_VEC_REF(z, M, _) BOOST_PP_COMMA_IF(M) std::vector< FuncArg ## M >& 00038 00039 00048 template< 00049 typename Cpi, typename FuncRetVal, 00050 BOOST_PP_ENUM_PARAMS (O, typename FuncArg) 00051 > 00052 inline void 00053 create_bulk_container_or_add_params(Cpi* cpi, bulk_container_base *& bc, 00054 std::vector<saga::uuid> (Cpi::*exec_bulk)( 00055 std::vector<FuncRetVal>&, BOOST_PP_REPEAT(O, GET_PARAM_VEC_REF, _) 00056 , std::vector<saga::uuid>&), 00057 FuncRetVal retval, BOOST_PP_ENUM_BINARY_PARAMS (O, FuncArg, func_arg), 00058 saga::uuid task_uuid 00059 ) 00060 { 00061 typedef saga::adaptors::bulk_container< 00062 Cpi, FuncRetVal, BOOST_PP_ENUM_PARAMS (O, FuncArg) 00063 > bulk_container_type; 00064 00065 if (NULL == bc) 00066 bc = new bulk_container_type(cpi, exec_bulk, retval, 00067 BOOST_PP_ENUM_PARAMS (O, func_arg), 00068 task_uuid); 00069 else 00070 static_cast<bulk_container_type *>(bc)->add_params(retval, 00071 BOOST_PP_ENUM_PARAMS (O, func_arg), 00072 task_uuid); 00073 } 00074 00075 00076 #define GET_MEMBER_VEC(z, M, _) std::vector< FuncArg ## M > vec_ ## M ; 00077 #define GET_PARAM_VEC(z, M, _) BOOST_PP_COMMA_IF(M) std::vector< FuncArg ## M > 00078 #define GET_PUSHBACK_VEC(z, M, _) vec_ ## M.push_back(func_arg ## M ); 00079 #define GET_DEFAULT_ARG(z, M, _) BOOST_PP_COMMA() phoenix::nil_t 00080 00082 00092 template<typename Cpi, typename FuncRetVal, 00093 BOOST_PP_ENUM_PARAMS (O, typename FuncArg)> 00094 class bulk_container<Cpi, FuncRetVal, 00095 BOOST_PP_ENUM_PARAMS (O, FuncArg) 00096 BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_PP_SUB(SAGA_ARGUMENT_LIMIT, O)), GET_DEFAULT_ARG, _) 00097 > 00098 : public saga::adaptors::bulk_container_base 00099 { 00100 private: 00101 std::vector<FuncRetVal> rets; 00102 std::vector<saga::uuid> uuids; 00103 BOOST_PP_REPEAT(O, GET_MEMBER_VEC, _) 00104 00105 std::vector<saga::uuid> (Cpi::*exec_bulk)(std::vector<FuncRetVal>&, 00106 BOOST_PP_REPEAT(O, GET_PARAM_VEC_REF, _) 00107 , std::vector<saga::uuid>&); 00108 Cpi* my_adaptor; 00109 00110 public: 00116 bulk_container (Cpi * cpi_, 00117 std::vector <saga::uuid> (Cpi::*exec_bulk_) 00118 (std::vector<FuncRetVal>&, 00119 BOOST_PP_REPEAT(O, GET_PARAM_VEC_REF, _) 00120 , std::vector<saga::uuid>&), 00121 FuncRetVal retval, 00122 BOOST_PP_ENUM_BINARY_PARAMS (O, FuncArg, func_arg), 00123 saga::uuid task_uuid) 00124 : exec_bulk (exec_bulk_), 00125 my_adaptor (cpi_) 00126 { 00127 this->add_params (retval, BOOST_PP_ENUM_PARAMS (O, func_arg), 00128 task_uuid); 00129 } 00130 00134 ~bulk_container(void) 00135 { 00136 } 00137 00141 bulk_container *add_params(FuncRetVal retval, 00142 BOOST_PP_ENUM_BINARY_PARAMS (O, FuncArg, func_arg), 00143 saga::uuid task_uuid) 00144 { 00145 rets.push_back(retval); 00146 uuids.push_back(task_uuid); 00147 BOOST_PP_REPEAT(O, GET_PUSHBACK_VEC, _) 00148 return this; 00149 } 00150 00155 std::vector<saga::uuid> execute_bulk() 00156 { 00157 return ((my_adaptor->*exec_bulk)(rets, 00158 BOOST_PP_ENUM_PARAMS (O, vec_) , 00159 uuids)); 00160 } 00161 00162 }; // class bulk_container 00163 00164 #undef GET_DEFAULT_ARG 00165 #undef GET_PARAM_VEC 00166 #undef GET_MEMBER_VEC 00167 #undef GET_PARAM_VEC 00168 #undef GET_PUSHBACK_VEC 00169 #undef O 00170 00171 #endif // defined(BOOST_PP_IS_ITERATING) 00172