* Transfer: Datatype Conversion and Selection</a> section in the HDF5
* User's Guide.
*/
- template <typename number>
- void
- write_dataset(const std::string name,
- const std::vector<number> &data) const;
-
- /**
- * Creates and writes data to a dataset. Number can be double, int, unsigned
- * int, bool or std::complex<double>.
- *
- * Datatype conversion takes place at the time of a read or write and is
- * automatic. See the <a
- * href="https://support.hdfgroup.org/HDF5/doc/UG/HDF5_Users_Guide-Responsive%20HTML5/index.html#t=HDF5_Users_Guide%2FDatatypes%2FHDF5_Datatypes.htm%23TOC_6_10_Data_Transferbc-26&rhtocid=6.5_2">Data
- * Transfer: Datatype Conversion and Selection</a> section in the HDF5
- * User's Guide.
- */
- template <typename number>
+ template <template <class...> class Container, typename number>
void
- write_dataset(const std::string name, const FullMatrix<number> &data) const;
+ write_dataset(const std::string name, const Container<number> &data) const;
};
/**
return t_type;
}
+ // This function returns the pointer to the raw data of a container
+ template <template <class...> class Container, typename number>
+ typename std::enable_if<
+ std::is_same<Container<number>, std::vector<number>>::value,
+ std::vector<hsize_t>>::type
+ get_container_dimensions(const Container<number> &data)
+ {
+ return std::vector<hsize_t>{data.size()};
+ }
+
+ template <template <class...> class Container, typename number>
+ typename std::enable_if<
+ std::is_same<Container<number>, Vector<number>>::value,
+ std::vector<hsize_t>>::type
+ get_container_dimensions(const Container<number> &data)
+ {
+ return std::vector<hsize_t>{data.size()};
+ }
+
+ template <template <class...> class Container, typename number>
+ typename std::enable_if<
+ std::is_same<Container<number>, FullMatrix<number>>::value,
+ std::vector<hsize_t>>::type
+ get_container_dimensions(const Container<number> &data)
+ {
+ return std::vector<hsize_t>{data.m(), data.n()};
+ }
+
+
// This function returns the pointer to the raw data of a container
template <template <class...> class Container, typename number>
typename std::enable_if<
unsigned int>::type
get_container_size(const Container<number> &data)
{
- // It is very important to pass the variable "data" by reference otherwise
- // the pointer will be wrong
return static_cast<unsigned int>(data.size());
}
unsigned int>::type
get_container_size(const Container<number> &data)
{
- // It is very important to pass the variable "data" by reference otherwise
- // the pointer will be wrong
return static_cast<unsigned int>(data.size());
}
unsigned int>::type
get_container_size(const Container<number> &data)
{
- // It is very important to pass the variable "data" by reference otherwise
- // the pointer will be wrong.
- // Use the first element of FullMatrix to get the pointer to the raw data
return static_cast<unsigned int>(data.m() * data.n());
}
return DataSet(name, *hdf5_reference, dimensions, t_type, mpi);
}
- template <typename number>
- void
- Group::write_dataset(const std::string name,
- const std::vector<number> &data) const
- {
- std::vector<hsize_t> dimensions = {data.size()};
- auto dataset = create_dataset<number>(name, dimensions);
- dataset.write(data);
- }
-
- template <typename number>
+ template <template <class...> class Container, typename number>
void
- Group::write_dataset(const std::string name,
- const FullMatrix<number> &data) const
+ Group::write_dataset(const std::string name,
+ const Container<number> &data) const
{
- std::vector<hsize_t> dimensions = {data.m(), data.n()};
+ std::vector<hsize_t> dimensions = internal::get_container_dimensions(data);
auto dataset = create_dataset<number>(name, dimensions);
dataset.write(data);
}
-
File::File(const std::string name,
const bool mpi,
const MPI_Comm mpi_communicator,
const std::vector<hsize_t> dimensions) const;
template void
- Group::write_dataset(const std::string name,
- const std::vector<int> &data) const;
+ Group::write_dataset<std::vector, int>(const std::string name,
+ const std::vector<int> &data) const;
template void
- Group::write_dataset(const std::string name,
- const std::vector<unsigned int> &data) const;
+ Group::write_dataset<std::vector, unsigned int>(
+ const std::string name,
+ const std::vector<unsigned int> &data) const;
# endif // DOXYGEN
template DataSet Group::create_dataset<number>(
const std::string name, const std::vector<hsize_t> dimensions) const;
- template void Group::write_dataset(const std::string name,
- const std::vector<number> &data) const;
+ template void Group::write_dataset<std::vector, number>(
+ const std::string name, const std::vector<number> &data) const;
- template void Group::write_dataset(const std::string name,
- const FullMatrix<number> &data) const;
+ template void Group::write_dataset<Vector, number>(
+ const std::string name, const Vector<number> &data) const;
+
+ template void Group::write_dataset<FullMatrix, number>(
+ const std::string name, const FullMatrix<number> &data) const;
}
\ No newline at end of file