lab_huffman
Hazardous Huffman Codes
BinaryFileWriter Class Reference

BinaryFileWriter: interface for writing to binary files, bit by bit or byte by byte. More...

#include "binary_file_writer.h"

+ Collaboration diagram for BinaryFileWriter:

Public Member Functions

 BinaryFileWriter (const std::string &fileName)
 Constructs a new BinaryFileWriter by opening the given filename. More...
 
 ~BinaryFileWriter ()
 Destroys an BinaryFileWriter: the destructor here ensures that all remaining bits are written to the file before closing the file. More...
 
void writeBit (bool bit)
 Writes the next bit of the file. More...
 
void writeByte (char byte)
 Writes the next byte to the file. More...
 
void close ()
 Closes the given file. More...
 

Private Member Functions

void writeCurrentByte ()
 Writes the current byte to the file. More...
 

Private Attributes

std::ofstream file
 std::ofstream used to write to the file. More...
 
char currentByte
 The current byte to write bits into. More...
 
int currentBit
 the current bit within the currentByte that is being written. More...
 

Detailed Description

BinaryFileWriter: interface for writing to binary files, bit by bit or byte by byte.

Wraps an ofstream in binary mode.

Author
Chase Geigle
Date
Sumer 2012

Constructor & Destructor Documentation

◆ BinaryFileWriter()

BinaryFileWriter::BinaryFileWriter ( const std::string fileName)

Constructs a new BinaryFileWriter by opening the given filename.

Parameters
fileNameFile to be opened.

◆ ~BinaryFileWriter()

BinaryFileWriter::~BinaryFileWriter ( )

Destroys an BinaryFileWriter: the destructor here ensures that all remaining bits are written to the file before closing the file.

If the file was already closed, nothing is done.

Member Function Documentation

◆ writeBit()

void BinaryFileWriter::writeBit ( bool  bit)

Writes the next bit of the file.

Parameters
bitThe bit to be written.

◆ writeByte()

void BinaryFileWriter::writeByte ( char  byte)

Writes the next byte to the file.

Parameters
byteThe byte to be written.

◆ close()

void BinaryFileWriter::close ( )

Closes the given file.

◆ writeCurrentByte()

void BinaryFileWriter::writeCurrentByte ( )
private

Writes the current byte to the file.

Member Data Documentation

◆ file

std::ofstream BinaryFileWriter::file
private

std::ofstream used to write to the file.

◆ currentByte

char BinaryFileWriter::currentByte
private

The current byte to write bits into.

◆ currentBit

int BinaryFileWriter::currentBit
private

the current bit within the currentByte that is being written.


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