hdf5_read_array now supports array witout resize.
This commit is contained in:
parent
c853abe354
commit
1ab31e6c19
@ -181,6 +181,48 @@ namespace CosmoTool {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename Array> class array_has_resize {
|
||||
struct Fallback { int resize; };
|
||||
struct Derived: Array, Fallback {};
|
||||
|
||||
typedef char yes[1];
|
||||
typedef char no[2];
|
||||
|
||||
template<typename U, U> struct Check;
|
||||
|
||||
template<typename U>
|
||||
static yes& func(Check<int Fallback::*, &U::resize> *);
|
||||
|
||||
template<typename U>
|
||||
static no& func(...);
|
||||
public:
|
||||
typedef array_has_resize type;
|
||||
enum { value = sizeof(func<Derived>(0)) == sizeof(no) };
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename ArrayType>
|
||||
typename boost::enable_if<
|
||||
array_has_resize<ArrayType>
|
||||
>::type
|
||||
hdf5_resize_array(ArrayType& data, std::vector<hsize_t>& dims) {
|
||||
data.resize(
|
||||
hdf5_extent_gen<ArrayType::dimensionality>::build(dims.data())
|
||||
);
|
||||
}
|
||||
|
||||
template<typename ArrayType>
|
||||
typename boost::disable_if<
|
||||
array_has_resize<ArrayType>
|
||||
>::type
|
||||
hdf5_resize_array(ArrayType& data, std::vector<hsize_t>& dims) {
|
||||
for (long i = 0; i < data.num_dimensions(); i++) {
|
||||
assert (data.shape()[i] == dims[i]);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename ArrayType, typename hdf5_data_type>
|
||||
void hdf5_read_array(H5::CommonFG& fg, const std::string& data_set_name,
|
||||
ArrayType& data,
|
||||
@ -196,7 +238,7 @@ namespace CosmoTool {
|
||||
}
|
||||
|
||||
dataspace.getSimpleExtentDims(dimensions.data());
|
||||
data.resize(hdf5_extent_gen<ArrayType::dimensionality>::build(dimensions.data()));
|
||||
hdf5_resize_array(data, dimensions);
|
||||
dataset.read(data.data(), datatype);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user