byteme
C++ wrappers for buffered inputs
Loading...
Searching...
No Matches
byteme::PerByte< Type_, Pointer_ > Class Template Reference

Perform byte-by-byte extraction from a Reader source. More...

#include <PerByte.hpp>

Public Member Functions

 PerByte (Pointer_ reader)
 
bool valid () const
 
bool advance ()
 
Type_ get () const
 
size_t position () const
 
std::pair< size_t, bool > extract (size_t number, Type_ *output)
 

Detailed Description

template<typename Type_ = char, class Pointer_ = Reader*>
class byteme::PerByte< Type_, Pointer_ >

Perform byte-by-byte extraction from a Reader source.

Template Parameters
Type_Character type to return, usually char for text or unsigned char for binary.
Pointer_A (possibly smart) non-const pointer to a Reader.

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.

Constructor & Destructor Documentation

◆ PerByte()

template<typename Type_ = char, class Pointer_ = Reader*>
byteme::PerByte< Type_, Pointer_ >::PerByte ( Pointer_ reader)
inline
Parameters
readerA (possibly smart) pointer to a Reader object.

Member Function Documentation

◆ advance()

template<typename Type_ = char, class Pointer_ = Reader*>
bool byteme::PerByte< Type_, Pointer_ >::advance ( )
inline

Advance to the next byte, possibly reading a new chunk from the supplied Reader. This should only be called if valid() is true.

Returns
Whether this instance still has bytes to be read, i.e., the output of valid() after advancing to the next byte.

◆ extract()

template<typename Type_ = char, class Pointer_ = Reader*>
std::pair< size_t, bool > byteme::PerByte< Type_, Pointer_ >::extract ( size_t number,
Type_ * output )
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. The number of successful iterations is returned in the output as the first pair element, while the return value of the final advance() is returned as the second pair element.

Parameters
numberNumber of bytes to extract.
[out]outputPointer to an output buffer of length number. This is filled with up to number bytes from the source.
Returns
Pair containing (1) the number of bytes that were successfully read into output, and (2) whether there are any more bytes available in the source for future get() or extract() calls.

◆ get()

template<typename Type_ = char, class Pointer_ = Reader*>
Type_ byteme::PerByte< Type_, Pointer_ >::get ( ) const
inline
Returns
The current byte.

This should only be called if valid() is true.

◆ position()

template<typename Type_ = char, class Pointer_ = Reader*>
size_t byteme::PerByte< Type_, Pointer_ >::position ( ) const
inline
Returns
The position of the current byte since the start of the input.

◆ valid()

template<typename Type_ = char, class Pointer_ = Reader*>
bool byteme::PerByte< Type_, Pointer_ >::valid ( ) const
inline
Returns
Whether this instance still has bytes to be read.

The documentation for this class was generated from the following file: