-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathParser.cpp
55 lines (51 loc) · 1.15 KB
/
Parser.cpp
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
#include "Parser.h"
#include "utility.h"
void Parser::open(const std::string& file) {
if (FILE.is_open()) {
FILE.close();
filename = file;
}
FILE.open(file);
if (!FILE.is_open()) {
std::cout << "Could not open " << file << std::endl;
return;
}
getNextLine();
}
void Parser::open(const std::experimental::filesystem::path& filepath) {
open(filepath.string());
}
void Parser::getNextLine() {
if (!FILE.is_open()) {
std::cout << filename << " has failed to open." << std::endl;
return;
}
currLine.clear();
std::string temp = "";
getline(FILE, temp);
currRawLine = temp;
std::istringstream iss(temp);
std::string tempL;
while (iss >> tempL) {
trimStr(tempL);
currLine.push_back(tempL);
}
return;
}
std::string Parser::getNextInStr() {
std::string str = currLine.front();
currLine.pop_front();
if (str.size() == 0) {
std::cout << "Could not extract from line." << std::endl;
}
if (currLine.size() == 0) {
getNextLine();
}
return str;
}
int Parser::getNextInInt() {
return atoi(getNextInStr().c_str());
}
double Parser::getNextInDouble() {
return atof(getNextInStr().c_str());
}