1 | /* |
2 | * has_pack_agg.hpp |
3 | * |
4 | * Created on: Feb 10, 2016 |
5 | * Author: yaroslav |
6 | */ |
7 | |
8 | #ifndef SRC_PACKER_UNPACKER_HAS_PACK_AGG_HPP_ |
9 | #define SRC_PACKER_UNPACKER_HAS_PACK_AGG_HPP_ |
10 | |
11 | #include "prp_all_zero.hpp" |
12 | #include "Vector/vect_isel.hpp" |
13 | |
14 | /*! \brief These set of classes generate an array definition at compile-time |
15 | * |
16 | * These set of classes generate an array definition at compile-time |
17 | * |
18 | * \see generate_array |
19 | * |
20 | */ |
21 | |
22 | #include <boost/fusion/mpl.hpp> |
23 | |
24 | /////////////////////////////////////////////////// |
25 | |
26 | |
27 | |
28 | /////////////// Classes to generate at compile time arrays from a boost::mpl::vector |
29 | |
30 | //! Generate the array specializing ArrayHolder |
31 | template<class T, size_t N , typename result_p ,class vprp> |
32 | struct has_pack_agg_impl |
33 | { |
34 | typedef typename boost::mpl::at<vprp,typename boost::mpl::int_<N-1>>::type vprp_N; |
35 | typedef typename boost::mpl::at<typename T::type,vprp_N>::type stype; |
36 | typedef typename boost::mpl::bool_<has_pack<stype>::value | result_p::value> result_n; |
37 | typedef typename has_pack_agg_impl<T,N-1,result_n,vprp>::result result; |
38 | }; |
39 | |
40 | //! terminator of the variadic template |
41 | template<class T, typename result_p, class vprp> |
42 | struct has_pack_agg_impl<T,0,result_p,vprp> |
43 | { |
44 | typedef boost::mpl::bool_<result_p::value> result; |
45 | // typedef std::vector<result_p::value> fail; |
46 | }; |
47 | |
48 | template<typename T, int np> |
49 | struct number_prop |
50 | { |
51 | enum |
52 | { |
53 | value = np |
54 | }; |
55 | }; |
56 | |
57 | //! return the number of properties the type T has |
58 | template<typename T> |
59 | struct number_prop<T,0> |
60 | { |
61 | enum |
62 | { |
63 | value = T::max_prop |
64 | }; |
65 | }; |
66 | |
67 | //! return if true the aggregate type T has a property that has a complex packing(serialization) method |
68 | template<class T, int ... prp> |
69 | struct has_pack_agg |
70 | { |
71 | typedef typename prp_all_zero<T,sizeof...(prp) == 0,prp...>::type vprp; |
72 | |
73 | //! typedef typename to_boost_vmpl<prp...>::type vprp; |
74 | typedef typename has_pack_agg_impl<T,number_prop<T,sizeof ... (prp)>::value, boost::mpl::bool_<false> , vprp>::result result; |
75 | }; |
76 | |
77 | //! It return true if the object T require complex serialization |
78 | template<class T, unsigned int sel = openfpm::vect_isel<T>::value == OPENFPM_NATIVE> |
79 | struct has_pack_gen |
80 | { |
81 | enum |
82 | { |
83 | value = has_pack_agg<T>::result::value |
84 | }; |
85 | }; |
86 | |
87 | //! It return true if the object T require complex serialization |
88 | template<class T> |
89 | struct has_pack_gen<T, false> |
90 | { |
91 | enum |
92 | { |
93 | value = has_pack<T>::type::value |
94 | }; |
95 | }; |
96 | |
97 | |
98 | #endif /* SRC_PACKER_UNPACKER_HAS_PACK_AGG_HPP_ */ |
99 | |