| 1 | #include "NetworkReader.h" |
|---|
| 2 | |
|---|
| 3 | HighwaysParser::HighwaysParser(const char * xml) { |
|---|
| 4 | ldsIndex = 0; |
|---|
| 5 | loadLines(xml); |
|---|
| 6 | } |
|---|
| 7 | |
|---|
| 8 | LOOP * HighwaysParser::parseLoop(TiXmlElement * loopElem) { |
|---|
| 9 | LOOP *loop = new LOOP; |
|---|
| 10 | |
|---|
| 11 | TiXmlElement *subLoopElem = loopElem->FirstChildElement(); |
|---|
| 12 | loop->loopID = atoi(subLoopElem->GetText()); |
|---|
| 13 | subLoopElem = subLoopElem->NextSiblingElement(); |
|---|
| 14 | loop->loop_loc = (char *) subLoopElem->GetText(); |
|---|
| 15 | subLoopElem = subLoopElem->NextSiblingElement(); |
|---|
| 16 | subLoopElem = subLoopElem->NextSiblingElement(); // skip lane num |
|---|
| 17 | loop->vol = atoi(subLoopElem->GetText()); |
|---|
| 18 | subLoopElem = subLoopElem->NextSiblingElement(); |
|---|
| 19 | loop->occ = atof(subLoopElem->GetText()); |
|---|
| 20 | subLoopElem = subLoopElem->NextSiblingElement(); |
|---|
| 21 | loop->spd = atof(subLoopElem->GetText()); |
|---|
| 22 | |
|---|
| 23 | return loop; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | STATION * HighwaysParser::parseStation(TiXmlElement *stationElem, FEP_LINE *line) { |
|---|
| 27 | STATION *station = new STATION; |
|---|
| 28 | |
|---|
| 29 | TiXmlElement *stationSubElem = stationElem->FirstChildElement(); |
|---|
| 30 | station->lds = atol(stationSubElem->GetText()); |
|---|
| 31 | cout << "Station: " << station->lds << endl; |
|---|
| 32 | line->lds.push_back(station->lds); |
|---|
| 33 | line->ldsIndex.push_back(ldsIndex++); |
|---|
| 34 | stationSubElem = stationSubElem->NextSiblingElement(); |
|---|
| 35 | station->line_num = atoi(stationSubElem->GetText()); |
|---|
| 36 | stationSubElem = stationSubElem->NextSiblingElement(); |
|---|
| 37 | station->drop = atoi(stationSubElem->GetText()); |
|---|
| 38 | stationSubElem = stationSubElem->NextSiblingElement(); |
|---|
| 39 | stationSubElem = stationSubElem->NextSiblingElement(); // skip location |
|---|
| 40 | stationSubElem = stationSubElem->NextSiblingElement(); // skip postmile |
|---|
| 41 | stationSubElem = stationSubElem->NextSiblingElement(); // skip direction |
|---|
| 42 | stationSubElem = stationSubElem->NextSiblingElement(); // skip freeway |
|---|
| 43 | station->MlTotVol = atoi(stationSubElem->GetText()); |
|---|
| 44 | stationSubElem = stationSubElem->NextSiblingElement(); |
|---|
| 45 | station->OppTotVol = atoi(stationSubElem->GetText()); |
|---|
| 46 | |
|---|
| 47 | station->pos = 0; // NOT SURE WHY WE NEED THIS? |
|---|
| 48 | |
|---|
| 49 | // Add loops to station |
|---|
| 50 | TiXmlElement *loopElem = stationSubElem->NextSiblingElement()->FirstChildElement(); |
|---|
| 51 | for (loopElem; loopElem; loopElem = loopElem->NextSiblingElement()) { |
|---|
| 52 | LOOP *loop = parseLoop(loopElem); |
|---|
| 53 | station->loops.push_back(loop); |
|---|
| 54 | } |
|---|
| 55 | cout << "Number of Loops: " << station->loops.size() << endl; |
|---|
| 56 | // Data pack ATMS message |
|---|
| 57 | station->length = station->loops.size() * 2 + CONTROL_DATA_LEN; |
|---|
| 58 | cout << station->loops.size() << endl; |
|---|
| 59 | station->dataPack = DataPacker::packData(station); |
|---|
| 60 | |
|---|
| 61 | return station; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | FEP_LINE * HighwaysParser::parseLine(TiXmlElement * lineElem) { |
|---|
| 65 | FEP_LINE *line = new FEP_LINE; |
|---|
| 66 | |
|---|
| 67 | TiXmlElement *lineSubElem = lineElem->FirstChildElement(); |
|---|
| 68 | line->lineNum = atoi(lineSubElem->GetText()); |
|---|
| 69 | cout << "Line: " << line->lineNum << endl; |
|---|
| 70 | lineSubElem = lineSubElem->NextSiblingElement(); |
|---|
| 71 | line->count = atoi(lineSubElem->GetText()); |
|---|
| 72 | lineSubElem = lineSubElem->NextSiblingElement(); |
|---|
| 73 | line->schedule = atoi(lineSubElem->GetText()); |
|---|
| 74 | lineSubElem = lineSubElem->NextSiblingElement(); |
|---|
| 75 | line->lineInfo = atoi(lineSubElem->GetText()); |
|---|
| 76 | lineSubElem = lineSubElem->NextSiblingElement(); |
|---|
| 77 | line->systemKey = atol(lineSubElem->GetText()); |
|---|
| 78 | lineSubElem = lineSubElem->NextSiblingElement(); |
|---|
| 79 | line->globalSeq = atol(lineSubElem->GetText()); |
|---|
| 80 | lineSubElem = lineSubElem->NextSiblingElement(); |
|---|
| 81 | line->schedleSeq = atol(lineSubElem->GetText()); |
|---|
| 82 | |
|---|
| 83 | TiXmlElement *stationsElem = lineSubElem->NextSiblingElement(); |
|---|
| 84 | TiXmlElement *stationElem = stationsElem->FirstChildElement(); |
|---|
| 85 | for (stationElem; stationElem; stationElem = stationElem->NextSiblingElement()) { |
|---|
| 86 | stations.push_back(parseStation(stationElem, line)); |
|---|
| 87 | } |
|---|
| 88 | return line; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | void HighwaysParser::loadLines(const char * xml) { |
|---|
| 92 | // Load network xml file |
|---|
| 93 | TiXmlDocument doc; |
|---|
| 94 | doc.Parse((const char*) xml, 0, TIXML_ENCODING_UTF8); |
|---|
| 95 | |
|---|
| 96 | // grab <Network> element |
|---|
| 97 | TiXmlHandle hDoc(&doc); |
|---|
| 98 | TiXmlElement *networkElem = hDoc.FirstChildElement().Element(); |
|---|
| 99 | |
|---|
| 100 | // grab first <Line> element |
|---|
| 101 | TiXmlElement *lineElem = networkElem->FirstChildElement(); |
|---|
| 102 | |
|---|
| 103 | // iterate through each line element to create FEP_LINE list |
|---|
| 104 | for (lineElem; lineElem; lineElem = lineElem->NextSiblingElement()) { |
|---|
| 105 | lines.push_back(parseLine(lineElem)); |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | vector<FEP_LINE*> HighwaysParser::getLines() { |
|---|
| 110 | |
|---|
| 111 | return lines; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | vector<STATION*> HighwaysParser::getStations() { |
|---|
| 115 | |
|---|
| 116 | return stations; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | HighwaysParser::~HighwaysParser() { |
|---|
| 120 | |
|---|
| 121 | } |
|---|