Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAce committed Oct 2, 2020
1 parent 26fefbe commit f86d978
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 89 deletions.
50 changes: 32 additions & 18 deletions h5pp/include/h5pp/details/h5ppInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,40 @@ namespace h5pp {
if(h5Layout.value() == H5D_CHUNKED) {}
if(h5Layout.value() == H5D_COMPACT) {
if(dimsChunk)
error_msg.append(h5pp::format("Chunk dims {} | Layout is H5D_COMPACT | chunk dimensions are only meant for H5D_CHUNKED layouts\n", dimsChunk.value()));
if(dimsMax and dims and dimsMax.value() != dims.value())
error_msg.append(h5pp::format(
"dims {} | max dims {} | layout is H5D_COMPACT | dims and max dims must be equal unless the layout is H5D_CHUNKED\n", dims.value(), dimsMax.value()));
"Chunk dims {} | Layout is H5D_COMPACT | chunk dimensions are only meant for H5D_CHUNKED layouts\n",
dimsChunk.value()));
if(dimsMax and dims and dimsMax.value() != dims.value())
error_msg.append(h5pp::format("dims {} | max dims {} | layout is H5D_COMPACT | dims and max dims must be equal "
"unless the layout is H5D_CHUNKED\n",
dims.value(),
dimsMax.value()));
}
if(h5Layout.value() == H5D_CONTIGUOUS) {
if(dimsChunk)
error_msg.append(
h5pp::format("Chunk dims {} | Layout is H5D_CONTIGUOUS | chunk dimensions are only meant for datasets with H5D_CHUNKED layout \n", dimsChunk.value()));
error_msg.append(h5pp::format("Chunk dims {} | Layout is H5D_CONTIGUOUS | chunk dimensions are only meant for "
"datasets with H5D_CHUNKED layout \n",
dimsChunk.value()));
if(dimsMax)
error_msg.append(
h5pp::format("Max dims {} | Layout is H5D_CONTIGUOUS | max dimensions are only meant for datasets with H5D_CHUNKED layout \n", dimsMax.value()));
error_msg.append(h5pp::format("Max dims {} | Layout is H5D_CONTIGUOUS | max dimensions are only meant for datasets "
"with H5D_CHUNKED layout \n",
dimsMax.value()));
}
}
std::string res1 = reportCompatibility(dims, dimsMax);
std::string res2 = reportCompatibility(dims, dimsChunk, DimSizeComparison::PERMISSIVE);
std::string res3 = reportCompatibility(dimsChunk, dimsMax);
if(not res1.empty()) error_msg.append(h5pp::format("\t{}: dims {} | max dims {}\n", res1, dims.value(), dimsMax.value()));
if(not res2.empty()) error_msg.append(h5pp::format("\t{}: dims {} | chunk dims {}\n", res2, dims.value(), dimsChunk.value()));
if(not res3.empty()) error_msg.append(h5pp::format("\t{}: chunk dims {} | max dims {}\n", res3, dimsChunk.value(), dimsMax.value()));
if(not res3.empty())
error_msg.append(h5pp::format("\t{}: chunk dims {} | max dims {}\n", res3, dimsChunk.value(), dimsMax.value()));
return error_msg;
}

}

