19using unqualified_t =
typename std::remove_const<typename std::remove_reference<T>::type>::type;
23struct type_char_array {
28struct type_char_array<T*> {
29 using type =
typename std::conditional<std::is_same<unqualified_t<T>,
char>::value,
31 typename type_char_array<T>::type>::type;
34template <
typename T, std::
size_t N>
35struct type_char_array<T[N]> {
36 using type =
typename std::conditional<std::is_same<unqualified_t<T>,
char>::value,
38 typename type_char_array<T>::type>::type;
43 using type_no_const =
typename std::remove_const<T>::type;
44 using elem_type =
typename details::inspector<type_no_const>::base_type;
45 using char_array_t =
typename details::type_char_array<type_no_const>::type;
46 static constexpr bool is_char_array = !std::is_same<char_array_t, void>::value;
48 enum Operation { read, write };
52 BufferInfo(
const DataType& dtype, F getName, Operation _op);
55 const bool is_fixed_len_string;
56 const size_t n_dimensions;
57 const DataType data_type;
61template <
typename SrcStrT>
62struct string_type_checker {
63 static DataType getDataType(
const DataType&,
const DataType&);
67struct string_type_checker<void> {
68 inline static DataType getDataType(
const DataType& element_type,
const DataType& dtype) {
72 if (H5Tget_class(element_type.getId()) == H5T_STRING &&
73 H5Tget_cset(dtype.getId()) == H5T_CSET_ASCII) {
74 H5Tset_cset(element_type.getId(), H5T_CSET_ASCII);
80template <std::
size_t FixedLen>
81struct string_type_checker<char[FixedLen]> {
82 inline static DataType getDataType(
const DataType& element_type,
const DataType& dtype) {
83 DataType return_type = (dtype.isFixedLenStr()) ? AtomicType<
char[FixedLen]>()
86 if (H5Tget_cset(dtype.getId()) == H5T_CSET_ASCII) {
87 H5Tset_cset(return_type.getId(), H5T_CSET_ASCII);
94struct string_type_checker<char*> {
95 inline static DataType getDataType(
const DataType&,
const DataType& dtype) {
96 if (dtype.isFixedLenStr())
97 throw DataSetException(
"Can't output variable-length to fixed-length strings");
99 DataType return_type = AtomicType<std::string>();
100 if (H5Tget_cset(dtype.getId()) == H5T_CSET_ASCII) {
101 H5Tset_cset(return_type.getId(), H5T_CSET_ASCII);
109BufferInfo<T>::BufferInfo(
const DataType& dtype, F getName, Operation _op)
111 , is_fixed_len_string(dtype.isFixedLenStr())
113 , n_dimensions(details::inspector<type_no_const>::recursive_ndim -
114 ((is_fixed_len_string && is_char_array) ? 1 : 0))
116 string_type_checker<char_array_t>::getDataType(
create_datatype<elem_type>(), dtype)) {
117 if (is_fixed_len_string && std::is_same<elem_type, std::string>::value) {
118 throw DataSetException(
119 "Can't output std::string as fixed-length. "
120 "Use raw arrays or FixedLenStringArray");
123 if (dtype.getClass() != data_type.getClass()) {
124 HIGHFIVE_LOG_WARN(getName() +
"\": data and hdf5 dataset have different types: " +
125 data_type.string() +
" -> " + dtype.string());
126 }
else if ((dtype.getClass() & data_type.getClass()) == DataTypeClass::Float) {
128 (op == read) && (dtype.getSize() > data_type.getSize()),
129 getName() +
"\": hdf5 dataset has higher floating point precision than data on read: " +
130 dtype.string() +
" -> " + data_type.string());
133 (op == write) && (dtype.getSize() < data_type.getSize()),
135 "\": data has higher floating point precision than hdf5 dataset on write: " +
136 data_type.string() +
" -> " + dtype.string());
#define HIGHFIVE_LOG_WARN_IF(cond, message)
Definition H5Utility.hpp:190
#define HIGHFIVE_LOG_WARN(message)
Definition H5Utility.hpp:186
Definition H5_definitions.hpp:15
DataType create_datatype()
Create a DataType instance representing type T.
Definition H5DataType_misc.hpp:472
typename std::remove_const< typename std::remove_reference< T >::type >::type unqualified_t
Definition H5Converter_misc.hpp:123