pflib v3.0.0-rc1-29-g3a901ac
Pretty Fine HGCROC Interaction Library
|
Reading a raw data stream with some underlying backend. More...
#include <Reader.h>
Public Member Functions | |
Reader ()=default | |
default constructor | |
virtual | ~Reader ()=default |
virtual destructor for inheritance | |
virtual void | seek (int off)=0 |
Go ("seek") a specific position in the stream. | |
template<typename WordType , std::enable_if_t< std::is_integral< WordType >::value, bool > = true> | |
void | seek (int off) |
Seek by number of words. | |
virtual int | tell ()=0 |
Tell us where the reader is. | |
template<typename WordType > | |
int | tell () |
Tell by number of words. | |
virtual Reader & | read (char *w, std::size_t count)=0 |
Read the next 'count' bytes into the input handle w. | |
template<typename WordType , std::enable_if_t< std::is_integral< WordType >::value, bool > = true> | |
Reader & | read (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> | |
Reader & | operator>> (WordType &w) |
Stream the next word into the input handle. | |
template<typename ObjectType , std::enable_if_t< std::is_class< ObjectType >::value, bool > = true> | |
Reader & | operator>> (ObjectType &o) |
Stream into a class object. | |
template<typename ContentType > | |
Reader & | read (std::vector< ContentType > &vec, std::size_t count, std::size_t offset=0) |
Read the next 'count' objects into the input vector. | |
virtual bool | good () const =0 |
Check if reader is in a good state. | |
virtual bool | operator! () const |
Check if reader is in a fail state. | |
virtual | operator bool () const |
Check if reader is in good/bad state. | |
virtual bool | eof ()=0 |
check if file is done | |
Reading a raw data stream with some underlying backend.
This abstract base class assumes a derived class defines how to extract the next byte of data from some input data stream (e.g. either a in-memory buffer or a binary file). Then this interface has several templated methods that deduce how many bytes to extract and calls read
methods on objects that are not integral types.
|
default |
default constructor
We make sure that our input file stream will not skip white space.
|
pure virtual |
check if file is done
Implemented in pflib::packing::FileReader.
|
pure virtual |
Check if reader is in a good state.
Implemented in pflib::packing::BufferReader, and pflib::packing::FileReader.
|
inlinevirtual |
|
inlinevirtual |
Check if reader is in a fail state.
|
inline |
Stream into a class object.
We assume that the class we are streaming to has a specific method defined.
Reader& read(Reader&)
This can be satisfied by the classes that we own and operate.
in] ObjectType class type to read
[in] | o | instance of object to read into |
|
inline |
Stream the next word into the input handle.
This implementation of the stream operator is only available to handles of integral types. Helps for shorthand of only grabbing a single word from the reader.
in] WordType integral-type word to read out
[in] | w | reference to word to read into |
|
pure virtual |
Read the next 'count' bytes into the input handle w.
[in] | w | pointer to array to write data into |
[in] | count | number of bytes to read |
Implemented in pflib::packing::BufferReader, and pflib::packing::FileReader.
|
inline |
Read the next 'count' objects into the input vector.
This is common enough, I wanted to specialize the read function.
The std::vector::resize is helpful for avoiding additional copies while the vector is being expanded. After allocating the space for each entry in the vector, we call the stream operator from *this into each entry in order, leaving early if a failure occurs.
in] ContentType type of object inside the vector
[in] | vec | object vector to read into |
[in] | count | number of objects to read |
|
inline |
Read the next 'count' words into the input handle.
This implementation of read is only available to pointers to integral types. We assume that whatever space pointed to by w already has the space reserved necessary for the input words.
in] WordType integral-type word to read out
[in] | w | pointer to WordType array to write data to |
[in] | count | number of words to read |
|
inline |
Seek by number of words.
This template version of seek uses the input word type to move around by the count of the input words rather than the count of bytes.
in] WordType Integral-type to count by
[in] | off | number of words to move relative to dir |
[in] | dir | location flag for the file, default is beginning |
|
pure virtual |
Go ("seek") a specific position in the stream.
This non-template version of seek uses the default meaning of the "off" parameter in which it counts bytes.
[in] | off | number of bytes to move relative to dir |
[in] | dir | location flag for the file, default is beginning |
Implemented in pflib::packing::BufferReader, and pflib::packing::FileReader.
|
inline |
Tell by number of words.
|
pure virtual |
Tell us where the reader is.
Implemented in pflib::packing::BufferReader, and pflib::packing::FileReader.