-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathPlotsFile.cpp
More file actions
66 lines (54 loc) · 1.78 KB
/
PlotsFile.cpp
File metadata and controls
66 lines (54 loc) · 1.78 KB
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
63
64
65
66
/*
GPU plot generator for Burst coin.
Author: Cryo
Bitcoin: 138gMBhCrNkbaiTCmUhP9HLU9xwn5QKZgD
Burst: BURST-YA29-QCEW-QXC3-BKXDL
Based on the code of the official miner and dcct's plotgen.
*/
#include <stdexcept>
#include <algorithm>
#include "constants.h"
#include "PlotsFile.h"
namespace cryo {
namespace gpuPlotGenerator {
PlotsFile::PlotsFile(const std::string& p_path, bool p_truncate) throw (std::exception) {
std::ofstream::openmode mode(std::ios::in | std::ios::out | std::ios::binary);
if(p_truncate) {
mode |= std::ios::trunc;
}
m_stream.open(p_path, mode);
if(!m_stream) {
throw std::runtime_error("Unable to open plots file");
}
}
PlotsFile::~PlotsFile() throw () {
m_stream.close();
}
void PlotsFile::seek(std::streamoff p_offset, std::ios::seekdir p_direction) {
m_stream.seekg(p_offset, p_direction);
}
void PlotsFile::read(unsigned char* p_buffer, std::streamsize p_size) throw (std::exception) {
for(std::streamsize offset = 0 ; offset < p_size ; offset += (std::streamsize)IO_CAP) {
std::streamsize size = std::min(p_size - offset, (std::streamsize)IO_CAP);
m_stream.read((char*)p_buffer + offset, size);
if(!m_stream) {
throw std::runtime_error("Error while reading from plots file");
}
}
}
void PlotsFile::write(const unsigned char* p_buffer, std::streamsize p_size) throw (std::exception) {
for(std::streamsize offset = 0 ; offset < p_size ; offset += (std::streamsize)IO_CAP) {
std::streamsize size = std::min(p_size - offset, (std::streamsize)IO_CAP);
m_stream.write((const char*)p_buffer + offset, size);
if(!m_stream) {
throw std::runtime_error("Error while writting to plots file");
}
}
}
void PlotsFile::flush() throw (std::exception) {
m_stream.flush();
if(!m_stream) {
throw std::runtime_error("Error while flushing plots file");
}
}
}}