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