| 1 | /* | 
|---|
| 2 | * t_to_memory_c.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Aug 27, 2014 | 
|---|
| 5 | *      Author: Pietro Incardona | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef T_TO_MEMORY_C_HPP_ | 
|---|
| 9 | #define T_TO_MEMORY_C_HPP_ | 
|---|
| 10 |  | 
|---|
| 11 | #include <boost/mpl/int.hpp> | 
|---|
| 12 | #include <memory_ly/memory_c.hpp> | 
|---|
| 13 |  | 
|---|
| 14 | /*! \brief t_to_memory_c is a metafunction that given T it convert it into | 
|---|
| 15 | * | 
|---|
| 16 | * t_to_memory_c<T>::type to memory_c<T> for scalar | 
|---|
| 17 | * | 
|---|
| 18 | * or | 
|---|
| 19 | * | 
|---|
| 20 | * t_to_memory_c<T[N1][N2]>::type to memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int<N1>,boost::mpl::int<N2>>>> | 
|---|
| 21 | * | 
|---|
| 22 | * for vector | 
|---|
| 23 | * | 
|---|
| 24 | * | 
|---|
| 25 | * Here we specialize t_to_memory_c for several dimensionalities | 
|---|
| 26 | * | 
|---|
| 27 | * \param T type | 
|---|
| 28 | * \param N1 .... N10 dimensions | 
|---|
| 29 | * | 
|---|
| 30 | */ | 
|---|
| 31 |  | 
|---|
| 32 | #include <boost/type_traits/remove_reference.hpp> | 
|---|
| 33 | #include <boost/type_traits/remove_const.hpp> | 
|---|
| 34 |  | 
|---|
| 35 | // First thing the metafunction has to do, is to remove eventually reference and const attribute | 
|---|
| 36 |  | 
|---|
| 37 | template<typename T> | 
|---|
| 38 | struct remove_attributes_const_ref | 
|---|
| 39 | { | 
|---|
| 40 | //! remove all attributes const and reference from the type | 
|---|
| 41 | typedef typename boost::remove_const <typename boost::remove_reference< T >::type >::type type; | 
|---|
| 42 | }; | 
|---|
| 43 |  | 
|---|
| 44 | //! Partial specialization for scalar N=0 | 
|---|
| 45 | template<typename T> | 
|---|
| 46 | struct t_to_memory_c_impl | 
|---|
| 47 | { | 
|---|
| 48 | //! transform a type T into memory_c<T> | 
|---|
| 49 | typedef memory_c<T> type; | 
|---|
| 50 | }; | 
|---|
| 51 |  | 
|---|
| 52 | //! Partial specialization for scalar N=0 | 
|---|
| 53 | template<typename T> | 
|---|
| 54 | struct t_to_memory_c_red_impl | 
|---|
| 55 | { | 
|---|
| 56 | //! transform a type T into memory_c<T,MEMORY_C_REDUCED> | 
|---|
| 57 | typedef memory_c<T,MEMORY_C_REDUCED> type; | 
|---|
| 58 | }; | 
|---|
| 59 |  | 
|---|
| 60 |  | 
|---|
| 61 | //! Partial specialization for N=1 | 
|---|
| 62 | template<typename T,size_t N1> | 
|---|
| 63 | struct t_to_memory_c_impl<T[N1]> | 
|---|
| 64 | { | 
|---|
| 65 | //! transfrom a type T into memory_c<T> | 
|---|
| 66 | typedef memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int_<N1>>>> type; | 
|---|
| 67 |  | 
|---|
| 68 | //! the internal array primitive information represented into a boost mpl vector | 
|---|
| 69 | typedef boost::mpl::vector<T,boost::mpl::int_<N1>> prim_vmpl; | 
|---|
| 70 | }; | 
|---|
| 71 |  | 
|---|
| 72 | //! Partial specialization for N=1 | 
|---|
| 73 | template<typename T,size_t N1> | 
|---|
| 74 | struct t_to_memory_c_red_impl<T[N1]> | 
|---|
| 75 | { | 
|---|
| 76 | //! transform a type T into memory_c<T,MEMORY_C_REDUCED> | 
|---|
| 77 | typedef memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int_<N1>>>,MEMORY_C_REDUCED> type; | 
|---|
| 78 |  | 
|---|
| 79 | //! the internal array primitive information represented into a boost mpl vector | 
|---|
| 80 | typedef boost::mpl::vector<T,boost::mpl::int_<N1>> prim_vmpl; | 
|---|
| 81 | }; | 
|---|
| 82 |  | 
|---|
| 83 | //! Partial specialization for N=2 | 
|---|
| 84 | template<typename T,size_t N1,size_t N2> | 
|---|
| 85 | struct t_to_memory_c_impl<T[N1][N2]> | 
|---|
| 86 | { | 
|---|
| 87 | //! tranform a type T into a memory_c<multi_array<.......>> | 
|---|
| 88 | typedef memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int_<N1>, | 
|---|
| 89 | boost::mpl::int_<N2>>>> type; | 
|---|
| 90 |  | 
|---|
| 91 |  | 
|---|
| 92 | //! the internal array primitive information represented into a boost mpl vector | 
|---|
| 93 | typedef boost::mpl::vector<T,boost::mpl::int_<N1>, | 
|---|
| 94 | boost::mpl::int_<N2>> prim_vmpl; | 
|---|
| 95 | }; | 
|---|
| 96 |  | 
|---|
| 97 | //! Partial specialization for N=2 | 
|---|
| 98 | template<typename T,size_t N1,size_t N2> | 
|---|
| 99 | struct t_to_memory_c_red_impl<T[N1][N2]> | 
|---|
| 100 | { | 
|---|
| 101 | //! transform a type T into a memory_c<multi_array<.......>,MEMORY_C_REDUCED> | 
|---|
| 102 | typedef memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int_<N1>, | 
|---|
| 103 | boost::mpl::int_<N2>>>,MEMORY_C_REDUCED> type; | 
|---|
| 104 |  | 
|---|
| 105 | //! the internal array primitive information represented into a boost mpl vector | 
|---|
| 106 | typedef boost::mpl::vector<T,boost::mpl::int_<N1>, | 
|---|
| 107 | boost::mpl::int_<N2>> prim_vmpl; | 
|---|
| 108 | }; | 
|---|
| 109 |  | 
|---|
| 110 | //! Partial specialization for N=3 | 
|---|
| 111 | template<typename T,size_t N1,size_t N2,size_t N3> | 
|---|
| 112 | struct t_to_memory_c_impl<T[N1][N2][N3]> | 
|---|
| 113 | { | 
|---|
| 114 | //! tranform a type T into a memory_c<multi_array<.......>> | 
|---|
| 115 | typedef memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int_<N1>, | 
|---|
| 116 | boost::mpl::int_<N2>, | 
|---|
| 117 | boost::mpl::int_<N3>>>> type; | 
|---|
| 118 | }; | 
|---|
| 119 |  | 
|---|
| 120 | //! Partial specialization for N=3 | 
|---|
| 121 | template<typename T,size_t N1,size_t N2,size_t N3> | 
|---|
| 122 | struct t_to_memory_c_red_impl<T[N1][N2][N3]> | 
|---|
| 123 | { | 
|---|
| 124 | //! tranform a type T into a memory_c<multi_array<.......>> | 
|---|
| 125 | typedef memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int_<N1>, | 
|---|
| 126 | boost::mpl::int_<N2>, | 
|---|
| 127 | boost::mpl::int_<N3>>>,MEMORY_C_REDUCED> type; | 
|---|
| 128 | }; | 
|---|
| 129 |  | 
|---|
| 130 | //! Partial specialization for N=4 | 
|---|
| 131 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4> | 
|---|
| 132 | struct t_to_memory_c_impl<T[N1][N2][N3][N4]> | 
|---|
| 133 | { | 
|---|
| 134 | //! tranform a type T into a memory_c<multi_array<.......>> | 
|---|
| 135 | typedef memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int_<N1>, | 
|---|
| 136 | boost::mpl::int_<N2>, | 
|---|
| 137 | boost::mpl::int_<N3>, | 
|---|
| 138 | boost::mpl::int_<N4>>>> type; | 
|---|
| 139 | }; | 
|---|
| 140 |  | 
|---|
| 141 | //! Partial specialization for N=4 | 
|---|
| 142 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4> | 
|---|
| 143 | struct t_to_memory_c_red_impl<T[N1][N2][N3][N4]> | 
|---|
| 144 | { | 
|---|
| 145 | //! tranform a type T into a memory_c<multi_array<.......>,MEMORY_C_REDUCED> | 
|---|
| 146 | typedef memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int_<N1>, | 
|---|
| 147 | boost::mpl::int_<N2>, | 
|---|
| 148 | boost::mpl::int_<N3>, | 
|---|
| 149 | boost::mpl::int_<N4>>>,MEMORY_C_REDUCED> type; | 
|---|
| 150 | }; | 
|---|
| 151 |  | 
|---|
| 152 | //! Partial specialization for N=5 | 
|---|
| 153 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5> | 
|---|
| 154 | struct t_to_memory_c_impl<T[N1][N2][N3][N4][N5]> | 
|---|
| 155 | { | 
|---|
| 156 | //! tranform a type T into a memory_c<multi_array<.......>> | 
|---|
| 157 | typedef memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int_<N1>, | 
|---|
| 158 | boost::mpl::int_<N2>, | 
|---|
| 159 | boost::mpl::int_<N3>, | 
|---|
| 160 | boost::mpl::int_<N4>, | 
|---|
| 161 | boost::mpl::int_<N5>>>> type; | 
|---|
| 162 | }; | 
|---|
| 163 |  | 
|---|
| 164 | //! Partial specialization for N=5 | 
|---|
| 165 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5> | 
|---|
| 166 | struct t_to_memory_c_red_impl<T[N1][N2][N3][N4][N5]> | 
|---|
| 167 | { | 
|---|
| 168 | //! tranform a type T into a memory_c<multi_array<.......>,MEMORY_C_REDUCED> | 
|---|
| 169 | typedef memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int_<N1>, | 
|---|
| 170 | boost::mpl::int_<N2>, | 
|---|
| 171 | boost::mpl::int_<N3>, | 
|---|
| 172 | boost::mpl::int_<N4>, | 
|---|
| 173 | boost::mpl::int_<N5>>>,MEMORY_C_REDUCED> type; | 
|---|
| 174 | }; | 
|---|
| 175 |  | 
|---|
| 176 | //! Partial specialization for N=6 | 
|---|
| 177 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5, size_t N6> | 
|---|
| 178 | struct t_to_memory_c_impl<T[N1][N2][N3][N4][N5][N6]> | 
|---|
| 179 | { | 
|---|
| 180 | //! tranform a type T into a memory_c<multi_array<.......>> | 
|---|
| 181 | typedef memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int_<N1>, | 
|---|
| 182 | boost::mpl::int_<N2>, | 
|---|
| 183 | boost::mpl::int_<N3>, | 
|---|
| 184 | boost::mpl::int_<N4>, | 
|---|
| 185 | boost::mpl::int_<N5>, | 
|---|
| 186 | boost::mpl::int_<N6>>>> type; | 
|---|
| 187 | }; | 
|---|
| 188 |  | 
|---|
| 189 | //! Partial specialization for N=7 | 
|---|
| 190 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5, size_t N6, size_t N7> | 
|---|
| 191 | struct t_to_memory_c_impl<T[N1][N2][N3][N4][N5][N6][N7]> | 
|---|
| 192 | { | 
|---|
| 193 | //! tranform a type T into a memory_c<multi_array<.......>> | 
|---|
| 194 | typedef memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int_<N1>, | 
|---|
| 195 | boost::mpl::int_<N2>, | 
|---|
| 196 | boost::mpl::int_<N3>, | 
|---|
| 197 | boost::mpl::int_<N4>, | 
|---|
| 198 | boost::mpl::int_<N5>, | 
|---|
| 199 | boost::mpl::int_<N6>, | 
|---|
| 200 | boost::mpl::int_<N7>>>> type; | 
|---|
| 201 | }; | 
|---|
| 202 |  | 
|---|
| 203 | //! Partial specialization for N=8 | 
|---|
| 204 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5, size_t N6, size_t N7, size_t N8> | 
|---|
| 205 | struct t_to_memory_c_impl<T[N1][N2][N3][N4][N5][N6][N7][N8]> | 
|---|
| 206 | { | 
|---|
| 207 | //! tranform a type T into a memory_c<multi_array<.......>> | 
|---|
| 208 | typedef memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int_<N1>, | 
|---|
| 209 | boost::mpl::int_<N2>, | 
|---|
| 210 | boost::mpl::int_<N3>, | 
|---|
| 211 | boost::mpl::int_<N4>, | 
|---|
| 212 | boost::mpl::int_<N5>, | 
|---|
| 213 | boost::mpl::int_<N6>, | 
|---|
| 214 | boost::mpl::int_<N7>, | 
|---|
| 215 | boost::mpl::int_<N8>>>> type; | 
|---|
| 216 | }; | 
|---|
| 217 |  | 
|---|
| 218 | //! Partial specialization for N=9 | 
|---|
| 219 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5, size_t N6, size_t N7, size_t N8, size_t N9> | 
|---|
| 220 | struct t_to_memory_c_impl<T[N1][N2][N3][N4][N5][N6][N7][N8][N9]> | 
|---|
| 221 | { | 
|---|
| 222 | //! tranform a type T into a memory_c<multi_array<.......>> | 
|---|
| 223 | typedef memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int_<N1>, | 
|---|
| 224 | boost::mpl::int_<N2>, | 
|---|
| 225 | boost::mpl::int_<N3>, | 
|---|
| 226 | boost::mpl::int_<N4>, | 
|---|
| 227 | boost::mpl::int_<N5>, | 
|---|
| 228 | boost::mpl::int_<N6>, | 
|---|
| 229 | boost::mpl::int_<N7>, | 
|---|
| 230 | boost::mpl::int_<N8>, | 
|---|
| 231 | boost::mpl::int_<N9>>>> type; | 
|---|
| 232 | }; | 
|---|
| 233 |  | 
|---|
| 234 | //! Partial specialization for N=10 | 
|---|
| 235 | template<typename T,size_t N1,size_t N2,size_t N3,size_t N4,size_t N5, size_t N6, size_t N7, size_t N8, size_t N9, size_t N10> | 
|---|
| 236 | struct t_to_memory_c_impl<T[N1][N2][N3][N4][N5][N6][N7][N8][N9][N10]> | 
|---|
| 237 | { | 
|---|
| 238 | //! tranform a type T into a memory_c<multi_array<.......>> | 
|---|
| 239 | typedef memory_c<multi_array<boost::mpl::vector<T,boost::mpl::int_<N1>, | 
|---|
| 240 | boost::mpl::int_<N2>, | 
|---|
| 241 | boost::mpl::int_<N3>, | 
|---|
| 242 | boost::mpl::int_<N4>, | 
|---|
| 243 | boost::mpl::int_<N5>, | 
|---|
| 244 | boost::mpl::int_<N6>, | 
|---|
| 245 | boost::mpl::int_<N7>, | 
|---|
| 246 | boost::mpl::int_<N8>, | 
|---|
| 247 | boost::mpl::int_<N9>, | 
|---|
| 248 | boost::mpl::int_<N10>>>> type; | 
|---|
| 249 | }; | 
|---|
| 250 |  | 
|---|
| 251 | /*! \brief Meta-function t_to_memory_c | 
|---|
| 252 | * | 
|---|
| 253 | * Meta-function t_to_memory_c, convert the type T into an appropriate memory_c type | 
|---|
| 254 | * | 
|---|
| 255 | * basically it convert t_to_memory_c<float> into memory_c<float> and array specification like | 
|---|
| 256 | * t_to_memory_c<float[3][3]> into memory_c<multi_array<float,3,3>>, and so on for higher dimensionality | 
|---|
| 257 | * | 
|---|
| 258 | */ | 
|---|
| 259 | template<typename T> | 
|---|
| 260 | struct t_to_memory_c | 
|---|
| 261 | { | 
|---|
| 262 | typedef typename t_to_memory_c_impl<typename remove_attributes_const_ref<T>::type>::type type; | 
|---|
| 263 | }; | 
|---|
| 264 |  | 
|---|
| 265 | /*! \brief Meta-function t_to_memory_c_red | 
|---|
| 266 | * | 
|---|
| 267 | * Meta-function t_to_memory_c, convert the type T into an appropriate memory_c<....,MEMORY_C_REDUCED> type | 
|---|
| 268 | * | 
|---|
| 269 | * basically it convert t_to_memory_c<float> into memory_c<float,MEMORY_C_REDUCED> and array specification like | 
|---|
| 270 | * t_to_memory_c<float[3][3]> into memory_c<multy_array<float,3,3>,MEMORY_C_REDUCED>, and so on for higher dimensionality | 
|---|
| 271 | * | 
|---|
| 272 | */ | 
|---|
| 273 | template<typename T> | 
|---|
| 274 | struct t_to_memory_c_red | 
|---|
| 275 | { | 
|---|
| 276 | typedef typename t_to_memory_c_red_impl<typename remove_attributes_const_ref<T>::type>::type type; | 
|---|
| 277 | }; | 
|---|
| 278 |  | 
|---|
| 279 | #endif /* T_TO_MEMORY_C_HPP_ */ | 
|---|
| 280 |  | 
|---|