Moved extent generator definition up

This commit is contained in:
Guilhem Lavaux 2015-03-21 18:27:09 +01:00
parent bf0be4fb61
commit 03fce51182

View File

@ -90,10 +90,31 @@ namespace CosmoTool {
#undef HDF5_TYPE #undef HDF5_TYPE
// Extent generator
template<std::size_t r>
struct hdf5_extent_gen {
typedef typename boost::detail::multi_array::extent_gen<r> type;
static inline type build(hsize_t *d)
{
return (hdf5_extent_gen<r-1>::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 //! write_hdf5 multi_array
//! //!
//! \author Guilhem Lavaux (2014-2015)
//! \author leo Goodstadt (04 March 2013) //! \author leo Goodstadt (04 March 2013)
//! //!
//!_______________________________________________________________________________________ //!_______________________________________________________________________________________
@ -214,24 +235,11 @@ namespace CosmoTool {
class InvalidDimensions: virtual std::exception { class InvalidDimensions: virtual std::exception {
}; };
template<std::size_t r>
struct hdf5_extent_gen {
typedef typename boost::detail::multi_array::extent_gen<r> type;
static inline type build(hsize_t *d)
{
return (hdf5_extent_gen<r-1>::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<typename Array> class array_has_resize { template<typename Array> class array_has_resize {
struct Fallback { int resize; }; struct Fallback { int resize; };
@ -280,11 +288,13 @@ namespace CosmoTool {
hdf5_resize_array(ArrayType& data, std::vector<hsize_t>& dims) { hdf5_resize_array(ArrayType& data, std::vector<hsize_t>& dims) {
hdf5_check_array(data, dims); hdf5_check_array(data, dims);
} }
// ----------------------------------------------------------------------
template<typename ArrayType, typename hdf5_data_type> template<typename ArrayType, typename hdf5_data_type>
void hdf5_read_array_typed(H5::CommonFG& fg, const std::string& data_set_name, void hdf5_read_array_typed(H5::CommonFG& fg, const std::string& data_set_name,
ArrayType& data, ArrayType& data,
const hdf5_data_type& datatype, bool auto_resize = true) const hdf5_data_type& datatype, bool auto_resize = true)
{ {
H5::DataSet dataset = fg.openDataSet(data_set_name); H5::DataSet dataset = fg.openDataSet(data_set_name);
H5::DataSpace dataspace = dataset.getSpace(); H5::DataSpace dataspace = dataset.getSpace();
@ -309,8 +319,7 @@ namespace CosmoTool {
{ {
typedef typename ArrayType::element T; typedef typename ArrayType::element T;
get_hdf5_data_type<T> hdf_data_type; hdf5_read_array_typed(fg, data_set_name, data, get_hdf5_data_type<T>::type(), auto_resize);
hdf5_read_array_typed(fg, data_set_name, data, hdf_data_type.type(), auto_resize);
} }