blob: 04839f67e1ef722ae584715ef8e53eb8686ec4de (
plain) (
blame)
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
|
#pragma once
#ifndef MARISA_GRIMOIRE_TRIE_HEADER_H_
#define MARISA_GRIMOIRE_TRIE_HEADER_H_
#include "../io.h"
namespace marisa {
namespace grimoire {
namespace trie {
class Header {
public:
enum {
HEADER_SIZE = 16
};
Header() {}
void map(Mapper &mapper) {
const char *ptr;
mapper.map(&ptr, HEADER_SIZE);
MARISA_THROW_IF(!test_header(ptr), MARISA_FORMAT_ERROR);
}
void read(Reader &reader) {
char buf[HEADER_SIZE];
reader.read(buf, HEADER_SIZE);
MARISA_THROW_IF(!test_header(buf), MARISA_FORMAT_ERROR);
}
void write(Writer &writer) const {
writer.write(get_header(), HEADER_SIZE);
}
std::size_t io_size() const {
return HEADER_SIZE;
}
private:
static const char *get_header() {
static const char buf[HEADER_SIZE] = "We love Marisa.";
return buf;
}
static bool test_header(const char *ptr) {
for (std::size_t i = 0; i < HEADER_SIZE; ++i) {
if (ptr[i] != get_header()[i]) {
return false;
}
}
return true;
}
// Disallows copy and assignment.
Header(const Header &);
Header &operator=(const Header &);
};
} // namespace trie
} // namespace marisa
} // namespace grimoire
#endif // MARISA_GRIMOIRE_TRIE_HEADER_H_
|