23 #include "splash/AttributeInfo.hpp" 24 #include "splash/CollectionType.hpp" 25 #include "splash/basetypes/generateCollectionType.hpp" 32 AttributeInfo::AttributeInfo(hid_t attr): attr_(attr), colType_(NULL)
36 AttributeInfo::AttributeInfo(
H5AttributeId& attr): attr_(attr.release()), colType_(NULL)
40 AttributeInfo::~AttributeInfo()
45 AttributeInfo::AttributeInfo(
const AttributeInfo& other): attr_(other.attr_), colType_(NULL)
62 std::string AttributeInfo::getExceptionString(
const std::string& msg)
64 return (std::string(
"Exception for DCAttribute [") +
readName() +
65 std::string(
"] ") + msg);
68 inline void AttributeInfo::loadType()
throw(
DCException)
72 type_.
reset(H5Aget_type(attr_));
74 throw DCException(getExceptionString(
"Could not get type"));
78 inline void AttributeInfo::loadSpace()
throw(
DCException)
82 space_.
reset(H5Aget_space(attr_));
84 throw DCException(getExceptionString(
"Could not get dataspace"));
86 if (H5Sis_simple(space_) <= 0)
87 throw DCException(getExceptionString(
"Dataspace is not simple"));
88 H5S_class_t spaceClass = H5Sget_simple_extent_type(space_);
89 if (spaceClass == H5S_SCALAR)
93 int nDims = H5Sget_simple_extent_ndims(space_);
95 throw DCException(getExceptionString(
"Could not get dimensionality of dataspace"));
96 nDims_ =
static_cast<uint32_t
>(nDims);
103 ssize_t nameLen = H5Aget_name(attr_, 0, NULL);
105 return std::string();
106 char* name =
new char[nameLen + 1];
108 if(H5Aget_name(attr_, nameLen + 1, name) < 0)
110 std::string strName(name);
120 if(H5Tis_variable_str(type_))
121 return H5Tget_size(type_);
124 size_t result = H5Aget_storage_size(attr_);
126 assert(result == H5Tget_size(type_) *
getDims().getScalarSize());
148 if (nDims_ > DSP_DIM_MAX)
149 throw DCException(getExceptionString(
"Dimensionality of dataspace is greater than the maximum supported value"));
150 int nDims2 = H5Sget_simple_extent_dims(space_, dims.
getPointer(), NULL);
152 if (nDims2 != static_cast<int>(nDims_))
153 throw DCException(getExceptionString(
"Could not get dimensions of dataspace"));
163 return nDims_ == 0 ? 1 : nDims_;
169 return H5Tis_variable_str(type_);
175 throw DCException(getExceptionString(
"Could not read or convert data"));
180 return H5Aread(attr_, colType.
getDataType(), buf) >= 0;
188 std::stringstream ss;
189 ss <<
"Buffer size (" << bufSize <<
") does not match attribute size (" <<
getMemSize() <<
")";
192 if(H5Aread(attr_, type_, buf) < 0)
193 throw DCException(getExceptionString(
"Could not read data"));
205 swap(lhs.attr_, rhs.attr_);
206 swap(lhs.colType_, rhs.colType_);
207 swap(lhs.type_, rhs.type_);
208 swap(lhs.space_, rhs.space_);
209 swap(lhs.nDims_, rhs.nDims_);
const CollectionType & getType()
CollectionType * generateCollectionType(hid_t datatype_id)
void swapDims(uint32_t dims)
const H5DataType & getDataType() const
bool readNoThrow(const CollectionType &colType, void *buf)
void read(const CollectionType &colType, void *buf)