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);
93 "Fixed-length, null-terminated need at least one byte to store the null-character.");
96 _hid = detail::h5t_copy(H5T_C_S1);
98 detail::h5t_set_size(
_hid, hsize_t(size));
99 detail::h5t_set_cset(
_hid, H5T_cset_t(character_set));
100 detail::h5t_set_strpad(
_hid, H5T_str_t(padding));
104 _hid = detail::h5t_copy(H5T_C_S1);
106 detail::h5t_set_size(
_hid, H5T_VARIABLE);
107 detail::h5t_set_cset(
_hid, H5T_cset_t(character_set));
113 _hid = detail::h5t_copy(H5T_NATIVE_CHAR);
118 _hid = detail::h5t_copy(H5T_NATIVE_SCHAR);
123 _hid = detail::h5t_copy(H5T_NATIVE_UCHAR);
129 _hid = detail::h5t_copy(H5T_NATIVE_SHORT);
134 _hid = detail::h5t_copy(H5T_NATIVE_USHORT);
140 _hid = detail::h5t_copy(H5T_NATIVE_INT);
145 _hid = detail::h5t_copy(H5T_NATIVE_UINT);
151 _hid = detail::h5t_copy(H5T_NATIVE_LONG);
156 _hid = detail::h5t_copy(H5T_NATIVE_ULONG);
162 _hid = detail::h5t_copy(H5T_NATIVE_LLONG);
167 _hid = detail::h5t_copy(H5T_NATIVE_ULLONG);
173 _hid = detail::h5t_copy(H5T_NATIVE_FLOAT);
178 _hid = detail::h5t_copy(H5T_NATIVE_DOUBLE);
183 _hid = detail::h5t_copy(H5T_NATIVE_LDOUBLE);
189 _hid = create_string(H5T_VARIABLE);
192#if HIGHFIVE_CXX_STD >= 17
196 _hid = detail::h5t_copy(H5T_NATIVE_B8);
202template <
size_t StrLen>
206 :
DataType(create_string(StrLen)) {}
209template <
size_t StrLen>
213 :
DataType(create_string(StrLen)) {}
222 sizeof(std::complex<T>))) {
223 static_assert(std::is_arithmetic<T>::value,
224 "std::complex accepts only floating point and integral numbers.");
230 return {{
"FALSE", details::Boolean::HighFiveFalse}, {
"TRUE", details::Boolean::HighFiveTrue}};
236 static_assert(details::inspector<T>::recursive_ndim == 0,
237 "Atomic types cant be arrays, except for char[] (fixed-length strings)");
238 static_assert(details::inspector<T>::recursive_ndim > 0,
"Type not supported");
242namespace deprecated {
243template <std::
size_t N>
245 datavec.resize(length);
246 std::memcpy(datavec[0].data(), array[0].data(), N * length);
249template <std::
size_t N>
251 const std::string* iter_end) {
252 datavec.reserve(
static_cast<std::size_t
>(iter_end - iter_begin));
253 for (std::string
const* it = iter_begin; it != iter_end; ++it) {
258template <std::
size_t N>
262template <std::
size_t N>
264 const std::initializer_list<std::string>& init_list)
267template <std::
size_t N>
269 datavec.emplace_back();
270 const size_t length = std::min(N - 1, src.length());
271 std::memcpy(datavec.back().data(), src.c_str(), length);
272 datavec.back()[length] = 0;
275template <std::
size_t N>
277 datavec.emplace_back();
278 std::copy(src.begin(), src.end(), datavec.back().data());
281template <std::
size_t N>
283 return std::string(datavec[i].data());
291 _hid = detail::h5t_copy(H5T_STD_REF_OBJ);
296 if (detail::h5t_get_class(hid) == H5T_COMPOUND) {
297 auto number_of_members = detail::h5t_get_nmembers(hid);
298 if (number_of_members == -1) {
300 std::to_string(hid));
302 if (number_of_members == 0) {
304 std::to_string(hid));
307 auto member_type = detail::h5t_get_member_type(hid, 0);
309 detail::h5t_close(member_type);
311 }
else if (detail::h5t_get_class(hid) == H5T_STRING) {
314 return detail::h5t_get_size(hid);
333#define _H5_STRUCT_PADDING(current_size, member_size) \
334 (((member_size) >= (current_size)) \
335 ? (((member_size) - (current_size)) % (member_size)) \
336 : ((((member_size) - (((current_size) - (member_size)) % (member_size)))) % \
339inline void CompoundType::create(
size_t size) {
341 size_t current_size = 0, max_atomic_size = 0;
344 for (
auto& member: members) {
345 size_t member_size = detail::h5t_get_size(member.base_type.getId());
347 if (member_size == 0) {
348 throw DataTypeException(
"Cannot get size of DataType with hid: " +
349 std::to_string(member.base_type.getId()));
360 current_size = member.offset + member_size;
364 max_atomic_size = std::max(max_atomic_size, first_atomic_size);
371 _hid = detail::h5t_create(H5T_COMPOUND, size);
374 for (
const auto& member: members) {
375 detail::h5t_insert(
_hid, member.name.c_str(), member.offset, member.base_type.getId());
379#undef _H5_STRUCT_PADDING
383 object.
getId(), name.c_str(),
getId(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
389 _hid = detail::h5t_enum_create(
AtomicType<
typename std::underlying_type<T>::type>{}.
getId());
392 for (
const auto& member: members) {
393 detail::h5t_enum_insert(_hid, member.name.c_str(), &(member.value));
400 object.getId(), name.c_str(), getId(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
405inline hid_t create_string(
size_t length) {
406 hid_t _hid = detail::h5t_copy(H5T_C_S1);
407 detail::h5t_set_size(_hid, length);
408 detail::h5t_set_cset(_hid, H5T_CSET_UTF8);
413inline DataTypeClass convert_type_class(
const H5T_class_t& tclass) {
502 if (
sizeof(T) != t.
getSize()) {
503 std::ostringstream ss;
504 ss <<
"Size of array type " <<
sizeof(T) <<
" != that of memory datatype " << t.
getSize()
524#ifdef H5_USE_HALF_FLOAT
#define HIGHFIVE_REGISTER_TYPE(type, function)
Macro to extend datatype of HighFive.
Definition H5DataType.hpp:490
#define _H5_STRUCT_PADDING(current_size, member_size)
Definition H5DataType_misc.hpp:333
AtomicType()
Definition H5DataType_misc.hpp:205
AtomicType()
Definition H5DataType_misc.hpp:212
AtomicType()
Definition H5DataType_misc.hpp:219
create an HDF5 DataType from a C++ type
Definition H5DataType.hpp:189
AtomicType()
Definition H5DataType_misc.hpp:235
Create a compound HDF5 datatype.
Definition H5DataType.hpp:200
void commit(const Object &object, const std::string &name) const
Commit datatype into the given Object.
Definition H5DataType_misc.hpp:381
Exception specific to HighFive DataType interface.
Definition H5Exception.hpp:94
HDF5 Data Type.
Definition H5DataType.hpp:61
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
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:76
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:298
void commit(const Object &object, const std::string &name) const
Commit datatype into the given Object.
Definition H5DataType_misc.hpp:398
FixedLengthStringType(size_t size, StringPadding padding, CharacterSet character_set=CharacterSet::Ascii)
Create a fixed length string datatype.
Definition H5DataType_misc.hpp:88
Definition H5Object.hpp:54
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:69
bool isValid() const noexcept
isValid
Definition H5Object_misc.hpp:65
hid_t _hid
Definition H5Object.hpp:105
Definition H5DataType.hpp:130
StringPadding getPadding() const
For fixed length stings return the padding.
Definition H5DataType_misc.hpp:80
CharacterSet getCharacterSet() const
For stings return the character set.
Definition H5DataType_misc.hpp:84
VariableLengthStringType(CharacterSet character_set=CharacterSet::Ascii)
Create a variable length string HDF5 datatype.
Definition H5DataType_misc.hpp:103
A structure representing a set of fixed-length strings.
Definition H5DataType.hpp:358
void push_back(const std::string &)
Append an std::string to the buffer structure.
Definition H5DataType_misc.hpp:268
std::string getString(std::size_t index) const
Retrieve a string from the structure as std::string.
Definition H5DataType_misc.hpp:282
FixedLenStringArray()=default
Definition H5_definitions.hpp:22
EnumType< details::Boolean > create_enum_boolean()
Definition H5DataType_misc.hpp:229
DataType create_and_check_datatype()
Create a DataType instance representing type T and perform a sanity check on its size.
Definition H5DataType_misc.hpp:486
DataType create_datatype()
Create a DataType instance representing type T.
Definition H5DataType_misc.hpp:479
CharacterSet
Definition H5DataType.hpp:125
DataType create_datatype< bool >()
Definition H5DataType_misc.hpp:518
size_t find_first_atomic_member_size(hid_t hid)
Definition H5DataType_misc.hpp:294
DataTypeClass
Enum of Fundamental data classes.
Definition H5DataType.hpp:31
StringPadding
Definition string_padding.hpp:7