23 #include "splash/AttributeInfo.hpp" 24 #include "splash/core/DCAttribute.hpp" 25 #include "splash/core/H5IdWrapper.hpp" 30 std::string DCAttribute::getExceptionString(
const char *name, std::string msg)
32 return (std::string(
"Exception for DCAttribute [") + std::string(name) +
33 std::string(
"] ") + msg);
36 AttributeInfo DCAttribute::readAttributeInfo(
const char* name, hid_t parent)
41 throw DCException(getExceptionString(name,
"Attribute could not be opened for reading"));
42 return AttributeInfo(attr);
45 void DCAttribute::readAttribute(
const char* name, hid_t parent,
void* dst)
50 throw DCException(getExceptionString(name,
"Attribute could not be opened for reading"));
52 H5TypeId attr_type(H5Aget_type(attr));
54 throw DCException(getExceptionString(name,
"Could not get type of attribute"));
56 if (H5Aread(attr, attr_type, dst) < 0)
57 throw DCException(getExceptionString(name,
"Attribute could not be read"));
60 void DCAttribute::writeAttribute(
const char* name,
const hid_t type, hid_t parent,
61 uint32_t ndims, Dimensions dims,
const void* src)
65 if (H5Aexists(parent, name))
66 attr.reset(H5Aopen(parent, name, H5P_DEFAULT));
71 if( ndims == 1 && dims.getScalarSize() == 1 )
72 dsp.
reset(H5Screate(H5S_SCALAR));
74 dsp.reset(H5Screate_simple( ndims, dims.getPointer(), dims.getPointer() ));
76 attr.reset(H5Acreate(parent, name, type, dsp, H5P_DEFAULT, H5P_DEFAULT));
80 throw DCException(getExceptionString(name,
"Attribute could not be opened or created"));
82 if (H5Awrite(attr, type, src) < 0)
83 throw DCException(getExceptionString(name,
"Attribute could not be written"));
86 void DCAttribute::writeAttribute(
const char* name,
const hid_t type, hid_t parent,
const void* src)
89 const Dimensions dims(1, 1, 1);
90 writeAttribute(name, type, parent, 1u, dims, src);
H5IdWrapper< H5Tclose, policies::NoCopy > H5TypeId
H5IdWrapper< H5Sclose, policies::NoCopy > H5DataspaceId
H5IdWrapper< H5Aclose, policies::NoCopy > H5AttributeId