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:
[legend]

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.

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

◆ close()

void BinaryFileWriter::close ( )

Closes the given file.

◆ 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.

◆ writeCurrentByte()

void BinaryFileWriter::writeCurrentByte ( )
private

Writes the current byte to the file.

Member Data Documentation

◆ currentBit_

int BinaryFileWriter::currentBit_
private

The current bit within the currentByte that is being written.

◆ currentByte_

char BinaryFileWriter::currentByte_
private

The current byte to write bits into.

◆ file_

std::ofstream BinaryFileWriter::file_
private

std::ofstream used to write to the file.


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