1 | /* |
2 | * copy_fusion_vector.hpp |
3 | * |
4 | * Created on: Nov 1, 2015 |
5 | * Author: i-bird |
6 | */ |
7 | |
8 | #ifndef OPENFPM_DATA_SRC_GRID_COPY_FUSION_VECTOR_HPP_ |
9 | #define OPENFPM_DATA_SRC_GRID_COPY_FUSION_VECTOR_HPP_ |
10 | |
11 | |
12 | /*! \brief this class is a functor for "for_each" algorithm |
13 | * |
14 | * It copy a boost::fusion::vector into an encap |
15 | * |
16 | */ |
17 | template<typename bfv, typename enc> |
18 | struct copy_fusion_vector_encap |
19 | { |
20 | //! source fusion vector |
21 | const bfv & src; |
22 | |
23 | //! destination fusion vector |
24 | enc & dst; |
25 | |
26 | /*! \brief constructor |
27 | * |
28 | * It define the copy parameters. |
29 | * |
30 | * \param src source fusion vector |
31 | * \param dst destination fusion vector |
32 | * |
33 | */ |
34 | __device__ __host__ inline copy_fusion_vector_encap(const bfv & src, enc & dst) |
35 | :src(src),dst(dst){}; |
36 | |
37 | #ifdef SE_CLASS1 |
38 | /*! \brief Constructor |
39 | * |
40 | * Calling this constructor produce an error. This class store the reference of the object, |
41 | * this mean that the object passed must not be a temporal object |
42 | * |
43 | */ |
44 | inline copy_fusion_vector_encap(const bfv && src, enc && dst) |
45 | :src(src),dst(dst) |
46 | {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object\n" ;}; |
47 | #endif |
48 | |
49 | //! It call the copy function for each property |
50 | template<typename T> |
51 | __device__ __host__ inline void operator()(T& t) |
52 | { |
53 | typedef typename boost::mpl::at<bfv,boost::mpl::int_<T::value> >::type copy_src; |
54 | typedef typename std::remove_reference<decltype(dst.template get<T::value>())>::type copy_dst; |
55 | |
56 | meta_copy_d<copy_src,copy_dst>::meta_copy_d_(boost::fusion::at_c<T::value>(src),dst.template get<T::value>()); |
57 | } |
58 | }; |
59 | |
60 | |
61 | /*! \brief this class is a functor for "for_each" algorithm |
62 | * |
63 | * It copy a boost::fusion::vector into an encap |
64 | * |
65 | */ |
66 | template<typename enc, typename bfv> |
67 | struct copy_encap_vector_fusion |
68 | { |
69 | //! source fusion vector |
70 | const enc & src; |
71 | |
72 | //! destination fusion vector |
73 | bfv & dst; |
74 | |
75 | /*! \brief constructor |
76 | * |
77 | * It define the copy parameters. |
78 | * |
79 | * \param src source fusion vector |
80 | * \param dst destination fusion vector |
81 | * |
82 | */ |
83 | __device__ __host__ inline copy_encap_vector_fusion(const enc & src, bfv & dst) |
84 | :src(src),dst(dst){}; |
85 | |
86 | #ifdef SE_CLASS1 |
87 | /*! \brief Constructor |
88 | * |
89 | * Calling this constructor produce an error. This class store the reference of the object, |
90 | * this mean that the object passed must not be a temporal object |
91 | * |
92 | */ |
93 | __device__ __host__ inline copy_encap_vector_fusion(const enc && src, bfv && dst) |
94 | :src(src),dst(dst) |
95 | {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object\n" ;}; |
96 | #endif |
97 | |
98 | //! It call the copy function for each property |
99 | template<typename T> |
100 | __device__ __host__ inline void operator()(T& t) |
101 | { |
102 | typedef typename boost::mpl::at<bfv,boost::mpl::int_<T::value> >::type copy_dst; |
103 | typedef typename std::remove_reference<decltype(src.template get<T::value>())>::type copy_src; |
104 | |
105 | meta_copy_d<copy_src,copy_dst>::meta_copy_d_(src.template get<T::value>(),boost::fusion::at_c<T::value>(dst)); |
106 | } |
107 | }; |
108 | |
109 | #endif /* OPENFPM_DATA_SRC_GRID_COPY_FUSION_VECTOR_HPP_ */ |
110 | |