20 using type_no_const =
typename std::remove_const<T>::type;
21 using elem_type =
typename details::inspector<type_no_const>::base_type;
22 using char_array_t =
typename details::type_char_array<type_no_const>::type;
23 static constexpr bool is_char_array = ! std::is_same<char_array_t, void>::value;
26 BufferInfo(
const DataType& dtype, F getName);
29 const bool is_fixed_len_string;
30 const size_t n_dimensions;
31 const DataType data_type;
35template <
typename SrcStrT>
36struct string_type_checker {
37 static DataType getDataType(
const DataType&,
const DataType&);
41struct string_type_checker<void> {
42inline static DataType getDataType(
const DataType& element_type,
const DataType& dtype) {
46 if (H5Tget_class(element_type.getId()) == H5T_STRING &&
47 H5Tget_cset(dtype.getId()) == H5T_CSET_ASCII) {
48 H5Tset_cset(element_type.getId(), H5T_CSET_ASCII);
53template <std::
size_t FixedLen>
54struct string_type_checker<char[FixedLen]> {
55inline static DataType getDataType(
const DataType& element_type,
const DataType& dtype) {
56 DataType return_type = (dtype.isFixedLenStr()) ? AtomicType<
char[FixedLen]>() : element_type;
58 if (H5Tget_cset(dtype.getId()) == H5T_CSET_ASCII) {
59 H5Tset_cset(return_type.getId(), H5T_CSET_ASCII);
65struct string_type_checker<char*> {
66inline static DataType getDataType(
const DataType&,
const DataType& dtype) {
67 if (dtype.isFixedLenStr())
68 throw DataSetException(
"Can't output variable-length to fixed-length strings");
70 DataType return_type = AtomicType<std::string>();
71 if (H5Tget_cset(dtype.getId()) == H5T_CSET_ASCII) {
72 H5Tset_cset(return_type.getId(), H5T_CSET_ASCII);
79BufferInfo<T>::BufferInfo(
const DataType& dtype, F getName)
80 : is_fixed_len_string(dtype.isFixedLenStr())
82 , n_dimensions(details::inspector<type_no_const>::recursive_ndim -
83 ((is_fixed_len_string && is_char_array) ? 1 : 0))
84 , data_type(string_type_checker<char_array_t>::getDataType(
86 if (is_fixed_len_string && std::is_same<elem_type, std::string>::value) {
87 throw DataSetException(
"Can't output std::string as fixed-length. "
88 "Use raw arrays or FixedLenStringArray");
91 if (dtype.getClass() != data_type.getClass()) {
92 std::cerr <<
"HighFive WARNING \""
94 <<
"\": data and hdf5 dataset have different types: "
95 << data_type.string() <<
" -> " << dtype.string() << std::endl;
Definition H5_definitions.hpp:15
DataType create_datatype()
Create a DataType instance representing type T.
Definition H5DataType_misc.hpp:427