-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_stream.h
More file actions
31 lines (25 loc) · 802 Bytes
/
file_stream.h
File metadata and controls
31 lines (25 loc) · 802 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
#ifndef __FILE_STREAM_H__
#define __FILE_STREAM_H__
#include <fstream>
#include <memory>
using namespace std;
class FileStream : fstream {
public:
FileStream(const char *path,
ios_base::openmode mode = ios_base::binary | ios_base::in)
: fstream(path, mode) {}
template <class Block>
auto loadBlock(Block &block, size_t offset = 0, size_t index = 0) {
seekg(offset + sizeof(block) * index, ios::beg);
read(reinterpret_cast<char *>(&block), sizeof(block));
return gcount();
}
template <class Block>
auto loadBlocks(Block *block, size_t offset, size_t num) {
seekg(offset, ios::beg);
read(reinterpret_cast<char *>(block), num * sizeof(*block));
return gcount();
}
auto loadBytes(size_t offset, size_t size) -> unique_ptr<char[]>;
};
#endif