This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
route_list_parser.cpp
66 lines (57 loc) · 1.67 KB
/
route_list_parser.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
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include "route_list_parser.h"
#include "io.h"
char RouteListParser::key_from_string(std::string *str) {
if (!str->compare("tag")) {
return ATTR_ROUTE_TAG;
} else if (!str->compare("title")) {
return ATTR_ROUTE_TITLE;
} else if (!str->compare("shouldRetry")) {
// Must have this one
return ATTR_ERROR_SHOULD_RETRY;
} else {
return 'Z';
}
}
std::string RouteListParser::results() {
std::stringstream ss;
int i;
if (routes.empty()) {
error("RouteListParser::results()");
}
ss << IO_GREEN "ROUTE TITLE "
<< "(ROUTE TAG)" IO_NORMAL
<< std::endl << std::endl;
for (i = 0; i < routes.size(); i++) {
ss << std::left << std::setw(30) << routes[i]->title
<< std::setw(0) << " (" IO_YELLOW << routes[i]->tag
<< IO_NORMAL ")" << std::endl;
}
ss << std::endl
<< IO_GREEN "NOTE: When you get predictions or "
<< "set route/stop variables,"
<< std::endl << "make sure to use the " IO_YELLOW
<< "ROUTE TAG" IO_GREEN "." IO_NORMAL;
return ss.str();
}
void RouteListParser::parse_route() {
std::map<char, std::string> *attributeMap;
tempRouteListing = new RouteListing();
attributeMap = parse_attributes();
tempRouteListing->tag = (*attributeMap)[ATTR_ROUTE_TAG];
tempRouteListing->title = (*attributeMap)[ATTR_ROUTE_TITLE];
routes.push_back(tempRouteListing);
}
void RouteListParser::element_open_actions() {
if (!substring.compare("route")) {
parse_route();
}
}
void RouteListParser::element_close_actions() {
// No actions necessary because <route/> is self-closing
}