-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataParser.cpp
More file actions
101 lines (86 loc) · 3.14 KB
/
DataParser.cpp
File metadata and controls
101 lines (86 loc) · 3.14 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "DataParser.h"
using namespace std;
int
DataParser::getResources(DataResources& resources, DataTuples& tuples)
{
if (!_inputData.is_open())
return -1;
string line;
DataType type = UNKNOWN;
while (!_inputData.eof()) {
getline(_inputData, line);
if (line.empty())
continue;
// Check for option
if (line[0] == '>') {
if (line == (">CLASSES:"))
type = CLASSES;
else if (line == (">ROOMS:"))
type = ROOMS;
else if (line == (">TEACHERS:"))
type = TEACHERS;
else if (line == (">SUBJECTS:"))
type = SUBJECTS;
else if (line == (">TUPLES:"))
type = TUPLES;
else
type = UNKNOWN;
} else {
switch (type) {
case CLASSES:
resources.addClass(new Class(line));
break;
case ROOMS:
resources.addRoom(new Room(line));
break;
case TEACHERS:
resources.addTeacher(new Teacher(line));
break;
case SUBJECTS: {
vector<string> columns;
split(line, ';', columns);
string& name = columns[0];
const Teacher* teacher =
resources.getTeacher().get(columns[1]);
const Room* room = resources.getRoom().get(columns[2]);
if (teacher == nullptr) {
cout << "Teacher " << columns[1]
<< " not existing - subject " << name << endl;
return -2;
}
if (teacher == nullptr) {
cout << "Room " << columns[2]
<< " not existing - subject " << name << endl;
return -2;
}
resources.addSubject(new Subject(name, teacher, room));
break;
}
case TUPLES: {
vector<string> columns;
split(line, ';', columns);
const Class* classObj =
resources.getClass().get(columns[0]);
const Subject* subject =
resources.getSubject().get(columns[1]);
if (classObj == nullptr) {
cout << "Subject " << columns[1]
<< " not existing - class " << columns[0] << endl;
return -2;
}
if (subject == nullptr) {
cout << "Class " << columns[0]
<< " not existing - subject " << columns[1]
<< endl;
return -2;
}
tuples.add(new DataTuple(classObj, subject));
break;
}
default:
continue;
}
}
}
return 0;
}