diff --git a/src/hdf5_array.hpp b/src/hdf5_array.hpp index 64eab5f..4250a0d 100644 --- a/src/hdf5_array.hpp +++ b/src/hdf5_array.hpp @@ -90,10 +90,31 @@ namespace CosmoTool { #undef HDF5_TYPE + // Extent generator + template + struct hdf5_extent_gen { + typedef typename boost::detail::multi_array::extent_gen type; + + static inline type build(hsize_t *d) + { + return (hdf5_extent_gen::build(d))[d[r-1]]; + } + }; + + template<> + struct hdf5_extent_gen<0> { + static inline boost::multi_array_types::extent_gen build(hsize_t *d) + { + return boost::extents; + } + }; + + //!_______________________________________________________________________________________ //! //! write_hdf5 multi_array //! +//! \author Guilhem Lavaux (2014-2015) //! \author leo Goodstadt (04 March 2013) //! //!_______________________________________________________________________________________ @@ -214,24 +235,11 @@ namespace CosmoTool { class InvalidDimensions: virtual std::exception { }; - template - struct hdf5_extent_gen { - typedef typename boost::detail::multi_array::extent_gen type; - - static inline type build(hsize_t *d) - { - return (hdf5_extent_gen::build(d))[d[r-1]]; - } - }; - - template<> - struct hdf5_extent_gen<0> { - static inline boost::multi_array_types::extent_gen build(hsize_t *d) - { - return boost::extents; - } - }; + // ---------------------------------------------------------------------- + // Conditional resize support + // If the Array type support resize then it is called. Otherwise + // the dimensions are checked and lead to a failure if they are different template class array_has_resize { struct Fallback { int resize; }; @@ -280,11 +288,13 @@ namespace CosmoTool { hdf5_resize_array(ArrayType& data, std::vector& dims) { hdf5_check_array(data, dims); } + + // ---------------------------------------------------------------------- template void hdf5_read_array_typed(H5::CommonFG& fg, const std::string& data_set_name, - ArrayType& data, - const hdf5_data_type& datatype, bool auto_resize = true) + ArrayType& data, + const hdf5_data_type& datatype, bool auto_resize = true) { H5::DataSet dataset = fg.openDataSet(data_set_name); H5::DataSpace dataspace = dataset.getSpace(); @@ -309,8 +319,7 @@ namespace CosmoTool { { typedef typename ArrayType::element T; - get_hdf5_data_type hdf_data_type; - hdf5_read_array_typed(fg, data_set_name, data, hdf_data_type.type(), auto_resize); + hdf5_read_array_typed(fg, data_set_name, data, get_hdf5_data_type::type(), auto_resize); }