-
Notifications
You must be signed in to change notification settings - Fork 0
/
Buffer.h
72 lines (60 loc) · 1.29 KB
/
Buffer.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <fstream>
#include <string>
#include <iostream>
#include <sstream>
#include <cstring>
//Two buffer pair
class Buffer {
public :
//Constructor & Destructor
explicit Buffer(std::string filePath);
explicit Buffer();
~Buffer() noexcept;
private :
//Private Vars
static const int SIZE = 64; //Size of buffer
std::string fileStr; //File path
std::ifstream fileStream;
enum class Tag { First, Second }; //Number of current buffer
Buffer::Tag activitiedBuffer = Tag::First; //Number of activitied buffer
char buffer1[SIZE]; //First buffer
char buffer2[SIZE]; //Second buffer
char* lexemeBegin = nullptr; //Start of lexeme
char* forward = nullptr; //End of lexeme
public :
//Public methods
/*
* @return Get lexeme between lexemeBegin and forward
*/
std::string getLexeme();
/*
* forward +1
* @return Get current char
*/
char next();
/*
* @return Get current char
*/
char cur();
/*
* forward -1
* @return Get current char
*/
char pre();
/*
* Change lexemeBegin if string is a lexeme
*/
void confirmLexeme();
/*
* Change file path
*/
void changeFilePath(std::string filePath);
//Public Vars
bool isEnd = false;
private :
//Private methods
/*
* Fill buffer with chars in filestream
*/
void read();
};