-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutputSerialiser.h
More file actions
49 lines (43 loc) · 1.03 KB
/
OutputSerialiser.h
File metadata and controls
49 lines (43 loc) · 1.03 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
#pragma once
#include "all.h"
template<typename T>
class OutputSerialiser {
private:
vector<T> buffer;
size_t n;
std::ofstream out;
string output_file_name;
virtual void pushbuffer();
public:
OutputSerialiser(int, const string&);
virtual void open();
virtual void push(T);
virtual void close();
};
template<typename T>
OutputSerialiser<T>::OutputSerialiser(int n_, const string& _output_file_name){
output_file_name = _output_file_name;
n = n_;
}
template<typename T>
void OutputSerialiser<T>::open() {
out.open(output_file_name, std::ios_base::out);
assert(out.is_open());
}
template<typename T>
void OutputSerialiser<T>::close() {
pushbuffer();
out.close();
}
template<typename T>
void OutputSerialiser<T>::pushbuffer() {
for (size_t i = 0; i < buffer.size(); ++i)
out << buffer[i] << ' ';
buffer.clear();
}
template<typename T>
void OutputSerialiser<T>::push(T arg) {
assert(out.is_open());
if (buffer.size() >= n) pushbuffer();
buffer.push_back(arg);
}