UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
read_buffer.cpp
1
42// UFO
43#include <ufo/utility/io/read_buffer.hpp>
44
45// STL
46#include <algorithm>
47#include <cstring>
48
49namespace ufo
50{
51ReadBuffer::ReadBuffer(std::byte const* data, size_type count) : BaseBuffer(data, count)
52{
53}
54
55ReadBuffer& ReadBuffer::read(void* dest, size_type count)
56{
57 readAt(pos_, dest, count);
58 pos_ += count;
59 return *this;
60}
61
62ReadBuffer& ReadBuffer::read(std::ostream& out, size_type count)
63{
64 readAt(pos_, out, count);
65 pos_ += count;
66 return *this;
67}
68
69void ReadBuffer::readAt(pos_type pos, void* dest, size_type count) const
70{
71 if (size() < pos) [[unlikely]] {
72 // TODO: Fill in exception message
73 throw std::out_of_range("");
74 }
75
76 std::memmove(dest, data_ + pos, count);
77}
78
79void ReadBuffer::readAt(pos_type pos, std::ostream& out, size_type count) const
80{
81 if (size() < pos) [[unlikely]] {
82 // TODO: Fill in exception message
83 throw std::out_of_range("");
84 }
85
86 out.write(reinterpret_cast<char const*>(data_ + pos),
87 static_cast<std::streamsize>(count));
88}
89
90void ReadBuffer::readAt(offset_type off, IODir dir, void* dest, size_type count) const
91{
92 readAt(pos(pos_, off, dir), dest, count);
93}
94
95void ReadBuffer::readAt(offset_type off, IODir dir, std::ostream& out,
96 size_type count) const
97{
98 readAt(pos(pos_, off, dir), out, count);
99}
100
101bool ReadBuffer::readLine(std::string& line)
102{
103 // FIXME: Implement correct
104 std::byte const* it = std::find_if(data_ + pos_, data_ + size_, [](std::byte b) {
105 return '\n' == static_cast<char>(b);
106 });
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_;
111}
112
113ReadBuffer::pos_type ReadBuffer::readPos() const noexcept { return pos_; }
114
115ReadBuffer& ReadBuffer::readSeek(pos_type pos) noexcept
116{
117 pos_ = pos;
118 return *this;
119}
120
121ReadBuffer& ReadBuffer::readSeek(offset_type off, IODir dir) noexcept
122{
123 return readSeek(pos(pos_, off, dir));
124}
125
126ReadBuffer::size_type ReadBuffer::readLeft() const noexcept
127{
128 return size_ < pos_ ? 0 : pos_ - size_;
129}
130} // namespace ufo
All vision-related classes and functions.
Definition cloud.hpp:49
constexpr T b(Lab< T, Flags > color) noexcept
Returns the un-weighted blue–yellow axis value.
Definition lab.hpp:326