14#if HIGHFIVE_CXX_STD >= 17
21#ifdef H5_USE_HALF_FLOAT
30inline DataTypeClass convert_type_class(
const H5T_class_t& tclass);
32inline hid_t create_string(std::size_t length);
36 return _hid == H5I_INVALID_HID;
40 return convert_type_class(H5Tget_class(
_hid));
44 return H5Tget_size(
_hid);
48 return (H5Tequal(
_hid, other.
_hid) > 0);
52 return !(*
this == other);
56 auto var_value = H5Tis_variable_str(
_hid);
60 return static_cast<bool>(var_value);
68 return H5Tequal(
_hid, H5T_STD_REF_OBJ) > 0;
78 _hid = H5Tcopy(H5T_NATIVE_CHAR);
83 _hid = H5Tcopy(H5T_NATIVE_SCHAR);
88 _hid = H5Tcopy(H5T_NATIVE_UCHAR);
94 _hid = H5Tcopy(H5T_NATIVE_SHORT);
99 _hid = H5Tcopy(H5T_NATIVE_USHORT);
105 _hid = H5Tcopy(H5T_NATIVE_INT);
110 _hid = H5Tcopy(H5T_NATIVE_UINT);
116 _hid = H5Tcopy(H5T_NATIVE_LONG);
121 _hid = H5Tcopy(H5T_NATIVE_ULONG);
127 _hid = H5Tcopy(H5T_NATIVE_LLONG);
132 _hid = H5Tcopy(H5T_NATIVE_ULLONG);
136#ifdef H5_USE_HALF_FLOAT
141 _hid = H5Tcopy(H5T_NATIVE_FLOAT);
143 H5Tset_fields(_hid, 15, 10, 5, 0, 10);
145 H5Tset_size(_hid, 2);
147 H5Tset_ebias(_hid, 15);
153 _hid = H5Tcopy(H5T_NATIVE_FLOAT);
158 _hid = H5Tcopy(H5T_NATIVE_DOUBLE);
163 _hid = H5Tcopy(H5T_NATIVE_LDOUBLE);
169 _hid = create_string(H5T_VARIABLE);
172#if HIGHFIVE_CXX_STD >= 17
176 _hid = H5Tcopy(H5T_NATIVE_B8);
182template <
size_t StrLen>
186 :
DataType(create_string(StrLen)) {}
189template <
size_t StrLen>
193 :
DataType(create_string(StrLen)) {}
201 CompoundType({{
"r", create_datatype<T>(), 0}, {
"i", create_datatype<T>(),
sizeof(T)}},
202 sizeof(std::complex<T>))) {
203 static_assert(std::is_floating_point<T>::value,
204 "std::complex accepts only floating point numbers.");
210 return {{
"FALSE", details::Boolean::HighFiveFalse}, {
"TRUE", details::Boolean::HighFiveTrue}};
216 static_assert(details::inspector<T>::recursive_ndim == 0,
217 "Atomic types cant be arrays, except for char[] (fixed-length strings)");
218 static_assert(details::inspector<T>::recursive_ndim > 0,
"Type not supported");
224template <std::
size_t N>
226 datavec.resize(length);
227 std::memcpy(datavec[0].data(), array[0].data(), N * length);
230template <std::
size_t N>
232 const std::string* iter_end) {
233 datavec.resize(
static_cast<std::size_t
>(iter_end - iter_begin));
234 for (
auto& dst_array: datavec) {
235 const char* src = (iter_begin++)->c_str();
236 const size_t length = std::min(N - 1, std::strlen(src));
237 std::memcpy(dst_array.data(), src, length);
238 dst_array[length] = 0;
242template <std::
size_t N>
246template <std::
size_t N>
248 const std::initializer_list<std::string>& init_list)
251template <std::
size_t N>
253 datavec.emplace_back();
254 const size_t length = std::min(N - 1, src.length());
255 std::memcpy(datavec.back().data(), src.c_str(), length);
256 datavec.back()[length] = 0;
259template <std::
size_t N>
261 datavec.emplace_back();
262 std::copy(src.begin(), src.end(), datavec.back().data());
265template <std::
size_t N>
267 return std::string(datavec[i].data());
274 _hid = H5Tcopy(H5T_STD_REF_OBJ);
279 if (H5Tget_class(hid) == H5T_COMPOUND) {
280 auto number_of_members = H5Tget_nmembers(hid);
281 if (number_of_members == -1) {
283 std::to_string(hid));
285 if (number_of_members == 0) {
287 std::to_string(hid));
290 auto member_type = H5Tget_member_type(hid, 0);
292 H5Tclose(member_type);
294 }
else if (H5Tget_class(hid) == H5T_STRING) {
297 return H5Tget_size(hid);
316#define _H5_STRUCT_PADDING(current_size, member_size) \
317 (((member_size) >= (current_size)) \
318 ? (((member_size) - (current_size)) % (member_size)) \
319 : ((((member_size) - (((current_size) - (member_size)) % (member_size)))) % \
322inline void CompoundType::create(
size_t size) {
324 size_t current_size = 0, max_atomic_size = 0;
327 for (
auto& member: members) {
328 size_t member_size = H5Tget_size(member.base_type.getId());
330 if (member_size == 0) {
331 throw DataTypeException(
"Cannot get size of DataType with hid: " +
332 std::to_string(member.base_type.getId()));
343 current_size = member.offset + member_size;
347 max_atomic_size = std::max(max_atomic_size, first_atomic_size);
354 if ((
_hid = H5Tcreate(H5T_COMPOUND, size)) < 0) {
359 for (
const auto& member: members) {
360 if (H5Tinsert(
_hid, member.name.c_str(), member.offset, member.base_type.getId()) < 0) {
366#undef _H5_STRUCT_PADDING
369 H5Tcommit2(
object.
getId(), name.c_str(),
getId(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
375 if ((_hid = H5Tenum_create(
AtomicType<
typename std::underlying_type<T>::type>{}.
getId())) < 0) {
380 for (
const auto& member: members) {
381 if (H5Tenum_insert(_hid, member.name.c_str(), &(member.value)) < 0) {
383 "Could not add new member to this enum datatype");
390 H5Tcommit2(
object.getId(), name.c_str(), getId(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
395inline hid_t create_string(
size_t length) {
396 hid_t _hid = H5Tcopy(H5T_C_S1);
397 if (H5Tset_size(_hid, length) < 0) {
401 H5Tset_cset(_hid, H5T_CSET_UTF8);
406inline DataTypeClass convert_type_class(
const H5T_class_t& tclass) {
495 if (
sizeof(T) != t.
getSize()) {
496 std::ostringstream ss;
497 ss <<
"Size of array type " <<
sizeof(T) <<
" != that of memory datatype " << t.
getSize()
#define HIGHFIVE_REGISTER_TYPE(type, function)
Macro to extend datatype of HighFive.
Definition H5DataType.hpp:406
#define _H5_STRUCT_PADDING(current_size, member_size)
Definition H5DataType_misc.hpp:316
AtomicType()
Definition H5DataType_misc.hpp:192
AtomicType()
Definition H5DataType_misc.hpp:185
AtomicType()
Definition H5DataType_misc.hpp:199
create an HDF5 DataType from a C++ type
Definition H5DataType.hpp:117
AtomicType()
Definition H5DataType_misc.hpp:215
Create a compound HDF5 datatype.
Definition H5DataType.hpp:128
void commit(const Object &object, const std::string &name) const
Commit datatype into the given Object.
Definition H5DataType_misc.hpp:368
Exception specific to HighFive DataType interface.
Definition H5Exception.hpp:94
HDF5 Data Type.
Definition H5DataType.hpp:54
bool operator==(const DataType &other) const
Definition H5DataType_misc.hpp:47
bool isFixedLenStr() const
Returns whether the type is a fixed-length string.
Definition H5DataType_misc.hpp:63
size_t getSize() const
Returns the length (in bytes) of this type elements.
Definition H5DataType_misc.hpp:43
bool isVariableStr() const
Returns whether the type is a variable-length string.
Definition H5DataType_misc.hpp:55
bool empty() const noexcept
Check the DataType was default constructed. Such value might represent auto-detection of the datatype...
Definition H5DataType_misc.hpp:35
std::string string() const
Returns a friendly description of the type (e.g. Float32)
Definition H5DataType_misc.hpp:71
DataTypeClass getClass() const
Return the fundamental type.
Definition H5DataType_misc.hpp:39
bool isReference() const
Returns whether the type is a Reference.
Definition H5DataType_misc.hpp:67
bool operator!=(const DataType &other) const
Definition H5DataType_misc.hpp:51
Create a enum HDF5 datatype.
Definition H5DataType.hpp:228
void commit(const Object &object, const std::string &name) const
Commit datatype into the given Object.
Definition H5DataType_misc.hpp:389
A structure representing a set of fixed-length strings.
Definition H5DataType.hpp:284
std::string getString(std::size_t index) const
Retrieve a string from the structure as std::string.
Definition H5DataType_misc.hpp:266
FixedLenStringArray()=default
void push_back(const std::string &)
Append an std::string to the buffer structure.
Definition H5DataType_misc.hpp:252
Definition H5Object.hpp:54
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:65
hid_t _hid
Definition H5Object.hpp:105
Definition H5_definitions.hpp:15
half_float::half float16_t
Definition H5DataType_misc.hpp:137
EnumType< details::Boolean > create_enum_boolean()
Definition H5DataType_misc.hpp:209
DataType create_and_check_datatype()
Create a DataType instance representing type T and perform a sanity check on its size.
Definition H5DataType_misc.hpp:479
DataType create_datatype()
Create a DataType instance representing type T.
Definition H5DataType_misc.hpp:472
size_t find_first_atomic_member_size(hid_t hid)
Definition H5DataType_misc.hpp:277
DataTypeClass
Enum of Fundamental data classes.
Definition H5DataType.hpp:25
static void ToException(const std::string &prefix_msg)
Definition H5Exception_misc.hpp:42