14#if HIGHFIVE_CXX_STD >= 17
27inline DataTypeClass convert_type_class(
const H5T_class_t& tclass);
29inline hid_t create_string(std::size_t length);
33 return _hid == H5I_INVALID_HID;
37 return convert_type_class(detail::h5t_get_class(
_hid));
41 return detail::h5t_get_size(
_hid);
45 return detail::h5t_equal(
_hid, other.
_hid) > 0;
49 return !(*
this == other);
53 return detail::h5t_is_variable_str(
_hid) > 0;
61 return detail::h5t_equal(
_hid, H5T_STD_REF_OBJ) > 0;
70 detail::h5i_inc_ref(
_hid);
82 detail::h5i_inc_ref(
_hid);
105 "Fixed-length, null-terminated need at least one byte to store the null-character.");
108 _hid = detail::h5t_copy(H5T_C_S1);
110 detail::h5t_set_size(
_hid, hsize_t(size));
111 detail::h5t_set_cset(
_hid, H5T_cset_t(character_set));
112 detail::h5t_set_strpad(
_hid, H5T_str_t(padding));
116 _hid = detail::h5t_copy(H5T_C_S1);
118 detail::h5t_set_size(
_hid, H5T_VARIABLE);
119 detail::h5t_set_cset(
_hid, H5T_cset_t(character_set));
125 _hid = detail::h5t_copy(H5T_NATIVE_CHAR);
130 _hid = detail::h5t_copy(H5T_NATIVE_SCHAR);
135 _hid = detail::h5t_copy(H5T_NATIVE_UCHAR);
141 _hid = detail::h5t_copy(H5T_NATIVE_SHORT);
146 _hid = detail::h5t_copy(H5T_NATIVE_USHORT);
152 _hid = detail::h5t_copy(H5T_NATIVE_INT);
157 _hid = detail::h5t_copy(H5T_NATIVE_UINT);
163 _hid = detail::h5t_copy(H5T_NATIVE_LONG);
168 _hid = detail::h5t_copy(H5T_NATIVE_ULONG);
174 _hid = detail::h5t_copy(H5T_NATIVE_LLONG);
179 _hid = detail::h5t_copy(H5T_NATIVE_ULLONG);
185 _hid = detail::h5t_copy(H5T_NATIVE_FLOAT);
190 _hid = detail::h5t_copy(H5T_NATIVE_DOUBLE);
195 _hid = detail::h5t_copy(H5T_NATIVE_LDOUBLE);
201 _hid = create_string(H5T_VARIABLE);
204#if HIGHFIVE_CXX_STD >= 17
208 _hid = detail::h5t_copy(H5T_NATIVE_B8);
214template <
size_t StrLen>
218 :
DataType(create_string(StrLen)) {}
226 CompoundType({{
"r", create_datatype<T>(), 0}, {
"i", create_datatype<T>(),
sizeof(T)}},
227 sizeof(std::complex<T>))) {
228 static_assert(std::is_arithmetic<T>::value,
229 "std::complex accepts only floating point and integral numbers.");
235 return {{
"FALSE", details::Boolean::HighFiveFalse}, {
"TRUE", details::Boolean::HighFiveTrue}};
243 "Missing specialization of AtomicType<T>. Therefore, type T is not supported by HighFive.");
251 _hid = detail::h5t_copy(H5T_STD_REF_OBJ);
256 if (detail::h5t_get_class(hid) == H5T_COMPOUND) {
257 auto number_of_members = detail::h5t_get_nmembers(hid);
258 if (number_of_members == -1) {
260 std::to_string(hid));
262 if (number_of_members == 0) {
264 std::to_string(hid));
267 auto member_type = detail::h5t_get_member_type(hid, 0);
269 detail::h5t_close(member_type);
271 }
else if (detail::h5t_get_class(hid) == H5T_STRING) {
274 return detail::h5t_get_size(hid);
294inline size_t struct_padding(
size_t current_size,
size_t member_size) {
295 if (member_size == 0) {
296 throw DataTypeException(
"Unexpected `member_size == 0`.");
299 return member_size >= current_size
300 ? (member_size - current_size) % member_size
301 : ((member_size - ((current_size - member_size) % member_size))) % member_size;
305inline void CompoundType::create(
size_t size) {
307 size_t current_size = 0, max_atomic_size = 0;
310 for (
auto& member: members) {
311 size_t member_size = detail::h5t_get_size(member.base_type.getId());
313 if (member_size == 0) {
314 throw DataTypeException(
"Cannot get size of DataType with hid: " +
315 std::to_string(member.base_type.getId()));
323 member.offset = current_size + detail::struct_padding(current_size, first_atomic_size);
326 current_size = member.offset + member_size;
330 max_atomic_size = std::max(max_atomic_size, first_atomic_size);
333 size = current_size + detail::struct_padding(current_size, max_atomic_size);
337 _hid = detail::h5t_create(H5T_COMPOUND, size);
340 for (
const auto& member: members) {
341 detail::h5t_insert(
_hid, member.name.c_str(), member.offset, member.base_type.getId());
347 object.
getId(), name.c_str(),
getId(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
353 _hid = detail::h5t_enum_create(
AtomicType<
typename std::underlying_type<T>::type>{}.
getId());
356 for (
const auto& member: members) {
357 detail::h5t_enum_insert(_hid, member.name.c_str(), &(member.value));
364 object.getId(), name.c_str(), getId(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
369inline hid_t create_string(
size_t length) {
370 hid_t _hid = detail::h5t_copy(H5T_C_S1);
371 detail::h5t_set_size(_hid, length);
372 detail::h5t_set_cset(_hid, H5T_CSET_UTF8);
377inline DataTypeClass convert_type_class(
const H5T_class_t& tclass) {
466 if (
sizeof(T) != t.
getSize()) {
467 std::ostringstream ss;
468 ss <<
"Size of array type " <<
sizeof(T) <<
" != that of memory datatype " << t.
getSize()
483 return create_datatype<HighFive::details::Boolean>();
#define HIGHFIVE_REGISTER_TYPE(type, function)
Macro to extend datatype of HighFive.
Definition H5DataType.hpp:383
AtomicType()
Definition H5DataType_misc.hpp:217
AtomicType()
Definition H5DataType_misc.hpp:224
create an HDF5 DataType from a C++ type
Definition H5DataType.hpp:211
AtomicType()
Definition H5DataType_misc.hpp:240
Create a compound HDF5 datatype.
Definition H5DataType.hpp:222
void commit(const Object &object, const std::string &name) const
Commit datatype into the given Object.
Definition H5DataType_misc.hpp:345
Exception specific to HighFive DataType interface.
Definition H5Exception.hpp:97
HDF5 Data Type.
Definition H5DataType.hpp:62
bool operator==(const DataType &other) const
Definition H5DataType_misc.hpp:44
bool isFixedLenStr() const
Returns whether the type is a fixed-length string.
Definition H5DataType_misc.hpp:56
size_t getSize() const
Returns the length (in bytes) of this type elements.
Definition H5DataType_misc.hpp:40
IntegerType asIntegerType() const
Returns this datatype as a IntegerType.
Definition H5DataType_misc.hpp:76
bool isVariableStr() const
Returns whether the type is a variable-length string.
Definition H5DataType_misc.hpp:52
bool empty() const noexcept
Check the DataType was default constructed.
Definition H5DataType_misc.hpp:32
std::string string() const
Returns a friendly description of the type (e.g. Float32)
Definition H5DataType_misc.hpp:88
DataTypeClass getClass() const
Return the fundamental type.
Definition H5DataType_misc.hpp:36
bool isReference() const
Returns whether the type is a Reference.
Definition H5DataType_misc.hpp:60
StringType asStringType() const
Returns this datatype as a StringType.
Definition H5DataType_misc.hpp:64
bool operator!=(const DataType &other) const
Definition H5DataType_misc.hpp:48
Create a enum HDF5 datatype.
Definition H5DataType.hpp:318
void commit(const Object &object, const std::string &name) const
Commit datatype into the given Object.
Definition H5DataType_misc.hpp:362
FixedLengthStringType(size_t size, StringPadding padding, CharacterSet character_set=CharacterSet::Ascii)
Create a fixed length string datatype.
Definition H5DataType_misc.hpp:100
An Integer datatype (i.e. H5T_INTEGER).
Definition H5DataType.hpp:194
Definition H5Object.hpp:36
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:75
bool isValid() const noexcept
isValid
Definition H5Object_misc.hpp:71
hid_t _hid
Definition H5Object.hpp:98
Definition H5DataType.hpp:136
StringPadding getPadding() const
For fixed length stings return the padding.
Definition H5DataType_misc.hpp:92
CharacterSet getCharacterSet() const
For stings return the character set.
Definition H5DataType_misc.hpp:96
VariableLengthStringType(CharacterSet character_set=CharacterSet::Ascii)
Create a variable length string HDF5 datatype.
Definition H5DataType_misc.hpp:115
Definition assert_compatible_spaces.hpp:15
EnumType< details::Boolean > create_enum_boolean()
Definition H5DataType_misc.hpp:234
DataType create_and_check_datatype()
Create a DataType instance representing type T and perform a sanity check on its size.
Definition H5DataType_misc.hpp:450
DataType create_datatype()
Create a DataType instance representing type T.
Definition H5DataType_misc.hpp:443
CharacterSet
Definition H5DataType.hpp:131
DataType create_datatype< bool >()
Definition H5DataType_misc.hpp:482
size_t find_first_atomic_member_size(hid_t hid)
Definition H5DataType_misc.hpp:254
DataTypeClass
Enum of Fundamental data classes.
Definition H5DataType.hpp:31
StringPadding
Definition string_padding.hpp:7