Template return-type functions for reading data?
Could we have instead of:
uint32_t v = 0;
attr.read(v);
this:
auto v = attr.read<uint32_t>();
Just an idea
Here is another example of boilerplate that could potentially be a one-liner
auto ds_event_time_zero
= hdf5::node::get_dataset(root_group, group_path + "/event_time_zero");
vector<uint64_t> event_time_zero(ds_event_time_zero.dataspace().size());
ds_event_time_zero.read(event_time_zero);
Yes, it's not as efficient as allocating everything at the beginning of the universe, but reality dictates many such situations as, for example, the above being from some unit tests that validate small datasets.
We definitely should have something like this and it is already planned. What we have to do for that purpose is to refacture the type trait framework we currently use for IO. What we would need in particular is a type trait that tells the library how to create an instance of a particular type. Something like this
template<typename T> class FactoryTrait
{
public:
static T create(const hdf5::dataspace::Dataspace &space,
const hdf5::datatype::Datatype &type);
}
With this in our arsenal it would be rather straight forward to do things like the above.
I have a very rough design in mind which would do the job. But it still requires some rethinking. I hope I can put a draft online for discussion this week.
I have attempted to do something like
template<typename T>
T read() const
{
T ret;
read(ret);
return ret;
}
but this only works for scalar values, not vectors, as it needs to resize them before writing. Any idea how to do this so it would work for both? Would this FactoryTrait really help?
As for the discusion with Jan on #379 the first step to make this happen is to add the following static member to the dataspace trait
namespace hdf5 {
namespace dataspace {
template<typename T> class TypeTrait<T>
public:
// create a new instance of T according to dataspace
static T allocate(const Dataspace &dataspace)
{
}
};
}
}
There is a fairly stale branch for this issue: https://github.com/ess-dmsc/h5cpp/tree/issue_280 Is this worth preserving?
I do not see this branch and the link is dead. Is this something you still have around on your machine?
Sorry, I must have pasted the wrong link. I deleted the branch for the closed ticket #280 that had nothing that isn't in master. Nothing to do with this one.
The branch for this ticket is https://github.com/ess-dmsc/h5cpp/tree/issue_216 Just adds this: https://github.com/ess-dmsc/h5cpp/compare/issue_216
This branch can be definitely removed. No objections on that. But we should leave this ticket open.