DynExp
Highly flexible laboratory automation for dynamically changing experiments.
|
Circular stream buffer to be used with the standard library's stream classes. Reading from or writing behind the buffer's end continues at the buffer's beginning. More...
Public Types | |
using | CharT = char |
Data type of a single character stored in the buffer. More... | |
Public Member Functions | |
circularbuf (size_t size) | |
Constructs a new circularbuf instance with a buffer of size size . The put area will span the entire buffer, the get area will be empty. More... | |
bool | empty () |
Indicates whether characters can be read from the get area. Not const since sync() needs to be called to get correct size after a character has been written recently. More... | |
size_t | gsize () |
Returns the size of the get area. Not const since sync() needs to be called to get correct size after a character has been written recently. More... | |
size_t | psize () const noexcept |
Returns the size of the put area. More... | |
pos_type | gtellp () const noexcept |
Indicates the get pointer's position within the get area. More... | |
pos_type | ptellp () const noexcept |
Indicates the put pointer's position within the put area. More... | |
void | clear () |
Resets the put areas to the entire area of buffer. The get area will be empty. The get and put pointers will point to the beginning of their respective areas. Resets put_overflowed. More... | |
void | resize (size_t size) |
Resizes the size of buffer to size . The put area will span the entire buffer. If the buffer is enlarged, the get area will maintain its size. If the buffer is shrunk, the get area will span the entire buffer. If the original put (get) pointer falls behind the new put (get) area's length, it is set to the put (get) area's end, otherwise it will maintain its old position. More... | |
Private Member Functions | |
std::streamsize | avail_get_count () const noexcept |
Returns the amount of characters available to be read from the current get pointer position to the get area's end. More... | |
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 . Takes the stream's circularity into account. More... | |
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 . More... | |
template<typename T , std::enable_if_t< std::is_unsigned_v< T >, int > = 0> | |
pos_type | to_pos_type (const T value) |
Converts an unsigned, integral number type to pos_type . More... | |
Overridden | |
Overridden from standard library. Refer to documentation of | |
virtual int_type | overflow (int_type c=traits_type::eof()) override |
Refer to documentation of std::streambuf . More... | |
virtual int_type | underflow () override |
Refer to documentation of std::streambuf . More... | |
virtual std::streamsize | showmanyc () override |
Refer to documentation of std::streambuf . More... | |
virtual int_type | pbackfail (int_type c=traits_type::eof()) override |
Refer to documentation of std::streambuf . More... | |
virtual int | sync () override |
Expands the get area to the size of the put area. Resets put_overflowed. More... | |
Private Attributes | |
std::vector< CharT > | buffer |
The buffer itself. More... | |
bool | put_overflowed |
Indicates wheter an overflow occurred writing to the buffer. If this was the case, subsequent calls to sync() have to enlarge the get area to the put area's size regardless of the current put pointer's position. More... | |
Circular stream buffer to be used with the standard library's stream classes. Reading from or writing behind the buffer's end continues at the buffer's beginning.
Definition at line 19 of file circularbuf.h.
using Util::circularbuf::CharT = char |
Data type of a single character stored in the buffer.
Definition at line 25 of file circularbuf.h.
Util::circularbuf::circularbuf | ( | size_t | size | ) |
Constructs a new circularbuf
instance with a buffer of size size
. The put area will span the entire buffer, the get area will be empty.
size | Initial buffer size |
Definition at line 8 of file circularbuf.cpp.
|
privatenoexcept |
Returns the amount of characters available to be read from the current get pointer position to the get area's end.
Definition at line 71 of file circularbuf.cpp.
void Util::circularbuf::clear | ( | ) |
Resets the put areas to the entire area of buffer. The get area will be empty. The get and put pointers will point to the beginning of their respective areas. Resets put_overflowed.
Definition at line 44 of file circularbuf.cpp.
bool Util::circularbuf::empty | ( | ) |
Indicates whether characters can be read from the get area. Not const since sync()
needs to be called to get correct size after a character has been written recently.
avail_get_count()
returns 0, false otherwise. Definition at line 15 of file circularbuf.cpp.
size_t Util::circularbuf::gsize | ( | ) |
Returns the size of the get area. Not const since sync()
needs to be called to get correct size after a character has been written recently.
Definition at line 22 of file circularbuf.cpp.
|
noexcept |
Indicates the get pointer's position within the get area.
Definition at line 34 of file circularbuf.cpp.
|
overrideprivatevirtual |
Refer to documentation of std::streambuf
.
Definition at line 76 of file circularbuf.cpp.
|
overrideprivatevirtual |
Refer to documentation of std::streambuf
.
Definition at line 118 of file circularbuf.cpp.
|
noexcept |
Returns the size of the put area.
Definition at line 29 of file circularbuf.cpp.
|
noexcept |
Indicates the put pointer's position within the put area.
Definition at line 39 of file circularbuf.cpp.
void Util::circularbuf::resize | ( | size_t | size | ) |
Resizes the size of buffer to size
. The put area will span the entire buffer. If the buffer is enlarged, the get area will maintain its size. If the buffer is shrunk, the get area will span the entire buffer. If the original put (get) pointer falls behind the new put (get) area's length, it is set to the put (get) area's end, otherwise it will maintain its old position.
size | New buffer size to apply |
std::overflow_error | is thrown if size does not fit into int . |
Definition at line 52 of file circularbuf.cpp.
|
overrideprivatevirtual |
Sets the position of the pointer(s) specified by which
to the position pos
relative to dir
. Takes the stream's circularity into account.
off | Destiny position (relative to dir ). |
dir | Set position relative to stream's beginning (std::ios_base::beg ), its end (std::ios_base::end ) or the current position (std::ios_base::cur ). |
which | Combination of flags std::ios_base::in and std::ios_base::out specifying get or put pointers. |
pos
in case of success, -1 otherwise. If the get and the put pointers are both successfully moved, the new position of the get pointer is returned. Definition at line 149 of file circularbuf.cpp.
|
overrideprivatevirtual |
Sets the position of the pointer(s) specified by which
to the absolute position pos
.
pos | Destiny position (absolute). |
which | Combination of flags std::ios_base::in and std::ios_base::out specifying get or put pointers. |
pos
in case of success, -1 otherwise. Definition at line 200 of file circularbuf.cpp.
|
overrideprivatevirtual |
Refer to documentation of std::streambuf
.
Definition at line 110 of file circularbuf.cpp.
|
overrideprivatevirtual |
Expands the get area to the size of the put area. Resets put_overflowed.
Definition at line 139 of file circularbuf.cpp.
|
inlineprivate |
Converts an unsigned, integral number type to pos_type
.
T | Type to convert from |
value | Value to convert |
std::overflow_error | is thrown if value is larger than the maximal number storable in pos_type . |
Definition at line 143 of file circularbuf.h.
|
overrideprivatevirtual |
Refer to documentation of std::streambuf
.
Definition at line 95 of file circularbuf.cpp.
|
private |
The buffer itself.
Definition at line 154 of file circularbuf.h.
|
private |
Indicates wheter an overflow occurred writing to the buffer. If this was the case, subsequent calls to sync()
have to enlarge the get area to the put area's size regardless of the current put pointer's position.
Definition at line 161 of file circularbuf.h.