Hi David,
I too recently needed H5LTopen_file_image with the C++ API. Since
I was unaware of the method Binh-Minh suggested, I instead
subclassed H5::H5File:
/**
* Open a `file image`, i.e. a chunk of memory which contains
* the contents of a HDF-5 file.
···
*
* See H5LTopen_file_image for the arguments that the constructor
* takes.
**/
class H5FileImage : public H5::H5File {
public:
H5FileImage(void *buf_ptr, size_t buf_size, unsigned flags);
static const unsigned OPEN_RW;
static const unsigned DONT_COPY;
static const unsigned DONT_RELEASE;
};
H5FileImage::H5FileImage(void *buf_ptr, size_t buf_size, unsigned flags)
: H5::H5File() {
hid_t id = H5LTopen_file_image(buf_ptr, buf_size, flags);
if (id < 0)
throw H5::FileIException("H5FileImage constructor",
"H5LTopen_file_image failed");
p_setId(id);
}
const unsigned H5FileImage::OPEN_RW = H5LT_FILE_IMAGE_OPEN_RW;
const unsigned H5FileImage::DONT_COPY = H5LT_FILE_IMAGE_DONT_COPY;
const unsigned H5FileImage::DONT_RELEASE = H5LT_FILE_IMAGE_DONT_RELEASE;
Usage should be pretty obvious:
H5FileImage f(buf_ptr, buf_size, H5FileImage::DONT_COPY &
H5FileImage::DONT_RELEASE);
// Use `f` just as you would H5::H5File.
Cheers,
Brad
________________________________
From: Hdf-forum <hdf-forum-bounces at lists.hdfgroup.org> on behalf of
David Froger <david.froger at inria.fr>
Sent: Thursday, September 12, 2013 9:41 AM
To: hdf-forum at lists.hdfgroup.org
Subject: [Hdf-forum] H5LTopen_file_image for C++ API
Hi,
I'm using a C++ library that read in a HDF5 file with the C++ HDF5 API,
using a H5File instance.
I would like to use this library to read a file image (file in memory)
instead of a file in the disk.
In C, this can be done with the 'H5LTopen_file_image' function, from HDF5
Lite, which return a hid_t for the opened file, that can be pass to other
functions (H5Dopen, ...). How could I build a H5File from this hid_t, so I
don't have to rewrite the library from the C++ HDF5 to the C HDF5 API?
Or is there another solution to read a file image with the C++ HDF5 API?
Thanks in advance,
David
~