43#include <ufo/utility/io/read_buffer.hpp>
51ReadBuffer::ReadBuffer(std::byte
const* data, size_type count) : BaseBuffer(data, count)
55ReadBuffer& ReadBuffer::read(
void* dest, size_type count)
57 readAt(pos_, dest, count);
62ReadBuffer& ReadBuffer::read(std::ostream& out, size_type count)
64 readAt(pos_, out, count);
69void ReadBuffer::readAt(pos_type pos,
void* dest, size_type count)
const
71 if (size() < pos) [[unlikely]] {
73 throw std::out_of_range(
"");
76 std::memmove(dest, data_ + pos, count);
79void ReadBuffer::readAt(pos_type pos, std::ostream& out, size_type count)
const
81 if (size() < pos) [[unlikely]] {
83 throw std::out_of_range(
"");
86 out.write(
reinterpret_cast<char const*
>(data_ + pos),
87 static_cast<std::streamsize
>(count));
90void ReadBuffer::readAt(offset_type off, IODir dir,
void* dest, size_type count)
const
92 readAt(pos(pos_, off, dir), dest, count);
95void ReadBuffer::readAt(offset_type off, IODir dir, std::ostream& out,
96 size_type count)
const
98 readAt(pos(pos_, off, dir), out, count);
101bool ReadBuffer::readLine(std::string& line)
104 std::byte
const* it = std::find_if(data_ + pos_, data_ + size_, [](std::byte b) {
105 return '\n' ==
static_cast<char>(
b);
107 line.assign(
reinterpret_cast<char const*
>(data_ + pos_),
108 reinterpret_cast<char const*
>(it));
109 pos_ = std::min(size_, pos_ + line.size() + 1);
110 return pos_ != size_;
113ReadBuffer::pos_type ReadBuffer::readPos() const noexcept {
return pos_; }
115ReadBuffer& ReadBuffer::readSeek(pos_type pos)
noexcept
121ReadBuffer& ReadBuffer::readSeek(offset_type off, IODir dir)
noexcept
123 return readSeek(pos(pos_, off, dir));
126ReadBuffer::size_type ReadBuffer::readLeft() const noexcept
128 return size_ < pos_ ? 0 : pos_ - size_;
All vision-related classes and functions.
constexpr T b(Lab< T, Flags > color) noexcept
Returns the un-weighted blue–yellow axis value.