-
Notifications
You must be signed in to change notification settings - Fork 0
/
bofstream.cpp
64 lines (53 loc) · 913 Bytes
/
bofstream.cpp
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
#include "bofstream.h"
bofstream::bofstream()
{
buffer = 0x00;
bitPosition = 7;
}
bofstream::~bofstream()
{
file.close();
}
void bofstream::open(const char *filePath)
{
file.open(filePath, std::ios_base::out | std::ios_base::binary);
}
void bofstream::close()
{
if (bitPosition != 7)
flushBufferToFile();
}
bool bofstream::good()
{
return file.good();
}
bool bofstream::fail()
{
return file.fail();
}
bool bofstream::eof()
{
return file.eof();
}
void bofstream::clear()
{
file.clear();
}
void bofstream::flushBufferToFile()
{
file.put(buffer);
buffer = 0x00;
bitPosition = 7;
}
void bofstream::put(bool bit)
{
buffer |= (bit << bitPosition);
bitPosition--;
if (bitPosition < 0)
flushBufferToFile();
}
void bofstream::put(std::vector<bool> bitset)
{
for (auto i = bitset.begin(); i != bitset.end(); i++)
put(*i);
}