-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputParser.cpp
47 lines (39 loc) · 1.33 KB
/
InputParser.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
#include "InputParser.hpp"
// Прочитать входной файл. Заполняется массив пользователей и график дежурств.
InputParser::InputParser(const std::string& filename):
filename(filename)
{
std::cout << boost::format("[InputParser] Input file: %s\n") % filename;
std::ifstream input(filename.c_str());
std::string s, firstWord;
while(std::getline(input, s)) {
// skip comments
if (s[0] == '#') {
continue;
}
boost::tokenizer<> toker(s);
boost::tokenizer<>::iterator t = toker.begin();
firstWord = (std::string)(*t);
if (firstWord == "person") {
t++;
std::string name = *t;
t++;
std::string surname = *t;
t++;
bool male = ((std::string)(*t) == "male");
DutyManager::addDutyPerson(name, surname, male);
}
else if (firstWord == "event") {
t++;
std::string name = *t;
t++;
int f_req = boost::lexical_cast<int>(*t);
t++;
int m_req = boost::lexical_cast<int>(*t);
DutyManager::addDutyEvent(name, f_req, m_req);
}
else {
std::cout << "[InputParser] Cannot parse config line: " << s;
}
}
}