Skip to content

Commit

Permalink
Add ostream operators to vstr_t and add .size() member to varr_t
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAce committed Nov 7, 2022
1 parent 33577b1 commit e85246e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/h5pp/details/h5ppVarr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include "h5ppFormat.h"
#include "h5ppTypeCompound.h"
#include <complex>
#include <cstdlib>
Expand Down Expand Up @@ -41,6 +42,7 @@ namespace h5pp::type::vlen {
hvl_t *vlen_data();
const hvl_t *vlen_data() const;
[[nodiscard]] size_t vlen_size() const;
[[nodiscard]] size_t size() const;
[[nodiscard]] size_t length() const;
const T *begin() const;
const T *end() const;
Expand All @@ -49,6 +51,19 @@ namespace h5pp::type::vlen {
bool empty() const;
static hid::h5t get_h5type();
~varr_t() noexcept;

#if !defined(FMT_FORMAT_H_) || !defined(H5PP_USE_FMT)
friend auto operator<<(std::ostream &os, const varr_t &v) -> std::ostream & {
if(v.empty())
os << "[]";
else {
os << "[";
std::copy(v.begin(), v.end(), std::ostream_iterator<T>(os, ", "));
os << "\b\b]";
}
return os;
}
#endif
};

template<typename T>
Expand Down Expand Up @@ -197,6 +212,10 @@ namespace h5pp::type::vlen {
return vl.len;
}
template<typename T>
size_t varr_t<T>::size() const {
return vl.len;
}
template<typename T>
size_t varr_t<T>::length() const {
return vl.len;
}
Expand Down
6 changes: 6 additions & 0 deletions include/h5pp/details/h5ppVstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ namespace h5pp::type::vlen {
void append(std::string_view v);
static hid::h5t get_h5type();
~vstr_t() noexcept;
#if !defined(FMT_FORMAT_H_) || !defined(H5PP_USE_FMT)
friend auto operator<<(std::ostream &os, const vstr_t &v) -> std::ostream & {
std::copy(v.begin(), v.end(), std::ostream_iterator<char>(os, ", "));
return os;
}
#endif
};

inline vstr_t::operator std::string_view() const { return {begin(), size()}; }
Expand Down

0 comments on commit e85246e

Please sign in to comment.