36 return gptr() - eback();
41 return pptr() - pbase();
60 if (buffer_size > std::numeric_limits<int>::max())
61 throw std::overflow_error(
"Cannot convert a buffer size to int since this would cause an overflow in circularbuf::resize().");
62 pbump(ppos >= buffer_size ? buffer_size : ppos);
67 gpos >= buffer_size ?
buffer.data() + buffer_size :
buffer.data() + gpos,
73 return egptr() - eback();
79 if (!
psize() || c == traits_type::eof())
80 return traits_type::eof();
83 if (pptr() == epptr())
84 setp(pbase(), epptr());
101 return traits_type::eof();
104 if (gptr() == egptr())
105 setg(eback(), eback(), egptr());
107 return traits_type::to_int_type(*gptr());
115 return count ? count : -1;
124 return traits_type::eof();
127 if (gptr() == eback())
128 setg(eback(), egptr() - 1, egptr());
133 if (c != traits_type::eof())
136 return traits_type::to_int_type(*gptr());
149 circularbuf::pos_type
circularbuf::seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which)
151 bool in = which & std::ios_base::in;
152 bool out = which & std::ios_base::out;
153 pos_type new_pos(pos_type(off_type(-1)));
157 pos_type abs_pos_in = (dir == std::ios_base::end ? pos_type(
avail_get_count()) :
158 (dir == std::ios_base::cur ?
gtellp() : pos_type(0)));
170 new_pos =
seekpos(abs_pos_in, std::ios_base::in);
174 if (out && ((in && new_pos >= 0) || !in))
176 pos_type abs_pos_out = (dir == std::ios_base::end ? pos_type(
buffer.size()) :
177 (dir == std::ios_base::cur ?
ptellp() : pos_type(0)));
189 auto new_pos_out =
seekpos(abs_pos_out, std::ios_base::out);
190 if (new_pos_out < 0 || !in)
191 new_pos = new_pos_out;
195 return pos_type(off_type(-1));
204 if (which & std::ios_base::in)
209 setg(eback(), eback() + pos, egptr());
212 if (which & std::ios_base::out && !fail)
218 setp(pbase(), epptr());
223 return fail ? pos_type(off_type(-1)) : pos;
Implements a circular stream buffer derived from std::streambuf to be used with standard library stre...
virtual int_type overflow(int_type c=traits_type::eof()) override
Refer to documentation of std::streambuf.
virtual pos_type seekpos(pos_type pos, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out) override
Sets the position of the pointer(s) specified by which to the absolute position pos.
bool put_overflowed
Indicates wheter an overflow occurred writing to the buffer. If this was the case,...
circularbuf(size_t size)
Constructs a new circularbuf instance with a buffer of size size. The put area will span the entire b...
pos_type gtellp() const noexcept
Indicates the get pointer's position within the get area.
virtual pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out) override
Sets the position of the pointer(s) specified by which to the position pos relative to dir....
std::streamsize avail_get_count() const noexcept
Returns the amount of characters available to be read from the current get pointer position to the ge...
void resize(size_t size)
Resizes the size of buffer to size. The put area will span the entire buffer. If the buffer is enlarg...
size_t gsize()
Returns the size of the get area. Not const since sync() needs to be called to get correct size after...
void clear()
Resets the put areas to the entire area of buffer. The get area will be empty. The get and put pointe...
virtual int_type underflow() override
Refer to documentation of std::streambuf.
virtual int_type pbackfail(int_type c=traits_type::eof()) override
Refer to documentation of std::streambuf.
size_t psize() const noexcept
Returns the size of the put area.
pos_type to_pos_type(const T value)
Converts an unsigned, integral number type to pos_type.
bool empty()
Indicates whether characters can be read from the get area. Not const since sync() needs to be called...
virtual std::streamsize showmanyc() override
Refer to documentation of std::streambuf.
pos_type ptellp() const noexcept
Indicates the put pointer's position within the put area.
std::vector< CharT > buffer
The buffer itself.
virtual int sync() override
Expands the get area to the size of the put area. Resets put_overflowed.
DynExp's Util namespace contains commonly used functions and templates as well as extensions to Qt an...
Accumulates include statements to provide a precompiled header.