|
pflib v3.9.0-rc3-11-g2537d8f
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 () 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> | |
| 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 or done state. | |
| virtual | operator bool () const |
| Check if reader is in good state and is not done reading yet. | |
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.
|
mutableprivate |
file stream we are reading from
Needs to be mutable since tellg needs to be able to set the fail state of the file but we want to be able to check where we are in the const eof()