-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add custom drivers non-intrusively? #650
Comments
Yes, it would be nice to support |
Hello @FlyingSamson, I've just created PR which adds DriverID::Custom=0 (#665) |
Yes, that solves my issue. For an (currently) internal project I'm developing a Virtual File Driver for hdf5, which I would like to use with h5cpp. I don't think that this offers much testing potential, but maybe one could add an example. What I currently do to add the VFD to h5cpp is (merged into one header instead of definitions in a separate CU for simplicity): class MyDriver : public hdf5::file::Driver {
public:
MyDriver(<some type> parameters_for_file_access) : _parameters_for_file_access{parameters_for_file_access} {}
MyDriver(const MyDriver&) = default;
virtual void operator()(const hdf5::property::FileAccessList& fapl) const override {
if (H5Pset_fapl_my_vfd(static_cast<hid_t>(fapl), _parameters_for_file_access) < 0) {
hdf5::error::Singleton::instance().throw_with_stack("Failure setting my_vfd driver!");
}
}
[[nodiscard]] virtual hdf5::file::DriverID id() const noexcept override {
return hdf5::file::DriverID::Custom;
}
private:
<some type> _parameters_for_file_access;
};
And then I call on a
and use that |
For the project I'm currently working on, I need to write a custom driver.
Inheriting from
hdf5::file::Driver
works per se, but to overload the pure virtual functionid()
I need to return ahdf5::file::DriverID
, which currently is limited toPosix
,Direct
,Memory
, andMPI
.I could not find any reference to
hdf5::file::DriverID
other than the once in the existing driversid()
functions, so I'm not sure what the intended useid()
is.Would it be feasible to add another choice (e.g.,
Custom
) to thehdf5::file::DriverID
enum?Alternatively, if the ID should remain unique even when multiple custom drivers are to be used, one might also consider some form of registration, that hands out unique integer ids for each driver. In any case I believe driver should be implemented as an open set, since hdf5 itself implements it that way. The implementation using the enum class makes this difficult, as it inherently makes it a closed set.
The text was updated successfully, but these errors were encountered: