Skip to content

Commit

Permalink
Fix boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
alkino committed Jan 23, 2023
1 parent ecb7b70 commit 52b7d9e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
25 changes: 16 additions & 9 deletions include/highfive/bits/H5Converter_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ struct inspector<std::string>: type_helper<std::string> {
}

static const hdf5_type* data(const type& /* val */) {
throw DataSpaceException("A std::string cannot be write directly.");
throw DataSpaceException("A std::string cannot be written directly.");
}

static void serialize(const type& val, hdf5_type* m) {
Expand All @@ -185,7 +185,7 @@ struct inspector<Reference>: type_helper<Reference> {
}

static const hdf5_type* data(const type& /* val */) {
throw DataSpaceException("A Reference cannot be write directly.");
throw DataSpaceException("A Reference cannot be written directly.");
}

static void serialize(const type& val, hdf5_type* m) {
Expand Down Expand Up @@ -265,7 +265,8 @@ struct inspector<std::vector<T>> {

static constexpr size_t ndim = 1;
static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value &&
inspector<value_type>::is_trivially_copyable;

static std::vector<size_t> getDimensions(const type& val) {
std::vector<size_t> sizes{val.size()};
Expand Down Expand Up @@ -329,7 +330,8 @@ struct inspector<std::array<T, N>> {

static constexpr size_t ndim = 1;
static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value &&
inspector<value_type>::is_trivially_copyable;

static std::vector<size_t> getDimensions(const type& val) {
std::vector<size_t> sizes{N};
Expand Down Expand Up @@ -399,7 +401,8 @@ struct inspector<T*> {

static constexpr size_t ndim = 1;
static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value &&
inspector<value_type>::is_trivially_copyable;

static size_t getSizeVal(const type& /* val */) {
throw DataSpaceException("Not possible to have size of a T*");
Expand Down Expand Up @@ -430,7 +433,8 @@ struct inspector<T[N]> {

static constexpr size_t ndim = 1;
static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value &&
inspector<value_type>::is_trivially_copyable;

static size_t getSizeVal(const type& val) {
return compute_total_size(getDimensions(val));
Expand Down Expand Up @@ -469,7 +473,8 @@ struct inspector<Eigen::Matrix<T, M, N>> {

static constexpr size_t ndim = 2;
static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value &&
inspector<value_type>::is_trivially_copyable;

static std::vector<size_t> getDimensions(const type& val) {
std::vector<size_t> sizes{static_cast<size_t>(val.rows()), static_cast<size_t>(val.cols())};
Expand Down Expand Up @@ -530,7 +535,8 @@ struct inspector<boost::multi_array<T, Dims>> {

static constexpr size_t ndim = Dims;
static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value &&
inspector<value_type>::is_trivially_copyable;

static std::vector<size_t> getDimensions(const type& val) {
std::vector<size_t> sizes;
Expand Down Expand Up @@ -608,7 +614,8 @@ struct inspector<boost::numeric::ublas::matrix<T>> {

static constexpr size_t ndim = 2;
static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value &&
inspector<value_type>::is_trivially_copyable;

static std::vector<size_t> getDimensions(const type& val) {
std::vector<size_t> sizes{val.size1(), val.size2()};
Expand Down
1 change: 0 additions & 1 deletion include/highfive/bits/H5DataType_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,3 @@ inline DataType create_and_check_datatype() {

} // namespace HighFive
HIGHFIVE_REGISTER_TYPE(HighFive::details::Boolean, HighFive::create_enum_boolean)
HIGHFIVE_REGISTER_TYPE(bool, HighFive::create_enum_boolean)
12 changes: 7 additions & 5 deletions tests/unit/test_all_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ TEMPLATE_TEST_CASE("Scalar in DataSet",

// Create the dataset
DataSet dataset =
file.createDataSet(DATASET_NAME, DataSpace(1), create_datatype<TestType>());
file.createDataSet(DATASET_NAME,
DataSpace(1),
create_datatype<typename details::inspector<TestType>::base_type>());

// Write into the initial part of the dataset
dataset.write(t1);
Expand Down Expand Up @@ -100,8 +102,8 @@ TEMPLATE_PRODUCT_TEST_CASE("Scalar in std::vector",
File file(FILE_NAME, File::ReadWrite | File::Create | File::Truncate);

// Create the dataset
DataSet dataset =
file.createDataSet(DATASET_NAME, {5}, create_datatype<typename TestType::value_type>());
DataSet dataset = file.createDataSet(
DATASET_NAME, {5}, create_datatype<typename details::inspector<TestType>::base_type>());

// Write into the initial part of the dataset
dataset.write(t1);
Expand Down Expand Up @@ -190,7 +192,7 @@ TEMPLATE_TEST_CASE("Scalar in std::array",
float,
double,
long double,
/* bool, */
bool,
std::string,
std::complex<float>,
std::complex<double>,
Expand Down Expand Up @@ -241,7 +243,7 @@ TEMPLATE_TEST_CASE("Scalar in std::vector<std::array>",
float,
double,
long double,
/* bool, */
bool,
std::string,
std::complex<float>,
std::complex<double>,
Expand Down

0 comments on commit 52b7d9e

Please sign in to comment.