pflib v3.0.0-rc1-25-gb91774e
Pretty Fine HGCROC Interaction Library
|
Reading a raw data file. More...
#include <FileReader.h>
Public Member Functions | |
FileReader () | |
default constructor | |
void | open (const std::string &file_name) |
Open a file with this reader. | |
FileReader (const std::string &file_name) | |
Constructor that also opens the input file. | |
~FileReader ()=default | |
destructor, close the input file stream | |
void | seek (int off) override |
Go ("seek") a specific position in the file. | |
int | tell () override |
Tell us where the reader is. | |
Reader & | read (char *w, std::size_t count) override |
Read the next count bytes into pointer w. | |
bool | good () const override |
Check if reader is in a fail state. | |
bool | eof () override |
check if file is done | |
![]() | |
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> | |
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 | operator! () const |
Check if reader is in a fail state. | |
virtual | operator bool () const |
Check if reader is in good/bad state. | |
Private Attributes | |
std::ifstream | file_ |
file stream we are reading from | |
std::size_t | file_size_ |
file size in bytes | |
Reading a raw data file.
We wrap a basic std::ifstream in order to make the retrieving of specific-width words easier for ourselves. The abstract base Reader implements the templated complexities.
pflib::packing::FileReader::FileReader | ( | ) |
default constructor
We make sure that our input file stream will not skip white space.
pflib::packing::FileReader::FileReader | ( | const std::string & | file_name | ) |
Constructor that also opens the input file.
[in] | file_name | full path to the file we are going to open |
|
overridevirtual |
check if file is done
Just calls the underlying ifstream eof.
Implements pflib::packing::Reader.
|
overridevirtual |
Check if reader is in a fail state.
Following the C++ reference, we pass-along the check on if our ifstream is in a fail state.
Implements pflib::packing::Reader.
void pflib::packing::FileReader::open | ( | const std::string & | file_name | ) |
Open a file with this reader.
We open the file as an input, binary file.
[in] | file_name | full path to the file we are going to open |
|
overridevirtual |
Read the next count
bytes into pointer w.
[in] | w | pointer to array to write data into |
[in] | count | number of bytes to read |
Implements pflib::packing::Reader.
|
overridevirtual |
Go ("seek") a specific position in the file.
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 |
Implements pflib::packing::Reader.
|
overridevirtual |
Tell us where the reader is.
Implements pflib::packing::Reader.