-
Notifications
You must be signed in to change notification settings - Fork 2
/
Parser.h
51 lines (42 loc) · 1.28 KB
/
Parser.h
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
#pragma once
#pragma once
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <deque>
#include <experimental/filesystem>
/**
* PARSER.H
* ~PARSER CLASS~
* CREATED BY JARRETT S. JOHNSON
* UPDATED DECEMBER 2017
* YANG ZHANG LABORATORY
* UNIVERSITY OF MICHIGAN, ANN ARBOR CAMPUS
* Desc: C++ Parser class to manage parsing files into simple C/C++ types and objects
* Note: Use GCC versions 5 and newer
* Note: std::deque preferred over std::queue due to std::queue's lack of .clear(), and inability to
* be used in ranged-based for's.
*
*/
class Parser {
private:
std::string filename;
std::deque<std::string> currLine;
std::string currRawLine;
std::ifstream FILE;
public:
Parser() = default;
void open(const std::string& file);
void open(const std::experimental::filesystem::path& file);
void close() { FILE.close(); }
inline std::string getFileName() const noexcept { return filename; }
void getNextLine();
std::string getNextInStr();
int getNextInInt();
double getNextInDouble();
bool isOpen() { return FILE.is_open(); }
bool eof() { return FILE.is_open() && FILE.eof(); }
std::string getCurrLine() const noexcept { return currRawLine; }
auto& getCurrLineAsWords() const noexcept { return currLine; }
};