-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.h
97 lines (94 loc) · 2.54 KB
/
source.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* @file
* Defines the structure of the Source class.
*/
#ifndef _SOURCE_H_
#define _SOURCE_H_
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <list>
#include <vector>
#include <queue>
#include <string>
#include "symbol.h"
#include "binarizer.h"
/**
* The source class is the main class of the program.
*
* We will use one Source class in the main program
* in order to do the operations we want.
*
* Taking a look to the different main.cpp files for
* the different modules will help us to understand
* how to use this methods for codifying and decodifying.
*/
class Source
{
/**
* The "symbolCounter" structure will help us
* to count the symbols in the file, so we can
* extract later the probabilities for that symbol.
*/
std::map <char, unsigned int> symbolCounter;
/**
* The "codificationTable" is a table that relates
* the label of a symbol to the string of 0s and 1s
* (binary code) corresponding to that label.
*
* It is used in the codification of a file.
*/
std::map <char, std::string> codificationTable;
/**
* The "decodificationTable" is a table that relates
* the string of 0s and 1s (binary code) with the label
* of a symbol.
*
* It is used in the decodification of a file.
*/
std::map <std::string, char> decodificationTable;
/**
* The "symbolList" list will store the simple
* symbols of the process, this is, the objects
* of the class Symbol (not the ones from the
* CombinedSymbol class) created after counting
* frequencies or reading a serial from file.
*/
std::list <Symbol*> symbolList;
/**
* The "rootSymbol" is a pointer to the object
* that is in the root of the binary tree.
*
* This way we can trigger the serializing methods
* easily.
*/
Symbol* rootSymbol;
/**
* A counter for the number of symbols read in the
* input file.
*/
unsigned int totalSymbols;
/**
* The serial for the describing the binary tree.
* It is a binary code which can be composed in two
* different ways: by looking at the binary tree or
* by reading it from a file.
*/
std::string serial;
public:
void getFrequencies(FILE *input);
void getProbabilities();
void getProperties(FILE *input);
std::string getSerial();
void solveHuffman();
void serializeTree();
void unserializeTree(FILE *input);
void writeCodifiedFile(char* inputFileName);
void writeUncodifiedFile(FILE *input, char* outputFileName);
void buildSymbolList();
void buildCodeList();
bool stringInCodeList(std::string binaryString);
void showProperties();
};
#endif