byteme
C++ wrappers for buffered inputs
Loading...
Searching...
No Matches
byteme::PerByteInterface< Type_ > Class Template Referenceabstract

Interface for byte-by-byte extraction from a Reader source. More...

#include <PerByte.hpp>

Inheritance diagram for byteme::PerByteInterface< Type_ >:

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)
 

Protected Member Functions

virtual void refill ()=0
 

Protected Attributes

const Type_ * ptr = nullptr
 
std::size_t available = 0
 

Detailed Description

template<typename Type_>
class byteme::PerByteInterface< Type_ >

Interface for byte-by-byte extraction from a Reader source.

Template Parameters
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.

Member Function Documentation

◆ advance()

template<typename Type_ >
bool byteme::PerByteInterface< Type_ >::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_ >
std::pair< std::size_t, bool > byteme::PerByteInterface< Type_ >::extract ( std::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_ >
Type_ byteme::PerByteInterface< Type_ >::get ( ) const
inline
Returns
The current byte.

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

◆ position()

template<typename Type_ >
unsigned long long byteme::PerByteInterface< Type_ >::position ( ) const
inline
Returns
The position of the current byte since the start of the input.

◆ refill()

template<typename Type_ >
virtual void byteme::PerByteInterface< Type_ >::refill ( )
protectedpure virtual

Set ptr and available to refer to an array of new bytes from a Reader.

Implemented in byteme::PerByteParallel< Type_, Pointer_ >, and byteme::PerByteSerial< Type_, Pointer_ >.

◆ valid()

template<typename Type_ >
bool byteme::PerByteInterface< Type_ >::valid ( ) const
inline
Returns
Whether this instance still has bytes to be read.

Member Data Documentation

◆ available

template<typename Type_ >
std::size_t byteme::PerByteInterface< Type_ >::available = 0
protected

Length of the array at ptr.

◆ ptr

template<typename Type_ >
const Type_* byteme::PerByteInterface< Type_ >::ptr = nullptr
protected

Pointer to an array of bytes, to be set by refill() whenever available > 0.


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