33 explicit word_view(std::span<std::uint64_t const> words) noexcept
34 :
bytes_(std::as_bytes(words)),
little_(std::endian::native == std::endian::little) {}
37 if (
bytes.size() & 7) error_detail::raise<std::invalid_argument>(
"word section length is not a multiple of eight");
41 std::size_t
size() const noexcept {
return bytes_.size() >> 3; }
43 std::span<std::byte const>
bytes() const noexcept {
return bytes_; }
46 if (offset >
size()) error_detail::raise<std::out_of_range>(
"word section offset");
47 if (count == std::dynamic_extent) count =
size() - offset;
48 if (count >
size() - offset) error_detail::raise<std::out_of_range>(
"word section length");
53 if (index >=
size()) error_detail::raise<std::out_of_range>(
"word section index");
55 std::memcpy(&value,
bytes_.data() + (index << 3), 8);
56 if constexpr (std::endian::native == std::endian::big) {
58 value = ((value & 0x00ff00ff00ff00ffull) << 8) | ((value >> 8) & 0x00ff00ff00ff00ffull);
59 value = ((value & 0x0000ffff0000ffffull) << 16) | ((value >> 16) & 0x0000ffff0000ffffull);
60 value = (value << 32) | (value >> 32);
68 static_assert(std::endian::native == std::endian::little || std::endian::native == std::endian::big,
69 "directory words require a byte-ordered host");
84 template <
class Sample>
explicit sample_view(std::span<Sample const> samples) noexcept
85 :
words_(std::as_bytes(samples), std::endian::native == std::endian::little) {
86 static_assert(std::is_standard_layout_v<Sample> && std::is_trivially_copyable_v<Sample>);
87 static_assert(std::is_same_v<
decltype(Sample::first), std::uint64_t> &&
88 std::is_same_v<
decltype(Sample::sparse), std::uint64_t>);
89 static_assert(
sizeof(Sample) == 16 && offsetof(Sample, first) == 0 && offsetof(Sample, sparse) == 8);
93 if (
bytes.size() & 15) error_detail::raise<std::invalid_argument>(
"sample section length is not a multiple of sixteen");
102 if (index >=
size()) error_detail::raise<std::out_of_range>(
"sample section index");
Outlines exceptional check failures while preserving their types and messages.
Definition active_engine.h:18
Definition word_view.h:75
std::uint64_t sparse
Definition word_view.h:77
std::uint64_t first
Definition word_view.h:76
Definition word_view.h:82
std::span< std::byte const > bytes() const noexcept
Definition word_view.h:100
sample_view(std::span< Sample const > samples) noexcept
Definition word_view.h:84
std::size_t size() const noexcept
Definition word_view.h:97
sample_view(word_view words) noexcept
Definition word_view.h:107
word_view words_
Definition word_view.h:108
bool empty() const noexcept
Definition word_view.h:98
static sample_view little_endian(std::span< std::byte const > bytes)
Definition word_view.h:92
sample_value operator[](std::size_t index) const
Definition word_view.h:101
word_view words() const noexcept
Definition word_view.h:99
Definition word_view.h:31
word_view subspan(std::size_t offset, std::size_t count=std::dynamic_extent) const
Definition word_view.h:45
bool empty() const noexcept
Definition word_view.h:42
static word_view little_endian(std::span< std::byte const > bytes)
Definition word_view.h:36
std::size_t size() const noexcept
Definition word_view.h:41
word_view(std::span< std::uint64_t const > words) noexcept
Definition word_view.h:33
word_view(std::span< std::byte const > bytes, bool little) noexcept
Definition word_view.h:70
std::uint64_t operator[](std::size_t index) const
Definition word_view.h:52
std::span< std::byte const > bytes() const noexcept
Definition word_view.h:43
bool is_little_endian() const noexcept
Definition word_view.h:44
bool little_
Definition word_view.h:72
std::span< std::byte const > bytes_
Definition word_view.h:71