-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputSerialiser.h
More file actions
59 lines (52 loc) · 1.18 KB
/
inputSerialiser.h
File metadata and controls
59 lines (52 loc) · 1.18 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
#pragma once
#include "all.h"
template<typename T>
class InputSerialiser {
private:
std::ifstream in;
bool buf;
T next_;
string input_file_name;
void update_buff();
public:
InputSerialiser(const string&);
virtual void open();
virtual void close();
virtual T get();
virtual bool empty();
};
template<typename T>
InputSerialiser<T>::InputSerialiser(const string& _input_file_name = "C:/Users/Howl/documents/visual studio 2015/Projects/Tim/Tim/ExternalSort/input") {
input_file_name = _input_file_name;
}
template<typename T>
void InputSerialiser<T>::open() {
in.open(input_file_name, std::ios_base::in);
assert(in.is_open());
}
template<typename T>
void InputSerialiser<T>::close() {
in.close();
}
template<typename T>
void InputSerialiser<T>::update_buff() {
assert(in.is_open());
empty();
}
template<typename T>
bool InputSerialiser<T>::empty() {
assert(in.is_open());
if (buf) return 0;
if (in.eof()) return 1;
in >> next_;
buf = !in.eof();
return !buf;
}
template<typename T>
T InputSerialiser<T>::get() {
assert(!empty());
update_buff();
buf = 0;
//cout << next_ << "\n";
return next_;
}