-
Notifications
You must be signed in to change notification settings - Fork 0
/
DecompressionManager.h
65 lines (54 loc) · 1.55 KB
/
DecompressionManager.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
/*
* File: DecompressionManager.h
* Author: Anas
*
* Created on December 30, 2012, 2:30 AM
*/
#ifndef DECOMPRESSIONMANAGER_H
#define DECOMPRESSIONMANAGER_H
#include <string>
#include <iostream>
#include <fstream>
#include "HuffmanTree.h"
using namespace std;
class DecompressionManager {
private:
int machineBits;
int biggestInteger;
ifstream inputFile;
ofstream outputFile;
protected:
int getLeftMostBit(int number);
public:
DecompressionManager(string ifile, string ofile, HuffmanTree * huffmanTree);
~DecompressionManager();
};
DecompressionManager::DecompressionManager(string ifile, string ofile, HuffmanTree * huffmanTree) {
machineBits = sizeof ( int) * 8;
biggestInteger = 1;
biggestInteger = biggestInteger << (machineBits - 1);
inputFile.open( ifile.c_str() );
outputFile.open( ofile.c_str() );
int number;
int bit;
char c;
while ( inputFile >> number ) {
for ( int i=0; i<machineBits; i++ ) {
bit = getLeftMostBit( number );
// cout << "got " << bit << endl;
c = huffmanTree->moveDecodingPointer( bit );
if ( c != '\0') {
outputFile << c;
}
number = number << 1;
}
}
}
DecompressionManager::~DecompressionManager() {
inputFile.close();
outputFile.close();
}
int DecompressionManager::getLeftMostBit(int number) {
return ( ((number & biggestInteger) == 0) ? 0 : 1);
}
#endif /* DECOMPRESSIONMANAGER_H */