-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.h
More file actions
39 lines (28 loc) · 845 Bytes
/
code.h
File metadata and controls
39 lines (28 loc) · 845 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
#pragma once
#include <cstddef>
#include <algorithm>
#include <stdexcept>
#include <cmath>
const unsigned char MAX_UCHAR = std::numeric_limits<unsigned char>::max();
class Code {
unsigned short bytes = 0;
public:
friend class CodeOutputStream;
static Code END_OF_FILE;
Code() = default;
explicit Code(unsigned short bytes) {
if (bytes > pow(2, 12) - 1) throw std::invalid_argument("Code value is out of bounds");
this->bytes = bytes;
};
Code &operator++();
bool operator==(const Code &other) const { return bytes == other.bytes; };
[[nodiscard]] unsigned short toShort() const { return bytes; };
};
namespace std {
template<>
struct hash<Code> {
size_t operator()(const Code &key) const {
return hash<unsigned short>()(key.toShort());
}
};
}