-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileReader.cpp
73 lines (55 loc) · 1.39 KB
/
FileReader.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// Created by Taemin Park on 1/12/16.
//
#include "FileReader.h"
#include <cstring>
using namespace std;
FileReader* FileReader::_fileReader = 0;
FileReader::FileReader() {
currentLinePosition = 0;
currentLineSize = 0;
currentLine = 0;
}
FileReader* FileReader::instance() {
if(!_fileReader)
_fileReader = new FileReader();
return _fileReader;
}
RC FileReader::openFile(const std::string &fileName) {
fileStream.open(fileName.c_str(), std::fstream::in | std::fstream::out);
if(!fileStream.is_open())
{
Error("File not exists.");
return -1;
}
return 1;
}
RC FileReader::closeFile() {
fileStream.close();
return 1;
}
void FileReader::Error(std::string errorMsg) {
cerr << "FileReader : "<< errorMsg << endl;
}
char FileReader::GetSym() {
if (isEndOfLine()) {
if (fileStream.eof())
return EOF;
fileStream.getline(lineBuffer, LINEBUFSIZE);
currentLineSize = std::strlen(lineBuffer);
lineBuffer[currentLineSize] = '\n';
lineBuffer[currentLineSize+1] = '\0';
currentLineSize++;
currentLine++;
currentLinePosition = 0;
return '\n';
//for debug
if(SOURCE_CODE_PRINT)
std::cout << lineBuffer << std::endl;
}
return lineBuffer[currentLinePosition++];
}
void FileReader::unGetSym()
{
currentLinePosition--;
}