From 03fce51182d50d8ceef14ce20628cce1f6f2a016 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Sat, 21 Mar 2015 18:27:09 +0100 Subject: [PATCH] Moved extent generator definition up --- src/hdf5_array.hpp | 51 +++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 21 deletions(-) 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); }