-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile.cpp
More file actions
159 lines (151 loc) · 2.84 KB
/
File.cpp
File metadata and controls
159 lines (151 loc) · 2.84 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include"File.h"
#include<string>
#include<QDebug>
#define MAX_SIZE_BUCKED 5;
File::File()
{
}
File::File(char FileName[])
{
for(int i=0; i<255; i++)
{
frequency[i]=0;
}
this->fileName=QString(FileName);
inputFile.open(FileName,std::ios::binary);
if(inputFile.is_open())
{
inputFile.seekg(0,inputFile.end);
size=inputFile.tellg();
inputFile.seekg(0, inputFile.beg);
}
this->position=0;
while(!this->isEnd())
{
this->grabBucked();
}
}
void File::grabBucked()
{
int read;
inputFile.seekg(this->position);
if(size-position>5)
{
this->position+=MAX_SIZE_BUCKED;
read=MAX_SIZE_BUCKED;
this->isEndBool=false;
}
else
{
read=size-position;
this->isEndBool=true;
}
fileCount(read);
}
int File::readFile(int initPosition)
{
QString file;
char buff;
inputFile.seekg(initPosition);
inputFile.get(buff);
if(buff<0)file.append(QString().setNum(buff+256));
else
file=(QString(QString().setNum((int)buff)));
return file.toInt();
}
QString File::readFile(int initPosition, int sizeRead)
{
QString file;
for(int i=initPosition;i<initPosition+sizeRead;i++)
{
file.append(readFile(i));
}
return file;
}
int File::fileSize()
{
return this->size;
}
void File::fileCount(int size)
{
char file[size];
inputFile.read(file,size);
for(int i=0; i<size; i++)
{
frequency[int(file[i])+128]++;
}
}
int File::bitFrequency(int Bit)
{
return frequency[Bit];
}
char File::bitToChar(int Bit)
{
return char(Bit-128);
}
int File::charToBit(char Char)
{
return int(Char+128);
}
void File::setFileName(QString fileName)
{
this->fileName=fileName;
}
QString File::getFileName()
{
return this->fileName.toLocal8Bit().data();
}
void File::clearPosition()
{
this->position=0;
this->isEndBool=false;
}
QString File::getfile()
{
int read;
inputFile.seekg(this->position);
if(size-position>5)
{
this->position+=MAX_SIZE_BUCKED;
read=MAX_SIZE_BUCKED;
this->isEndBool=false;
}
else
{
read=size-position;
this->isEndBool=true;
}
QString file;
char buff;
for(int i=0;i<read;i++)
{
inputFile.get(buff);
if(buff<0)
file.append(buff+256);
else
file.append(buff);
}
return file;
}
int File::getBucked()
{
return MAX_SIZE_BUCKED;
}
bool File::isEnd()
{
return this->isEndBool;
}
int* File::getFrequency()
{
return this->frequency;
}
void File::setPosition(int position)
{
this->position=position;
if(this->position==this->size)
{
this->isEndBool=true;
}
else
this->isEndBool=false;
}