lab_huffman
Hazardous Huffman Codes
 All Classes Namespaces Files Functions Variables Pages
BinaryFileReader Class Reference

BinaryFileReader: interface for reading binary files, bit by bit or byte by byte. More...

#include <binary_file_reader.h>

Collaboration diagram for BinaryFileReader:
[legend]

Public Member Functions

 BinaryFileReader (const std::string &fileName)
 Constructs a new BinaryFileReader by opening the given file. More...
 
 ~BinaryFileReader ()
 Destroys a BinaryFileReader, ensuring the file is correctly closed. More...
 
bool getNextBit ()
 Reads the next bit of the file. More...
 
char getNextByte ()
 Reads the next byte of the file. More...
 
void reset ()
 Resets the file pointer to the beginning of the file. More...
 
void close ()
 Closes the given file. More...
 
bool hasBits () const
 Determines if there are more bits to be read in the file. More...
 
bool hasBytes () const
 Determines if there are more bytes to be read in the file. More...
 

Private Member Functions

bool needsNextByte () const
 Determines whether or not another byte needs read from the file. More...
 
void readNextByte ()
 Reads in a single byte from the file. More...
 

Private Attributes

std::ifstream file_
 std::ifstream used to read in the file. More...
 
char currentByte_
 The current byte to read bits from. More...
 
int currentBit_
 The current bit within the currentByte that is being read. More...
 
int maxBytes_
 The total number of bytes in the file. More...
 
int numRead_
 The number of bytes read from the file. More...
 
int paddingBits_
 The number of padding bits there are in the final byte. More...
 

Detailed Description

BinaryFileReader: interface for reading binary files, bit by bit or byte by byte.

Wraps an ifstream in binary mode.

Constructor & Destructor Documentation

BinaryFileReader::BinaryFileReader ( const std::string fileName)

Constructs a new BinaryFileReader by opening the given file.

Parameters
fileNameFile to be opened.
BinaryFileReader::~BinaryFileReader ( )

Destroys a BinaryFileReader, ensuring the file is correctly closed.

If the file is already closed, does nothing.

Member Function Documentation

void BinaryFileReader::close ( )

Closes the given file.

bool BinaryFileReader::getNextBit ( )

Reads the next bit of the file.

Should only be called when hasBits() is true.

Returns
The next bit of the file.
char BinaryFileReader::getNextByte ( )

Reads the next byte of the file.

Should only be called when hasBytes() is true.

Returns
The next byte of the file, as a char.
bool BinaryFileReader::hasBits ( ) const

Determines if there are more bits to be read in the file.

Returns
Whether or not there exists at least one more unread bit in the file.
bool BinaryFileReader::hasBytes ( ) const

Determines if there are more bytes to be read in the file.

Returns
Whether or not there exists at least one more unread byte in the file.
bool BinaryFileReader::needsNextByte ( ) const
private

Determines whether or not another byte needs read from the file.

Returns
Whether or not another byte must be read.
void BinaryFileReader::readNextByte ( )
private

Reads in a single byte from the file.

void BinaryFileReader::reset ( )

Resets the file pointer to the beginning of the file.

Member Data Documentation

int BinaryFileReader::currentBit_
private

The current bit within the currentByte that is being read.

char BinaryFileReader::currentByte_
private

The current byte to read bits from.

std::ifstream BinaryFileReader::file_
private

std::ifstream used to read in the file.

int BinaryFileReader::maxBytes_
private

The total number of bytes in the file.

int BinaryFileReader::numRead_
private

The number of bytes read from the file.

int BinaryFileReader::paddingBits_
private

The number of padding bits there are in the final byte.


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