pflib v3.0.0-rc1-25-gb91774e
Pretty Fine HGCROC Interaction Library
All Classes Namespaces Files Functions Variables Typedefs Pages
pflib::packing::FileReader Class Reference

Reading a raw data file. More...

#include <FileReader.h>

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

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.
 
Readerread (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
 
- 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 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
 

Detailed Description

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.

FileReader r{"file.raw"};
r >> obj; // obj is some object with a Reader& read(Reader&) method
Reading a raw data file.
Definition FileReader.h:25

Constructor & Destructor Documentation

◆ FileReader() [1/2]

pflib::packing::FileReader::FileReader ( )

default constructor

We make sure that our input file stream will not skip white space.

◆ FileReader() [2/2]

pflib::packing::FileReader::FileReader ( const std::string & file_name)

Constructor that also opens the input file.

See also
open
Parameters
[in]file_namefull path to the file we are going to open

Member Function Documentation

◆ eof()

bool pflib::packing::FileReader::eof ( )
overridevirtual

check if file is done

Just calls the underlying ifstream eof.

Returns
true if we have reached the end of file.

Implements pflib::packing::Reader.

◆ good()

bool pflib::packing::FileReader::good ( ) const
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.

Returns
bool true if ifstream is in fail state

Implements pflib::packing::Reader.

◆ open()

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.

Parameters
[in]file_namefull path to the file we are going to open

◆ read()

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

Read the next count bytes into pointer w.

Parameters
[in]wpointer to array to write data into
[in]countnumber of bytes to read
Returns
(*this)

Implements pflib::packing::Reader.

◆ seek()

void pflib::packing::FileReader::seek ( int off)
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.

Parameters
[in]offnumber of bytes to move relative to dir
[in]dirlocation flag for the file, default is beginning

Implements pflib::packing::Reader.

◆ tell()

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

Tell us where the reader is.

Returns
int number of bytes relative to beginning of file

Implements pflib::packing::Reader.


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