-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputStream.cpp
More file actions
56 lines (45 loc) · 898 Bytes
/
Copy pathinputStream.cpp
File metadata and controls
56 lines (45 loc) · 898 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
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "inputStream.h"
#include <assert.h>
#include <fstream>
InputStream::InputStream(std::string fileName) {
openFile(fileName);
col = 1;
row = 1;
}
InputStream::~InputStream() {
}
inputToken InputStream::peek() {
assert(fd.is_open());
inputToken res(fd.peek(), col, row);
return res;
}
inputToken InputStream::peek(int n) {
assert(fd.is_open());
fd.seekg(n, std::ios::cur);
inputToken res(fd.peek(), col+n, row);
fd.seekg(-n, std::ios::cur);
return res;
}
inputToken InputStream::consume() {
assert(fd.is_open());
inputToken res = peek();
fd.get();
if (res.c == '\n') {
col = 0;
row++;
}
else
col++;
return res;
}
bool InputStream::eof() {
assert(fd.is_open());
return fd.eof();
}
void InputStream::croack(std::string msg) {
assert(fd.is_open());
}
bool InputStream::openFile(std::string fileName) {
fd = std::ifstream(fileName);
return fd.is_open();
}