| 1 | /* |
| 2 | * is_vtk_writable.hpp |
| 3 | * |
| 4 | * Created on: Jul 18, 2016 |
| 5 | * Author: i-bird |
| 6 | */ |
| 7 | |
| 8 | #ifndef OPENFPM_IO_SRC_VTKWRITER_IS_VTK_WRITABLE_HPP_ |
| 9 | #define OPENFPM_IO_SRC_VTKWRITER_IS_VTK_WRITABLE_HPP_ |
| 10 | |
| 11 | //! the vtk type |
| 12 | template<typename T, bool is_w> |
| 13 | struct vtk_type |
| 14 | { |
| 15 | //! get the vtk type for the property |
| 16 | typedef decltype(std::declval<T>().get_vtk(0)) type; |
| 17 | }; |
| 18 | |
| 19 | //! the vtk type |
| 20 | template<typename T> |
| 21 | struct vtk_type<T,false> |
| 22 | { |
| 23 | //! non writable vtk property (so void) |
| 24 | typedef void type; |
| 25 | }; |
| 26 | |
| 27 | /*! \brief it check if the type is vtk writable |
| 28 | * |
| 29 | * |
| 30 | */ |
| 31 | template<typename ObjType, typename Sfinae = void> |
| 32 | struct is_custom_vtk_writable: std::false_type {}; |
| 33 | |
| 34 | /*! \brief it check if the type is vtk writable |
| 35 | * |
| 36 | * \tparam ObjType check the type |
| 37 | * |
| 38 | */ |
| 39 | template<typename ObjType> |
| 40 | struct is_custom_vtk_writable <ObjType, typename Void< typename ObjType::is_vtk_writable >::type> : std::true_type |
| 41 | {}; |
| 42 | |
| 43 | /*! \brief it check if the type is vtk writable |
| 44 | * |
| 45 | * |
| 46 | */ |
| 47 | template<typename ObjType, typename Sfinae = void> |
| 48 | struct is_vtk_vector_dims: std::false_type {}; |
| 49 | |
| 50 | //! If it has not dims property defined the object is considered scalar |
| 51 | template<typename ObjType, bool has_dims = is_vtk_vector_dims<ObjType>::value > |
| 52 | struct vtk_dims |
| 53 | { |
| 54 | //! dimensionality of the vtk property (scalar) |
| 55 | enum |
| 56 | { |
| 57 | value = 1 |
| 58 | }; |
| 59 | }; |
| 60 | |
| 61 | //! return the dimansionality of the object |
| 62 | template<typename ObjType > |
| 63 | struct vtk_dims<ObjType,true> |
| 64 | { |
| 65 | //! dimansionality of the vtk proverty (vector) in case of an object point |
| 66 | //! or an object that define dimansionality |
| 67 | enum |
| 68 | { |
| 69 | value = ObjType::dims |
| 70 | }; |
| 71 | }; |
| 72 | |
| 73 | /*! \brief it check if the type is vtk writable |
| 74 | * |
| 75 | * \tparam ObjType check the type |
| 76 | * |
| 77 | */ |
| 78 | template<typename ObjType> |
| 79 | struct is_vtk_vector_dims<ObjType, typename Void< decltype(ObjType::dims) >::type> : std::true_type |
| 80 | {}; |
| 81 | |
| 82 | //! check for T to be writable |
| 83 | template<typename T> |
| 84 | struct is_vtk_writable |
| 85 | { |
| 86 | typedef T base; |
| 87 | |
| 88 | //! It check if the object is vtk compatible |
| 89 | enum |
| 90 | { |
| 91 | value = is_custom_vtk_writable<T>::value |
| 92 | }; |
| 93 | }; |
| 94 | |
| 95 | //! check float |
| 96 | template<> |
| 97 | struct is_vtk_writable<float> |
| 98 | { |
| 99 | typedef float base; |
| 100 | |
| 101 | //! float is vtk writable |
| 102 | enum |
| 103 | { |
| 104 | value = true |
| 105 | }; |
| 106 | }; |
| 107 | |
| 108 | //! check double |
| 109 | template<> |
| 110 | struct is_vtk_writable<double> |
| 111 | { |
| 112 | typedef double base; |
| 113 | |
| 114 | //! double is vtk writable |
| 115 | enum |
| 116 | { |
| 117 | value = true |
| 118 | }; |
| 119 | }; |
| 120 | |
| 121 | //! check char |
| 122 | template<> |
| 123 | struct is_vtk_writable<char> |
| 124 | { |
| 125 | typedef char base; |
| 126 | |
| 127 | //! char is vtk writable |
| 128 | enum |
| 129 | { |
| 130 | value = true |
| 131 | }; |
| 132 | }; |
| 133 | |
| 134 | //! check unsigned char |
| 135 | template<> |
| 136 | struct is_vtk_writable<unsigned char> |
| 137 | { |
| 138 | typedef unsigned char base; |
| 139 | |
| 140 | //! unsigned char is vtk writable |
| 141 | enum |
| 142 | { |
| 143 | value = true |
| 144 | }; |
| 145 | }; |
| 146 | |
| 147 | //! check short |
| 148 | template<> |
| 149 | struct is_vtk_writable<short> |
| 150 | { |
| 151 | typedef short base; |
| 152 | |
| 153 | //! short is vtk writable |
| 154 | enum |
| 155 | { |
| 156 | value = true |
| 157 | }; |
| 158 | }; |
| 159 | |
| 160 | //! check unsigned short |
| 161 | template<> |
| 162 | struct is_vtk_writable<unsigned short> |
| 163 | { |
| 164 | typedef unsigned short base; |
| 165 | |
| 166 | //! unsigned short is vtk writable |
| 167 | enum |
| 168 | { |
| 169 | value = true |
| 170 | }; |
| 171 | }; |
| 172 | |
| 173 | //! check int |
| 174 | template<> |
| 175 | struct is_vtk_writable<int> |
| 176 | { |
| 177 | typedef int base; |
| 178 | |
| 179 | //! int is vtk writable |
| 180 | enum |
| 181 | { |
| 182 | value = true |
| 183 | }; |
| 184 | }; |
| 185 | |
| 186 | //! check unsigned int |
| 187 | template<> |
| 188 | struct is_vtk_writable<unsigned int> |
| 189 | { |
| 190 | typedef unsigned int base; |
| 191 | |
| 192 | //! unsigned int is vtk writable |
| 193 | enum |
| 194 | { |
| 195 | value = true |
| 196 | }; |
| 197 | }; |
| 198 | |
| 199 | //! check long int |
| 200 | template<> |
| 201 | struct is_vtk_writable<long int> |
| 202 | { |
| 203 | typedef int base; |
| 204 | |
| 205 | //! long int is vtk writable |
| 206 | enum |
| 207 | { |
| 208 | value = true |
| 209 | }; |
| 210 | }; |
| 211 | |
| 212 | //! check unsigned long int |
| 213 | template<> |
| 214 | struct is_vtk_writable<unsigned long int> |
| 215 | { |
| 216 | typedef unsigned int base; |
| 217 | |
| 218 | //! unsigned long int is vtk writable |
| 219 | enum |
| 220 | { |
| 221 | value = true |
| 222 | }; |
| 223 | }; |
| 224 | |
| 225 | //! check bool |
| 226 | template<> |
| 227 | struct is_vtk_writable<bool> |
| 228 | { |
| 229 | typedef bool base; |
| 230 | |
| 231 | //! bool is vtk writable |
| 232 | enum |
| 233 | { |
| 234 | value = true |
| 235 | }; |
| 236 | }; |
| 237 | |
| 238 | #endif /* OPENFPM_IO_SRC_VTKWRITER_IS_VTK_WRITABLE_HPP_ */ |
| 239 | |