struct Options {
/* clang-format off */
std::optional<std::string> linkPath = std::nullopt; /*!< Path to HDF5 dataset relative to the file root */
std::optional<std::string> attrName = std::nullopt; /*!< Name of attribute on group or dataset */
OptDimsType dataDims = std::nullopt; /*!< Data dimensions hint. Required for pointer data */
Expand All @@ -84,7 +92,8 @@ namespace h5pp {
std::optional<H5D_layout_t> h5Layout = std::nullopt; /*!< (On create) Layout of dataset. Choose between H5D_CHUNKED,H5D_COMPACT and H5D_CONTIGUOUS */
std::optional<unsigned int> compression = std::nullopt; /*!< (On create) Compression level 0-9, 0 = off, 9 is gives best compression and is slowest */
std::optional<h5pp::ResizeMode> resizeMode = std::nullopt; /*!< Type of resizing if needed. Choose INCREASE_ONLY, RESIZE_TO_FIT,DO_NOT_RESIZE */
[[nodiscard]] std::string string() const {
/* clang-format on */
[[nodiscard]] std::string string() const {
std::string msg;
/* clang-format off */
if(dataDims) msg.append(h5pp::format(" | data dims {}", dataDims.value()));
Expand Down Expand Up @@ -151,7 +160,8 @@ namespace h5pp {
/* clang-format on */
hsize_t size_check = std::accumulate(dataDims->begin(), dataDims->end(), static_cast<hsize_t>(1), std::multiplies<>());
if(size_check != dataSize.value())
throw std::runtime_error(h5pp::format("Data size mismatch: dataSize [{}] | dataDims {} = size [{}]", dataSize.value(), dataDims.value(), size_check));
throw std::runtime_error(h5pp::format(
"Data size mismatch: dataSize [{}] | dataDims {} = size [{}]", dataSize.value(), dataDims.value(), size_check));
}

void assertReadReady() const {
Expand All @@ -170,7 +180,8 @@ namespace h5pp {

/* clang-format on */
hsize_t size_check = std::accumulate(dataDims->begin(), dataDims->end(), static_cast<hsize_t>(1), std::multiplies<>());
if(size_check != dataSize.value()) throw std::runtime_error(h5pp::format("Data size mismatch: dataSize [{}] | size check [{}]", dataSize.value(), size_check));
if(size_check != dataSize.value())
throw std::runtime_error(h5pp::format("Data size mismatch: dataSize [{}] | size check [{}]", dataSize.value(), size_check));
}
[[nodiscard]] std::string string() const {
// std::string msg;
Expand Down Expand Up @@ -394,19 +405,20 @@ namespace h5pp {
if(not h5Link ) error_msg.append("\t h5Link\n");
if(not h5Type ) error_msg.append("\t h5Type\n");
if(not h5Space ) error_msg.append("\t h5Space\n");
if(not h5PlistAttrCreate) error_msg.append("\t h5PlistAttrCreate\n");
if(not h5PlistAttrAccess) error_msg.append("\t h5PlistAttrAccess\n");
if(not h5PlistAttrCreate ) error_msg.append("\t h5PlistAttrCreate\n");
if(not h5PlistAttrAccess ) error_msg.append("\t h5PlistAttrAccess\n");
if(not error_msg.empty())
throw std::runtime_error(h5pp::format("Cannot create attribute. The following fields are undefined:\n{}", error_msg));
if(not linkExists.value())
throw std::runtime_error(h5pp::format("Cannot create attribute [{}] for link [{}]. The link does not exist",attrName.value(),linkPath.value()));
if(not h5Link->valid() ) error_msg.append("\t h5Link\n");
if(not h5Type->valid() ) error_msg.append("\t h5Type\n");
if(not h5Space->valid() ) error_msg.append("\t h5Space\n");
if(not h5Link->valid() ) error_msg.append("\t h5Link\n");
if(not h5Type->valid() ) error_msg.append("\t h5Type\n");
if(not h5Space->valid() ) error_msg.append("\t h5Space\n");
if(not h5PlistAttrCreate->valid()) error_msg.append("\t h5PlistAttrCreate\n");
if(not h5PlistAttrAccess->valid()) error_msg.append("\t h5PlistAttrAccess\n");
if(not error_msg.empty())
throw std::runtime_error(h5pp::format("Cannot create attribute [{}] for link [{}]. The following fields are not valid: {}",attrName.value(),linkPath.value(),error_msg));
throw std::runtime_error(h5pp::format("Cannot create attribute [{}] for link [{}]. The following fields are not valid: {}",
attrName.value(),linkPath.value(),error_msg));
/* clang-format on */
}

Expand All @@ -420,7 +432,9 @@ namespace h5pp {
if(not h5Attr->valid() ) error_msg.append("\t h5Attr\n");
if(not h5Type->valid() ) error_msg.append("\t h5Type\n");
if(not error_msg.empty())
throw std::runtime_error(h5pp::format("Cannot create attribute [{}] for link [{}]. The following fields are not valid: {}",attrName.value(),linkPath.value(),error_msg));
throw std::runtime_error(h5pp::format(
"Cannot create attribute [{}] for link [{}]. The following fields are not valid: {}",
attrName.value(),linkPath.value(),error_msg));
/* clang-format on */
}

Expand Down
33 changes: 18 additions & 15 deletions h5pp/include/h5pp/details/h5ppTypeSfinae.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ namespace h5pp::type::sfinae {
template<typename T, auto rank, typename = std::void_t<>>
struct has_resizeN : public std::false_type {};
template<typename T, auto rank>
struct has_resizeN<T, rank, std::void_t<decltype(std::declval<T>().resize(std::declval<std::array<long, rank>>()))>> : public std::true_type {};
struct has_resizeN<T, rank, std::void_t<decltype(std::declval<T>().resize(std::declval<std::array<long, rank>>()))>>
: public std::true_type {};
template<typename T, auto rank>
inline constexpr bool has_resizeN_v = has_resizeN<T, rank>::value;

Expand Down Expand Up @@ -173,7 +174,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::declval<T>().begin()), decltype(std::declval<T>().end()), typename T::value_type>> : public std::true_type {};
struct is_iterable<T, std::void_t<decltype(std::declval<T>().begin()), decltype(std::declval<T>().end()), typename T::value_type>>
: public std::true_type {};
template<typename T>
inline constexpr bool is_iterable_v = is_iterable<T>::value;

Expand Down Expand Up @@ -216,29 +218,30 @@ namespace h5pp::type::sfinae {
using enable_if_is_integral_iterable_or_num = std::enable_if_t<is_integral_iterable_or_num_v<T>>;

template<typename T>
using enable_if_is_integral_iterable_or_nullopt = std::enable_if_t<is_integral_iterable_or_num_v<T> or std::is_same_v<T, std::nullopt_t>>;


using enable_if_is_integral_iterable_or_nullopt =
std::enable_if_t<is_integral_iterable_or_num_v<T> or std::is_same_v<T, std::nullopt_t>>;

template<typename T>
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> or std::is_same_v<T, hid_t>>;
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> 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::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>>;
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::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>>;
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>>;
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>
using enable_if_not_h5_type = std::enable_if_t<not std::is_same_v<T,hid::h5t> and not std::is_same_v<T, hid_t>>;


using enable_if_not_h5_type = std::enable_if_t<not std::is_same_v<T, hid::h5t> and not std::is_same_v<T, hid_t>>;

template<typename T>
struct is_text {
Expand Down
Loading

0 comments on commit f86d978

Please sign in to comment.