36 assert(data.getSpace().getSimpleExtentNdims() == 0);
37 assert(data.getDataType().getClass() == H5T_STRING);
39 auto dtype = data.getDataType();
40 if (!dtype.isVariableStr()) {
45 data.read(&vptr, dtype);
47 const auto& dspace = data.getSpace();
48 const auto& plist = H5::DSetMemXferPropList::DEFAULT;
52 throw std::runtime_error(
"detected a NULL pointer for a variable length string in '" +
get_name(data) +
"'");
67 assert(data.getSpace().getSimpleExtentNdims() == 1);
68 assert(data.getDataType().getClass() == H5T_STRING);
70 auto dtype = data.getDataType();
71 if (!dtype.isVariableStr()) {
75 hsize_t block_size = 10000;
76 const auto& plist = data.getCreatePlist();
77 if (plist.getLayout() == H5D_CHUNKED) {
78 plist.getChunk(1, &block_size);
81 H5::DataSpace mspace(1, &block_size), dspace(1, &full_length);
82 auto buffer = sanisizer::create<std::vector<char*> >(block_size);
84 for (hsize_t i = 0; i < full_length; i += block_size) {
85 const hsize_t available = sanisizer::min(full_length - i, block_size);
86 constexpr hsize_t zero = 0;
87 mspace.selectHyperslab(H5S_SELECT_SET, &available, &zero);
88 dspace.selectHyperslab(H5S_SELECT_SET, &available, &i);
90 data.read(buffer.data(), dtype, mspace, dspace);
92 const auto& plist = H5::DSetMemXferPropList::DEFAULT;
93 [[maybe_unused]]
ReclaimVlsMemory deletor(&dtype, &mspace, &plist, buffer.data());
94 for (hsize_t j = 0; j < available; ++j) {
95 if (buffer[j] == NULL) {
96 throw std::runtime_error(
"detected a NULL pointer for a variable length string in '" +
get_name(data) +
"'");
113 assert(data.getSpace().getSimpleExtentNdims() > 0);
114 assert(data.getDataType().getClass() == H5T_STRING);
116 auto stype = data.getDataType();
117 if (!stype.isVariableStr()) {
122 const auto ndims = dimensions.size();
123 assert(sanisizer::is_equal(ndims, data.getSpace().getSimpleExtentNdims()));
125 std::vector<hsize_t> chunk_dims;
126 const auto& plist = data.getCreatePlist();
127 if (plist.getLayout() == H5D_CHUNKED) {
128 chunk_dims.resize(ndims);
129 plist.getChunk(dimensions.size(), chunk_dims.data());
137 const auto ndim = dimensions.size();
138 H5::DataSpace fspace(ndim, dimensions.data());
140 auto buffer = sanisizer::create<std::vector<char*> >(mspace.getSimpleExtentNpoints());
143 const auto& curcount = iter.
counts();
144 mspace.setExtentSimple(ndim, curcount.data());
145 fspace.selectHyperslab(H5S_SELECT_SET, curcount.data(), iter.
starts().data());
147 data.read(buffer.data(), stype, mspace, fspace);
148 const auto& plist = H5::DSetMemXferPropList::DEFAULT;
149 [[maybe_unused]]
ReclaimVlsMemory deleter(&stype, &mspace, &plist, buffer.data());
151 const auto npts = mspace.getSimpleExtentNpoints();
152 for (I<
decltype(npts)> i = 0; i < npts; ++i) {
153 if (buffer[i] == NULL) {
154 throw std::runtime_error(
"detected NULL pointer in a variable-length string dataset");
170 assert(attr.getSpace().getSimpleExtentNdims() == 0);
171 assert(attr.getDataType().getClass() == H5T_STRING);
173 auto dtype = attr.getDataType();
174 if (!dtype.isVariableStr()) {
178 const auto& mspace = attr.getSpace();
179 const auto& plist = H5::DSetMemXferPropList::DEFAULT;
181 attr.read(dtype, &buffer);
182 [[maybe_unused]]
ReclaimVlsMemory deletor(&dtype, &mspace, &plist, &buffer);
183 if (buffer == NULL) {
184 throw std::runtime_error(
"detected a NULL pointer for a variable length string attribute");
199 assert(attr.getSpace().getSimpleExtentNdims() == 1);
200 assert(attr.getDataType().getClass() == H5T_STRING);
202 auto dtype = attr.getDataType();
203 if (!dtype.isVariableStr()) {
207 const auto& mspace = attr.getSpace();
208 const auto& plist = H5::DSetMemXferPropList::DEFAULT;
209 auto buffer = sanisizer::create<std::vector<char*> >(full_length);
210 attr.read(dtype, buffer.data());
211 [[maybe_unused]]
ReclaimVlsMemory deletor(&dtype, &mspace, &plist, buffer.data());
212 for (hsize_t i = 0; i < full_length; ++i) {
213 if (buffer[i] == NULL) {
214 throw std::runtime_error(
"detected a NULL pointer for a variable length string attribute");