byteme
C++ wrappers for buffered inputs
|
Interface for byte-by-byte extraction from a Reader
source.
More...
#include <PerByte.hpp>
Public Member Functions | |
bool | advance () |
Type_ | get () const |
unsigned long long | position () const |
bool | valid () const |
std::pair< std::size_t, bool > | extract (std::size_t number, Type_ *output) |
std::size_t | advance_and_extract (std::size_t number, Type_ *output) |
Protected Member Functions | |
virtual void | refill ()=0 |
Protected Attributes | |
const Type_ * | ptr = nullptr |
std::size_t | available = 0 |
Interface for byte-by-byte extraction from a Reader
source.
Type_ | Type of the output bytes, usually char for text or unsigned char for binary. |
This wraps a Reader
so that developers can avoid the boilerplate of managing blocks of bytes, when all they want is to iterate over the bytes of the input.
|
inline |
|
inline |
Advance to the next byte, extract up to number
bytes from the Reader
source and store them in the output
. This is equivalent to (but more efficient than) calling advance()
and then get()
up to number
times, only iterating while the return value of advance()
is still true. Users should only call this method if valid()
returns true
. Note the distinction between this method and extract()
, as the latter calls get()
before advance()
.
number | Number of bytes to extract. | |
[out] | output | Pointer to an output buffer of length number . This is filled with up to number bytes from the source. |
output
. The first element is less than number
if and only if no more bytes are available in the source, i.e., valid()
returns false
. (This can also be interpreted as the last call to advance()
returning false
in a hypothetical iterative implementation.)
|
inline |
Extract up to number
bytes from the Reader
source and store them in the output
. This is equivalent to (but more efficient than) calling get()
and then advance()
up to number
times, only iterating while the return value of advance()
is still true. Users should only call this method if no previous call to advance()
has returned false
- or equivalently, no previous call to extract()
has false
in the second element of its return value.
number | Number of bytes to extract. | |
[out] | output | Pointer to an output buffer of length number . This is filled with up to number bytes from the source. |
output
, and (2) whether there are any more bytes available in the source for future get()
or extract()
calls. The first value can be interpreted as the number of successful get()
/advance()
iterations, while the second value can be interpreted as the result of the final advance()
. If the first element is less than number
, it can be assumed that no more bytes are available in the source (i.e., the second element must be false). Note that the converse is not true as it is possible to read number
bytes and finish the source at the same time.
|
inline |
This should only be called if valid()
is true
.
|
inline |
|
protectedpure virtual |
Set ptr
and available
to refer to an array of new bytes from a Reader
. Implementations may assume that Reader::load()
has not previously returned false
.
Implemented in byteme::PerByteParallel< Type_, Pointer_ >, and byteme::PerByteSerial< Type_, Pointer_ >.
|
inline |
|
protected |
Length of the array at ptr
.
|
protected |
Pointer to an array of bytes, to be set by refill()
whenever available > 0
.