pflib v3.9.0-rc3-11-g2537d8f
Pretty Fine HGCROC Interaction Library
Loading...
Searching...
No Matches
pflib::packing::BufferReader Class Reference

This class is a helper class for reading the buffer stored in the raw data format. More...

#include <BufferReader.h>

Inheritance diagram for pflib::packing::BufferReader:
[legend]
Collaboration diagram for pflib::packing::BufferReader:
[legend]

Public Member Functions

 BufferReader (const std::vector< uint8_t > &b)
 Initialize a reader by wrapping a buffer to read.
 
 ~BufferReader ()=default
 default destructor so handle to buffer is given up
 
void seek (int off) override
 go to the index off in bytes
 
int tell () override
 return where in the word we are in bytes
 
Readerread (char *w, std::size_t count) override
 read the next count bytes into array w and move the index
 
bool good () const override
 Return state of buffer.
 
bool eof () const override
 check if file is done
 
- Public Member Functions inherited from pflib::packing::Reader
 Reader ()=default
 default constructor
 
virtual ~Reader ()=default
 virtual destructor for inheritance
 
template<typename WordType , std::enable_if_t< std::is_integral< WordType >::value, bool > = true>
void seek (int off)
 Seek by number of words.
 
template<typename WordType >
int tell ()
 Tell by number of words.
 
template<typename WordType , std::enable_if_t< std::is_integral< WordType >::value, bool > = true>
Readerread (WordType *w, std::size_t count)
 Read the next 'count' words into the input handle.
 
template<typename WordType , std::enable_if_t< std::is_integral< WordType >::value, bool > = true>
Readeroperator>> (WordType &w)
 Stream the next word into the input handle.
 
template<typename ObjectType , std::enable_if_t< std::is_class< ObjectType >::value, bool > = true>
Readeroperator>> (ObjectType &o)
 Stream into a class object.
 
template<typename ContentType >
Readerread (std::vector< ContentType > &vec, std::size_t count, std::size_t offset=0)
 Read the next 'count' objects into the input vector.
 
virtual bool operator! () const
 Check if reader is in a fail or done state.
 
virtual operator bool () const
 Check if reader is in good state and is not done reading yet.
 

Private Attributes

const std::vector< uint8_t > & buffer_
 
std::size_t i_word_
 

Detailed Description

This class is a helper class for reading the buffer stored in the raw data format.

The raw data format specifies that the buffer for all data is a specific type (vector of bytes), but the users in different subsystems/translators may want the buffer to be read in different size words than single bytes. This class helps in that translation.

BufferReader r{data}; // data is some vector of bytes
r >> obj; // obj is some object with a Reader& read(Reader&) method
This class is a helper class for reading the buffer stored in the raw data format.
Definition BufferReader.h:27

Member Function Documentation

◆ eof()

bool pflib::packing::BufferReader::eof ( ) const
overridevirtual

check if file is done

Returns
true if we have reached the end of file.

Implements pflib::packing::Reader.

◆ good()

bool pflib::packing::BufferReader::good ( ) const
overridevirtual

Return state of buffer.

false if buffer is done being read, true otherwise.

Implements pflib::packing::Reader.

◆ read()

Reader & pflib::packing::BufferReader::read ( char * w,
std::size_t count )
overridevirtual

read the next count bytes into array w and move the index

Implements pflib::packing::Reader.

◆ seek()

void pflib::packing::BufferReader::seek ( int off)
overridevirtual

go to the index off in bytes

Implements pflib::packing::Reader.

◆ tell()

int pflib::packing::BufferReader::tell ( )
overridevirtual

return where in the word we are in bytes

Implements pflib::packing::Reader.


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