Skip to content

Commit

Permalink
Fixed some sfinae detection of h5 objects
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAce committed Oct 10, 2020
1 parent c96270c commit 84d97ab
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
4 changes: 2 additions & 2 deletions h5pp/include/h5pp/details/h5ppHdf5.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ namespace h5pp::hdf5 {
}
}

template<typename h5x, typename = h5pp::type::sfinae::enable_if_is_h5_link_or_hid_t<h5x>>
template<typename h5x, typename = h5pp::type::sfinae::enable_if_is_h5_link<h5x>>
[[nodiscard]] inline bool checkIfAttributeExists(const h5x & link,
std::string_view linkPath,
std::string_view attrName,
Expand All @@ -521,7 +521,7 @@ namespace h5pp::hdf5 {
return exists;
}

template<typename h5x, typename = h5pp::type::sfinae::enable_if_is_h5_loc_or_hid_t<h5x>>
template<typename h5x, typename = std::enable_if_t<std::is_same_v<h5x,hid::h5f>>>
[[nodiscard]] inline bool checkIfAttributeExists(const h5x & loc,
std::string_view linkPath,
std::string_view attrName,
Expand Down
17 changes: 9 additions & 8 deletions h5pp/include/h5pp/details/h5ppInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,14 @@ namespace h5pp {
std::optional<size_t> cppTypeSize = std::nullopt;
std::optional<std::type_index> cppTypeIndex = std::nullopt;

[[nodiscard]] hid_t getLocId() const {
[[nodiscard]] hid::h5f getLocId() const {
if(h5File) return h5File.value();
if(h5Group) return h5Group.value();
if(h5ObjLoc) return h5ObjLoc.value();
if(h5Group) return H5Iget_file_id(h5Group.value());
if(h5ObjLoc) return H5Iget_file_id(h5ObjLoc.value());
h5pp::logger::log->debug("Dataset location id is not defined");
return -1;
return static_cast<hid_t>(0);
}

void assertCreateReady() const {
std::string error_msg;
/* clang-format off */
Expand Down Expand Up @@ -494,12 +495,12 @@ namespace h5pp {
std::optional<std::vector<size_t>> cppTypeSize = std::nullopt;
std::optional<std::vector<std::type_index>> cppTypeIndex = std::nullopt;

[[nodiscard]] hid_t getTableLocId() const {
[[nodiscard]] hid::h5f getTableLocId() const {
if(tableFile) return tableFile.value();
if(tableGroup) return tableGroup.value();
if(tableObjLoc) return tableObjLoc.value();
if(tableGroup) return H5Iget_file_id(tableGroup.value());
if(tableObjLoc) return H5Iget_file_id(tableObjLoc.value());
h5pp::logger::log->debug("Table location is not defined");
return -1;
return static_cast<hid_t>(0);
}
/* clang-format off */
void assertCreateReady() const {
Expand Down
29 changes: 15 additions & 14 deletions h5pp/include/h5pp/details/h5ppTypeSfinae.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ namespace h5pp::type::sfinae {
}

// helper constant for static asserts
template<class> inline constexpr bool always_false_v = false;
template<class> inline constexpr bool unrecognized_type_v = false;
template<class> inline constexpr bool invalid_type_v = false;
template<class>
inline constexpr bool always_false_v = false;
template<class>
inline constexpr bool unrecognized_type_v = false;
template<class>
inline constexpr bool invalid_type_v = false;

template<typename T, typename = std::void_t<>>
struct has_size : public std::false_type {};
Expand Down Expand Up @@ -179,7 +182,8 @@ namespace h5pp::type::sfinae {
template<typename T, typename = std::void_t<>>
struct is_iterable : public std::false_type {};
template<typename T>
struct is_iterable<T, std::void_t<decltype(std::begin(std::declval<T>())),decltype(std::end(std::declval<T>()))>> : public std::true_type {};
struct is_iterable<T, std::void_t<decltype(std::begin(std::declval<T>())), decltype(std::end(std::declval<T>()))>>
: public std::true_type {};
template<typename T>
inline constexpr bool is_iterable_v = is_iterable<T>::value;

Expand Down Expand Up @@ -229,19 +233,16 @@ namespace h5pp::type::sfinae {
using enable_if_is_iterable_or_nullopt = std::enable_if_t<is_iterable_v<T> or std::is_same_v<T, std::nullopt_t>>;

template<typename T>
using enable_if_is_h5_loc = std::enable_if_t<std::is_same_v<T, hid::h5f> or std::is_same_v<T, hid::h5g> or
std::is_same_v<T, hid::h5o> or std::is_same_v<T, hid_t>>;
using enable_if_is_h5_loc = std::enable_if_t<std::is_same_v<T, hid::h5f> or std::is_same_v<T, hid::h5g> or std::is_same_v<T, hid::h5o>>;
template<typename T>
using enable_if_is_h5_loc_or_hid_t =
std::enable_if_t<std::is_same_v<T, hid::h5f> or std::is_same_v<T, hid::h5g> or std::is_same_v<T, hid::h5o> or
std::is_same_v<T, hid_t> or std::is_same_v<T, hid_t>>;
using enable_if_is_h5_loc_or_hid_t = std::enable_if_t<std::is_same_v<T, hid::h5f> or std::is_same_v<T, hid::h5g> or
std::is_same_v<T, hid::h5o> or std::is_same_v<T, hid_t>>;
template<typename T>
using enable_if_is_h5_link = std::enable_if_t<std::is_same_v<T, hid::h5f> or std::is_same_v<T, hid::h5d> or
std::is_same_v<T, hid::h5g> or std::is_same_v<T, hid::h5o> or std::is_same_v<T, hid_t>>;
using enable_if_is_h5_link =
std::enable_if_t<std::is_same_v<T, hid::h5d> or std::is_same_v<T, hid::h5g> or std::is_same_v<T, hid::h5o>>;
template<typename T>
using enable_if_is_h5_link_or_hid_t =
std::enable_if_t<std::is_same_v<T, hid::h5f> or std::is_same_v<T, hid::h5d> or std::is_same_v<T, hid::h5g> or
std::is_same_v<T, hid::h5o> or std::is_same_v<T, hid_t> or std::is_same_v<T, hid_t>>;
using enable_if_is_h5_link_or_hid_t = std::enable_if_t<std::is_same_v<T, hid::h5d> or std::is_same_v<T, hid::h5g> or
std::is_same_v<T, hid::h5o> or std::is_same_v<T, hid_t>>;
template<typename T>
using enable_if_is_h5_type = std::enable_if_t<std::is_same_v<T, hid::h5t> or std::is_same_v<T, hid_t>>;
template<typename T>
Expand Down

0 comments on commit 84d97ab

Please sign in to comment.