-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitReader.cpp
More file actions
40 lines (34 loc) · 753 Bytes
/
BitReader.cpp
File metadata and controls
40 lines (34 loc) · 753 Bytes
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
/**
* Created by Zakharov Sergey (aka Zakhse),
* Student of NRU HSE, the Faculty of Computer Science, Software Engineering
*
* 2k16, November
*/
#include "BitReader.h"
#include <bitset>
BitReader::BitReader(std::string path)
{
file = new std::ifstream;
file->open(path, std::ios_base::in);
buffer = "";
finished = false;
}
std::string BitReader::get_next(int size)
{
char ch;
while (buffer.length() < size && file->get(ch))
{
buffer += std::bitset<8>(ch).to_string();
}
std::string result = buffer.substr(0, size);
buffer = buffer.substr(size);
return result;
}
void BitReader::finish()
{
if (finished) return;
file->close();
buffer = "";
delete file;
finished = true;
}