| 1 | /* |
| 2 | * Pack_selector.hpp |
| 3 | * |
| 4 | * Created on: Jul 15, 2015 |
| 5 | * Author: Pietro Incardona |
| 6 | */ |
| 7 | |
| 8 | |
| 9 | #ifndef SRC_PACK_AAA_SELECTOR_HPP_ |
| 10 | #define SRC_PACK_AAA_SELECTOR_HPP_ |
| 11 | |
| 12 | #include <type_traits> |
| 13 | #include "util/common.hpp" |
| 14 | #include "memory_ly/Encap.hpp" |
| 15 | #include "Grid/util.hpp" |
| 16 | #include "Vector/util.hpp" |
| 17 | #include "Packer_Unpacker/has_pack_agg.hpp" |
| 18 | |
| 19 | //! Primitive packing |
| 20 | #define PACKER_PRIMITIVE 1 |
| 21 | //! Array of primitives packing |
| 22 | #define PACKER_ARRAY_PRIMITIVE 2 |
| 23 | //! Encapsulated Object packing |
| 24 | #define PACKER_ENCAP_OBJECTS 3 |
| 25 | //! Vector of objects packing |
| 26 | #define PACKER_GENERAL 4 |
| 27 | //! Grid packing |
| 28 | #define PACKER_GRID 5 |
| 29 | //! Packer cannot check for pointers |
| 30 | #define PACKER_OBJECTS_WITH_WARNING_POINTERS 6 |
| 31 | //! Packer error structure has pointers |
| 32 | #define PACKER_OBJECTS_WITH_POINTER_CHECK 7 |
| 33 | //! Compile time array packing |
| 34 | #define PACKER_ARRAY_CP_PRIMITIVE 8 |
| 35 | //! Packer in case of ENCAP with chunking |
| 36 | #define PACKER_ENCAP_OBJECTS_CHUNKING 9 |
| 37 | |
| 38 | #define IS_ENCAP 4 |
| 39 | #define IS_GRID 2 |
| 40 | #define HAS_PACKER 1 |
| 41 | |
| 42 | /*! \brief Pack selector for unknown type |
| 43 | * |
| 44 | * |
| 45 | */ |
| 46 | template <typename T, bool has_noPointers> |
| 47 | struct Pack_selector_unknown_type_impl |
| 48 | { |
| 49 | enum |
| 50 | { |
| 51 | value = PACKER_OBJECTS_WITH_POINTER_CHECK |
| 52 | }; |
| 53 | }; |
| 54 | |
| 55 | template <typename T> |
| 56 | struct Pack_selector_unknown_type_impl<T,false> |
| 57 | { |
| 58 | enum |
| 59 | { |
| 60 | value = PACKER_OBJECTS_WITH_WARNING_POINTERS |
| 61 | }; |
| 62 | }; |
| 63 | |
| 64 | /*! \brief Pack selector for unknown type |
| 65 | * |
| 66 | * |
| 67 | */ |
| 68 | template <typename T, int known_type> |
| 69 | struct Pack_selector_known_type_impl |
| 70 | { |
| 71 | enum |
| 72 | { |
| 73 | value = Pack_selector_unknown_type_impl<T, has_noPointers<T>::value >::value |
| 74 | }; |
| 75 | }; |
| 76 | |
| 77 | template <typename T> |
| 78 | struct Pack_selector_known_type_impl<T,IS_GRID> |
| 79 | { |
| 80 | enum |
| 81 | { |
| 82 | value = PACKER_GRID |
| 83 | }; |
| 84 | }; |
| 85 | |
| 86 | template <typename T> |
| 87 | struct Pack_selector_known_type_impl<T,HAS_PACKER> |
| 88 | { |
| 89 | enum |
| 90 | { |
| 91 | value = PACKER_GENERAL |
| 92 | }; |
| 93 | }; |
| 94 | |
| 95 | template <typename T> |
| 96 | struct Pack_selector_known_type_impl<T,IS_ENCAP> |
| 97 | { |
| 98 | enum |
| 99 | { |
| 100 | value = PACKER_ENCAP_OBJECTS |
| 101 | }; |
| 102 | }; |
| 103 | |
| 104 | /////////////////////// ---------- CHECKING FOR PRIMITIVES -------------- |
| 105 | /*! \brief it is not a fundamental type |
| 106 | * |
| 107 | */ |
| 108 | template<typename T, bool is_foundamental> |
| 109 | struct Pack_selector_impl |
| 110 | { |
| 111 | enum |
| 112 | { |
| 113 | value = Pack_selector_known_type_impl< T, 4*is_encap<T>::value + is_grid<T>::value * 2 + (has_pack_gen<T>::value)*(!is_grid<T>::value) >::value |
| 114 | }; |
| 115 | }; |
| 116 | |
| 117 | template<typename T, bool impl = std::is_array<T>::value> |
| 118 | struct Pack_selector_array_prim |
| 119 | { |
| 120 | enum |
| 121 | { |
| 122 | value = PACKER_PRIMITIVE |
| 123 | }; |
| 124 | }; |
| 125 | |
| 126 | template<typename T> |
| 127 | struct Pack_selector_array_prim<T,true> |
| 128 | { |
| 129 | enum |
| 130 | { |
| 131 | value = PACKER_ARRAY_CP_PRIMITIVE |
| 132 | }; |
| 133 | }; |
| 134 | |
| 135 | /*! \brief Select the primitive packing |
| 136 | * |
| 137 | */ |
| 138 | template<typename T> |
| 139 | struct Pack_selector_impl<T,true> |
| 140 | { |
| 141 | enum |
| 142 | { |
| 143 | value = Pack_selector_array_prim<T>::value |
| 144 | }; |
| 145 | }; |
| 146 | |
| 147 | ////////////////////////////////////////////////////////////////////////// |
| 148 | |
| 149 | /*! \brief Pack selector |
| 150 | * |
| 151 | * |
| 152 | */ |
| 153 | template <typename T> |
| 154 | struct Pack_selector |
| 155 | { |
| 156 | enum |
| 157 | { |
| 158 | value = Pack_selector_impl< T,std::is_fundamental<T>::value || std::is_fundamental< typename std::remove_all_extents<T>::type >::value >::value |
| 159 | }; |
| 160 | }; |
| 161 | |
| 162 | |
| 163 | #endif /* SRC_PACK_SELECTOR_HPP_ */ |
| 164 | |