forked from szatmary/PlotFS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotfactory.hpp
More file actions
43 lines (38 loc) · 1016 Bytes
/
Copy pathplotfactory.hpp
File metadata and controls
43 lines (38 loc) · 1016 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
40
41
42
43
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include <fcntl.h>
#include <unistd.h>
#include "plot.hpp"
class PlotFactory {
public:
virtual std::shared_ptr<PlotFile> openPlot(const std::string& path) const
{
uint8_t k = 0;
std::string signature;
std::vector<uint8_t> id(32);
int fd = ::open(path.c_str(), O_RDONLY);
if (fd < 0) {
return nullptr;
}
signature.resize(19);
if (::read(fd, signature.data(), signature.size()) != signature.size()) {
::close(fd);
return nullptr;
}
if (::read(fd, id.data(), id.size()) != id.size()) {
::close(fd);
return nullptr;
}
if (::read(fd, &k, 1) != 1) {
::close(fd);
return nullptr;
}
if (0 != ::lseek64(fd, 0, SEEK_SET)) {
::close(fd);
return nullptr;
}
return std::make_shared<PlotFile>(fd, k, id);
}
};