lab_huffman
Hazardous Huffman Codes
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:

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.

Author
Chase Geigle
Date
Summer 2012

Constructor & Destructor Documentation

◆ BinaryFileReader()

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

Constructs a new BinaryFileReader by opening the given file.

Parameters
fileNameFile to be opened.

◆ ~BinaryFileReader()

BinaryFileReader::~BinaryFileReader ( )

Destroys a BinaryFileReader, ensuring the file is correctly closed.

If the file is already closed, does nothing.

Member Function Documentation

◆ getNextBit()

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.

◆ getNextByte()

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.

◆ reset()

void BinaryFileReader::reset ( )

Resets the file pointer to the beginning of the file.

◆ close()

void BinaryFileReader::close ( )

Closes the given file.

◆ hasBits()

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.

◆ hasBytes()

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.

◆ needsNextByte()

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.

◆ readNextByte()

void BinaryFileReader::readNextByte ( )
private

Reads in a single byte from the file.

Member Data Documentation

◆ file

std::ifstream BinaryFileReader::file
private

std::ifstream used to read in the file.

◆ currentByte

char BinaryFileReader::currentByte
private

The current byte to read bits from.

◆ currentBit

int BinaryFileReader::currentBit
private

The current bit within the currentByte that is being read.

◆ maxBytes

int BinaryFileReader::maxBytes
private

The total number of bytes in the file.

◆ numRead

int BinaryFileReader::numRead
private

The number of bytes read from the file.

◆ paddingBits

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: