-
Notifications
You must be signed in to change notification settings - Fork 0
/
BitStream.h
76 lines (65 loc) · 2.52 KB
/
BitStream.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//BitStream.h
/*
Class Description: Class responsible for reading 'bits' from a file and
writing 'bits', or a sequence of 'bits', to a file.
Class Invariants: -
Author: Jiacheng Xu & Carla Louw
Date: March 17, 2019
*/
#pragma once
#include <string>
#include <iostream>
#include <fstream>
#include "FrequencyCounter.h"
class BitStream
{
private:
char* buffer;
long int length;
char* outputBuffer;
long int lengthOfOutput;
int mode;
long int currentIndex;
char bitBuff;
int currentBit;
PriorityQueue* treeQueue;
HuffmansTree* mainTree;
FrequencyCounter counter;
public:
//Description: Default Constructor
BitStream();
//Description: Parameterized Constructor
BitStream(int inputMode);
//Description: Destructor (for dynamic allocation)
//Precondition: A BitStream object exists to be destructed
//Postcondition: BitStream object is deleted
~BitStream();
//Description: Reader File, takes in characters and reads the
// binary bit code associated with it.
//Postcondition: File is read into a buffer as the binary code.
bool loadFile(char* argv);
//Description: Takes in either (-c) or (-d) to for later specification of compression
// or decompression
void setMode(int inputMode);
//Description: Establishes the correct code in an 8-digit format, will move
// through all bytes present
void writeToBit(int bit);
//Description: Checks to see how many 0's are placed on the end of a byte (as placeholders)
// and places the necessary 0s since a byte must have 8 bits and the unspecified places are set to 0
//Postcondition: Byte is completed with the necessary number of zeros at the end
int checkBitTail();
//Description: Takes all the bytes created an joins them into one long string (for reading purposes)
//Postcondition: Bytes are joined into one string of bytes.
void setBitStream();
//Description: Takes to Huffman Trees and joins them into one,
// specifically joining tree2 onto tree1 (deep copy), then deleting tree2
//Precondition: There are trees to join
//Postcondition: Trees are joined into one and set as maintree.
void mergeHuffmansTrees();
//Description: Writes the data (bytes) to an external file
bool writeToFile(char* argv);
//Description: Takes in binary code and forms the appropriate tree from it
//Precondition: There is binary code to read from
//Postcondition: Appropriate tree is formed from the binary instructions
long int createTreeFromBinary();
};