-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialize.cpp
More file actions
54 lines (44 loc) · 1.02 KB
/
Serialize.cpp
File metadata and controls
54 lines (44 loc) · 1.02 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
#include "Serialize.h"
// roughly adapted from https://stackoverflow.com/questions/20511347/a-good-hash-function-for-a-vector
std::size_t HashVec(std::vector<uint16_t> const& vec)
{
std::size_t seed = vec.size();
for (auto& i : vec) {
seed ^= i + 0x9e37 + (seed << 6) + (seed >> 2);
}
return seed;
}
FastFileStream::FastFileStream(std::string filename)
: fileStream(filename, std::ios::binary), position(0)
{
}
FastFileStream::FastFileStream()
: fileStream(), position(-1)
{
}
void FastFileStream::Seek(size_t newPosition)
{
if (position != newPosition)
{
// TODO late bind?
fileStream.seekg(newPosition);
position = newPosition;
}
}
size_t FastFileStream::GetPosition() const
{
return position;
}
void FastFileStream::Read(void* dest, size_t length)
{
fileStream.read(reinterpret_cast<uint8_t*>(dest), length);
position += length;
}
void FastFileStream::Close()
{
fileStream.close();
}
bool FastFileStream::Failed()
{
return fileStream.fail();
}