diff --git a/src/hdf5_array.hpp b/src/hdf5_array.hpp index c6ce5c9..318181f 100644 --- a/src/hdf5_array.hpp +++ b/src/hdf5_array.hpp @@ -180,7 +180,49 @@ namespace CosmoTool { return boost::extents; } }; + + + template class array_has_resize { + struct Fallback { int resize; }; + struct Derived: Array, Fallback {}; + typedef char yes[1]; + typedef char no[2]; + + template struct Check; + + template + static yes& func(Check *); + + template + static no& func(...); + public: + typedef array_has_resize type; + enum { value = sizeof(func(0)) == sizeof(no) }; + }; + + + + template + typename boost::enable_if< + array_has_resize + >::type + hdf5_resize_array(ArrayType& data, std::vector& dims) { + data.resize( + hdf5_extent_gen::build(dims.data()) + ); + } + + template + typename boost::disable_if< + array_has_resize + >::type + hdf5_resize_array(ArrayType& data, std::vector& dims) { + for (long i = 0; i < data.num_dimensions(); i++) { + assert (data.shape()[i] == dims[i]); + } + } + template 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::build(dimensions.data())); + hdf5_resize_array(data, dimensions); dataset.read(data.data(), datatype); }