Line data Source code
1 : #include "data/SUMO/TAZ.hpp" 2 : 3 : #include <cstring> 4 : #include <fstream> 5 : #include <iostream> 6 : #include <memory> 7 : #include <rapidxml.hpp> 8 : #include <rapidxml_utils.hpp> 9 : #include <sstream> 10 : 11 : using namespace std; 12 : using namespace rapidxml; 13 : using namespace SUMO; 14 : using namespace utils::stringify; 15 : 16 1 : TAZs TAZ::loadFromFile(const string &path) { 17 1 : TAZs ret; 18 : 19 : // Parse XML 20 1 : shared_ptr<file<>> xmlFilePointer = nullptr; 21 1 : try { 22 1 : xmlFilePointer = make_shared<file<>>(path.c_str()); 23 0 : } catch(const ios_base::failure &e) { 24 0 : throw ios_base::failure("Could not open file " + path); 25 : } 26 1 : file<> &xmlFile = *xmlFilePointer; 27 : 28 2 : xml_document<> doc; 29 1 : doc.parse<0>(xmlFile.data()); 30 : 31 : // Get data from XML parser 32 1 : auto tazs = doc.first_node(); 33 1 : if(!tazs->first_node("taz")) tazs = tazs->first_node(); 34 : 35 : // Junctions 36 120 : for(auto it = tazs->first_node("taz"); it; it = it->next_sibling("taz")) { 37 238 : TAZ taz; 38 : 39 119 : taz.id = it->first_attribute("id")->value(); 40 : 41 : // clang-format off 42 1205 : for(auto it2 = it->first_node("tazSource"); it2; it2 = it2->next_sibling("tazSource")) { 43 3258 : taz.sources.push_back({ 44 1086 : it2->first_attribute("id")->value(), 45 2172 : stringify<TAZ::Weight>::fromString( 46 1086 : it2->first_attribute("weight")->value() 47 : ) 48 : }); 49 : } 50 1205 : for(auto it2 = it->first_node("tazSink"); it2; it2 = it2->next_sibling("tazSink")) { 51 3258 : taz.sinks.push_back({ 52 1086 : it2->first_attribute("id")->value(), 53 2172 : stringify<TAZ::Weight>::fromString( 54 1086 : it2->first_attribute("weight")->value() 55 : ) 56 : }); 57 : } 58 : // clang-format on 59 : 60 119 : ret[taz.id] = taz; 61 : } 62 : 63 2 : return ret; 64 : }