When inserting temporary property with H5Pinsert2(dapl_id, ...)
into hid_t dapl_id
and checking its existence with H5Pexist( dapl_id, ... )
I get confirmed response.
However when passing this dapl_id
to hid_t ds = H5Dopen(fd, "some_dataset", dapl_id);
then retrieving data access property dapl_
with H5Dget_access_plist()
from the returned descriptor ds
I get negative response.
OTOH when I copy property into the dapl_
newly retrieved directly from dataset, I get positive response, but the copy_callback(...)
function specified to H5Pinsert2(...)
doesn’t get called.
My interpretation of temporary properties that they have the lifespan of the property list, in this case dapl_id
.
The goal is to have a custom property with lifespan of the property list.
What am I doing wrong?
SSCCE added:
#include <iostream>
#include <hdf5.h>
#define CUSTOM_PROP "custom propery"
namespace exp {
struct custom_prop_t {
custom_prop_t(){ std::cout <<"<CTOR>"; }
~custom_prop_t(){ std::cout <<"<DTOR>"; }
};
herr_t dapl_custom_prop_create( const char *name, size_t size, void *initial_value){
std::cout <<"<prop create>\n";
return 1;
}
herr_t dapl_custom_prop_set( ::hid_t dapl_id, const char *name, size_t size, void *new_value){
std::cout <<"<prop set>\n";
return 1;
}
herr_t dapl_custom_prop_get( ::hid_t dapl_id, const char *name, size_t size, void *value){
return 1;
}
herr_t dapl_custom_prop_delete( ::hid_t dapl_id, const char *name, size_t size, void *value){
std::cout << "<prop delete>\n";
return 1;
}
herr_t dapl_custom_prop_copy( const char *name, size_t size, void *value){
std::cout <<"<prop copy>\n";
return 1;
}
int dapl_custom_prop_comp( const void *value1, const void *value2, size_t size){
std::cout << "<prop comp>\n";
return 1;
}
herr_t dapl_custom_prop_close( const char *name, size_t size, void *ptr ){
delete *static_cast<exp::custom_prop_t**>( ptr );
return 1;
}
::herr_t dapl_custom_prop(::hid_t dapl ){
exp::custom_prop_t* ptr = new exp::custom_prop_t();
return H5Pinsert2(dapl, CUSTOM_PROP, sizeof(exp::custom_prop_t*), &ptr,
dapl_custom_prop_set, dapl_custom_prop_get, dapl_custom_prop_delete, dapl_custom_prop_copy, dapl_custom_prop_comp, dapl_custom_prop_close);
}
}
int main(int argc, char **argv) {
std::cout << "\n\n";
std::cout << "creating dapl_0 and dapl_1: \n";
hid_t dapl_0 = H5Pcreate( H5P_DATASET_ACCESS );
hid_t dapl_1 = H5Pcreate( H5P_DATASET_ACCESS );
std::cout << "inserting custom property into dapl_0, expecting <CTOR> being called: \n";
herr_t err = exp::dapl_custom_prop( dapl_0 );
std::cout << "status (herr_t) < 0 => error : " << err <<"\n";
std::cout << "checking the existence of custom prop in dapl_0:\n";
if( H5Pexist(dapl_0, CUSTOM_PROP) ){
std::cout<<"<dapl_0 custom prop present>\n";
}else{
std::cout<<"<dapl_0 custom prop NOT present>\n";
}
std::cout<< "copying custom prop from dapl_0 to dapl_1, expecting copy callback should be called:\n";
H5Pcopy_prop(dapl_1, dapl_0, CUSTOM_PROP );
std::cout<<"";
std::cout << "\n\n";
return 0;
}