forked from loveyacper/ananas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMmapFile.h
53 lines (38 loc) · 952 Bytes
/
MmapFile.h
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
#ifndef BERT_MMAPFILE_H
#define BERT_MMAPFILE_H
#include <string>
namespace ananas {
namespace internal {
class OMmapFile {
public:
OMmapFile();
~OMmapFile();
bool Open(const std::string& file, bool bAppend = true);
bool Open(const char* file, bool bAppend = true);
void Close();
bool Sync();
void Truncate(std::size_t size);
void Write(const void* data, std::size_t len);
template <typename T>
void Write(const T& t);
std::size_t Offset() const {
return offset_;
}
bool IsOpen() const;
private:
bool _MapWriteOnly();
void _ExtendFileSize(std::size_t size);
void _AssureSpace(std::size_t size);
int file_;
char* memory_;
std::size_t offset_;
std::size_t size_;
std::size_t syncPos_;
};
template <typename T>
inline void OMmapFile::Write(const T& t) {
this->Write(&t, sizeof t);
}
} // end namespace internal
} // end namespace ananas
#endif