6 #ifndef ECHELON_HDF5_TYPE_FACTORY_HPP 7 #define ECHELON_HDF5_TYPE_FACTORY_HPP 9 #include <echelon/hdf5/type.hpp> 10 #include <echelon/hdf5/type_traits.hpp> 11 #include <echelon/hdf5/precursor/object_reference.hpp> 12 #include <echelon/hdf5/customization_hooks.hpp> 13 #include <echelon/hdf5/static_type_layout.hpp> 23 inline typename std::enable_if<is_predefined_hdf5_type<T>::value, type>::type get_hdf5_type();
26 inline typename std::enable_if<is_hdf5_type<T>::value && !is_predefined_hdf5_type<T>::value,
31 inline typename std::enable_if<!is_hdf5_type<T>::value && !is_trivially_storable<T>(), type>::type
35 inline typename std::enable_if<!is_hdf5_type<T>::value && is_trivially_storable<T>(), type>::type
39 struct hdf5_type_selector
41 static_assert(
sizeof(T) !=
sizeof(T),
"invalid type");
45 struct hdf5_type_selector<char>
54 struct hdf5_type_selector<unsigned char>
63 struct hdf5_type_selector<short>
72 struct hdf5_type_selector<unsigned short>
81 struct hdf5_type_selector<int>
90 struct hdf5_type_selector<unsigned int>
99 struct hdf5_type_selector<long>
108 struct hdf5_type_selector<unsigned long>
117 struct hdf5_type_selector<long long>
126 struct hdf5_type_selector<unsigned long long>
135 struct hdf5_type_selector<float>
144 struct hdf5_type_selector<double>
153 struct hdf5_type_selector<bool>
162 struct hdf5_type_selector<std::string>
170 template <std::
size_t N>
171 struct hdf5_type_selector<char[N]>
180 struct hdf5_type_selector<precursor::object_reference>
188 template <
typename T>
189 struct hdf5_type_selector<T const> : hdf5_type_selector<typename std::remove_cv<T>::type>
196 template <
typename T, std::
size_t I,
typename Enable =
void>
197 struct add_member_to_layout;
199 template <
typename T, std::
size_t I>
200 struct add_member_to_layout<T, I,
201 typename std::enable_if<static_type_layout<T>::category ==
202 static_type_layout_category::generic>::type>
204 static std::size_t eval(type_layout& layout, std::size_t)
206 const id_offset_pair id_offset = static_type_layout<T>::members()[I];
208 typedef typename std::tuple_element<I, typename static_type_layout<T>::member_types>::type
211 layout.add_element(id_offset.id, get_hdf5_type<member_type>(), id_offset.offset);
213 return id_offset.offset;
217 template <
typename T, std::
size_t I>
218 struct add_member_to_layout<T, I,
219 typename std::enable_if<static_type_layout<T>::category ==
220 static_type_layout_category::packed>::type>
222 static std::size_t eval(type_layout& layout, std::size_t current_offset)
224 const id_size_pair id_size = static_type_layout<T>::members()[I];
226 typedef typename std::tuple_element<I, typename static_type_layout<T>::member_types>::type
229 layout.add_element(id_size.id, get_hdf5_type<member_type>(), current_offset);
231 return current_offset + id_size.size;
235 template <
typename T, std::
size_t I, std::
size_t N,
typename Enable =
void>
236 struct add_members_to_layout;
238 template <
typename T, std::
size_t I, std::
size_t N>
239 struct add_members_to_layout<T, I, N>
241 static void eval(type_layout& layout, std::size_t current_offset)
243 const std::size_t new_offset = add_member_to_layout<T, I>::eval(layout, current_offset);
245 add_members_to_layout<T, I + 1, N>::eval(layout, new_offset);
249 template <
typename T, std::
size_t N>
250 struct add_members_to_layout<T, N, N>
252 static void eval(type_layout&, std::size_t)
258 template <
typename T>
259 inline typename std::enable_if<is_predefined_hdf5_type<T>::value, type>::type get_hdf5_type()
261 return hdf5_type_selector<T>::get();
264 template <
typename T>
265 inline typename std::enable_if<is_hdf5_type<T>::value && !is_predefined_hdf5_type<T>::value,
269 typedef typename std::remove_reference<typename std::remove_cv<T>::type>::type value_type;
271 type_layout new_layout(static_type_layout<value_type>::size);
273 constexpr std::size_t num_members = static_type_layout<value_type>::num_members;
275 detail::add_members_to_layout<value_type, 0, num_members>::eval(new_layout, 0);
280 template <
typename T>
281 inline typename std::enable_if<!is_hdf5_type<T>::value && !is_trivially_storable<T>(), type>::type
285 typename std::decay<decltype(lower_type_internal(std::declval<T>(), {}))>::type;
287 return get_hdf5_type<lowered_type>();
290 template <
typename T>
291 inline typename std::enable_if<!is_hdf5_type<T>::value && is_trivially_storable<T>(), type>::type
294 static_assert(is_hdf5_type<T>::value,
"T must be a valid HDF5 type");
echelon's core namespace
Definition: attribute.cpp:10
static type short_()
Returns a handle to the primitive type 'short'.
Definition: hdf5/type.cpp:17
static type float_()
Returns a handle to the primitive type 'float'.
Definition: hdf5/type.cpp:62
static type object_reference()
Returns a handle to the primitive type 'object reference'.
Definition: hdf5/type.cpp:77
static type long_long()
Returns a handle to the primitive type 'long long'.
Definition: hdf5/type.cpp:32
static type uchar()
Returns a handle to the primitive type 'unsigned char'.
Definition: hdf5/type.cpp:37
static type string()
Returns a handle to the primitive type 'string'.
Definition: hdf5/type.cpp:72
static type double_()
Returns a handle to the primitive type 'double'.
Definition: hdf5/type.cpp:67
static type int_()
Returns a handle to the primitive type 'int'.
Definition: hdf5/type.cpp:22
static type ulong_long()
Returns a handle to the primitive type 'unsigned long long'.
Definition: hdf5/type.cpp:57
static type ushort()
Returns a handle to the primitive type 'unsigned short'.
Definition: hdf5/type.cpp:42
static type long_()
Returns a handle to the primitive type 'long'.
Definition: hdf5/type.cpp:27
static type uint()
Returns a handle to the primitive type 'unsigned int'.
Definition: hdf5/type.cpp:47
static type char_()
Returns a handle to the primitive type 'char'.
Definition: hdf5/type.cpp:12
static type ulong()
Returns a handle to the primitive type 'unsigned long'.
Definition: hdf5/type.cpp:52
static type compound_type(const type_layout &layout)
Creates a new compound type using a given layout.
Definition: hdf5/type.cpp:82