1 | /* |
2 | * util.hpp |
3 | * |
4 | * Created on: Jul 16, 2015 |
5 | * Author: i-bird |
6 | */ |
7 | |
8 | #ifndef SRC_VECTOR_UTIL_HPP_ |
9 | #define SRC_VECTOR_UTIL_HPP_ |
10 | |
11 | #include "util/common.hpp" |
12 | |
13 | |
14 | template<typename T, typename Sfinae = void> |
15 | struct is_vector: std::false_type {}; |
16 | |
17 | /*! \brief is_grid check if the type is a vector |
18 | * |
19 | * ### Example |
20 | * |
21 | * \snippet util.hpp Check is_vector |
22 | * |
23 | * return true if T is a vector |
24 | * |
25 | */ |
26 | template<typename T> |
27 | struct is_vector<T, typename Void< typename T::yes_i_am_vector>::type > : std::true_type |
28 | {}; |
29 | |
30 | /////////////////////////////////////////////////////////////////////////////////////////////////////////// |
31 | |
32 | template<typename T, typename Sfinae = void> |
33 | struct is_vector_native: std::false_type {}; |
34 | |
35 | |
36 | /*! \brief is_grid check if the type is a vector |
37 | * |
38 | * ### Example |
39 | * |
40 | * \snippet util.hpp Check is_vector |
41 | * |
42 | * return true if T is a vector |
43 | * |
44 | */ |
45 | template<typename T> |
46 | struct is_vector_native<T, typename Void< typename T::yes_i_am_vector_native>::type > : std::true_type |
47 | {}; |
48 | |
49 | /////////////////////////////////////////////////////////////////////////////////////////////////////////// |
50 | |
51 | template<typename T, typename Sfinae = void> |
52 | struct is_vector_dist: std::false_type {}; |
53 | |
54 | |
55 | /*! \brief is_grid check if the type is a vector |
56 | * |
57 | * ### Example |
58 | * |
59 | * \snippet util.hpp Check is_vector |
60 | * |
61 | * return true if T is a vector |
62 | * |
63 | */ |
64 | template<typename T> |
65 | struct is_vector_dist<T, typename Void< typename T::yes_i_am_vector_dist>::type > : std::true_type |
66 | {}; |
67 | |
68 | /////////////////////////////////////////////////////////////////////////////////////////////////////////// |
69 | |
70 | /*! \brief Check this is a gpu or cpu type cell-list |
71 | * |
72 | */ |
73 | template<typename T, typename Sfinae = void> |
74 | struct is_gpu_celllist: std::false_type {}; |
75 | |
76 | |
77 | template<typename T> |
78 | struct is_gpu_celllist<T, typename Void<typename T::yes_is_gpu_celllist>::type> : std::true_type |
79 | {}; |
80 | |
81 | /////////////////////////////////////////////////////////////////////////////////////////////////////////// |
82 | |
83 | /*! \brief Check this is a gpu or cpu type cell-list |
84 | * |
85 | */ |
86 | template<typename T, typename Sfinae = void> |
87 | struct is_gpu_ker_celllist: std::false_type {}; |
88 | |
89 | |
90 | template<typename T> |
91 | struct is_gpu_ker_celllist<T, typename Void<typename T::yes_is_gpu_ker_celllist>::type> : std::true_type |
92 | {}; |
93 | |
94 | // structure to check the device pointer |
95 | |
96 | /*! \brief this class is a functor for "for_each" algorithm |
97 | * |
98 | * This class is a functor for "for_each" algorithm. It check if the |
99 | * pointer ptr match one of the pointer properties |
100 | * |
101 | */ |
102 | template<typename data_type> |
103 | struct check_device_ptr |
104 | { |
105 | //! pointer to check |
106 | void * ptr; |
107 | |
108 | //! Data to check |
109 | data_type & data; |
110 | |
111 | mutable int prp; |
112 | |
113 | mutable bool result; |
114 | |
115 | /*! \brief constructor |
116 | * |
117 | * \param ptr pointer to check |
118 | * \param data data structure |
119 | * |
120 | */ |
121 | inline check_device_ptr(void * ptr, data_type & data) |
122 | :ptr(ptr),data(data),result(false) |
123 | {}; |
124 | |
125 | //! It call the copy function for each property |
126 | template<typename T> |
127 | inline void operator()(T& t) |
128 | { |
129 | if (data.template getPointer<T::value>() == ptr) |
130 | { |
131 | prp = T::value; |
132 | result = true; |
133 | } |
134 | } |
135 | }; |
136 | |
137 | #endif /* SRC_VECTOR_UTIL_HPP_ */ |
138 | |