Line data Source code
1 : #include "data/SUMO/Additionals/Additionals.hpp" 2 : 3 : #include <spdlog/spdlog.h> 4 : 5 : #include <iostream> 6 : #include <rapidxml.hpp> 7 : #include <rapidxml_utils.hpp> 8 : 9 : #include "data/SUMO/Additionals/Location.hpp" 10 : #include "data/SUMO/Additionals/Poi.hpp" 11 : #include "data/SUMO/Additionals/Poly.hpp" 12 : #include "utils/stringify.hpp" 13 : 14 : using namespace std; 15 : using namespace rapidxml; 16 : using namespace SUMO::Additionals; 17 : using namespace utils::stringify; 18 : 19 0 : vector<unique_ptr<Additional>> SUMO::Additionals::loadFromFile(const filesystem::path &path) { 20 0 : vector<unique_ptr<Additional>> result; 21 : 22 0 : file<> xmlFile(path.c_str()); 23 : 24 0 : xml_document<> doc; 25 0 : doc.parse<0>(xmlFile.data()); 26 : 27 0 : xml_node<> *additionalEl = doc.first_node("additional"); 28 0 : assert(additionalEl != nullptr); 29 : 30 0 : Additionals::XMLFactory xmlFactory; 31 : 32 0 : for(auto el = additionalEl->first_node(); el; el = el->next_sibling()) { 33 0 : result.emplace_back(xmlFactory.create(*el)); 34 : } 35 : 36 0 : return result; 37 : } 38 : 39 0 : unique_ptr<Additional> XMLFactory::create(const rapidxml::xml_node<> &node) { 40 0 : if(string(node.name()) == "location") { 41 0 : unique_ptr<Location> result = make_unique<Location>(); 42 : 43 0 : result->loadFromXMLNode(node); 44 : 45 0 : return result; 46 : } 47 0 : if(string(node.name()) == "poly") { 48 0 : xml_attribute<> *idAttr = node.first_attribute("id"); 49 0 : xml_attribute<> *shapeAttr = node.first_attribute("shape"); 50 : 51 0 : assert(idAttr != nullptr); 52 0 : assert(shapeAttr != nullptr); 53 : 54 0 : unique_ptr<Poly> result = make_unique<Poly>( 55 0 : idAttr->value(), 56 0 : stringify<SUMO::Shape>::fromString(shapeAttr->value()) 57 0 : ); 58 : 59 0 : result->loadFromXMLNode(node); 60 : 61 0 : return result; 62 : } 63 0 : if(string(node.name()) == "poi") { 64 0 : xml_attribute<> *idAttr = node.first_attribute("id"); 65 : 66 0 : assert(idAttr != nullptr); 67 : 68 0 : unique_ptr<Poi> result = make_unique<Poi>(idAttr->value()); 69 : 70 0 : result->loadFromXMLNode(node); 71 : 72 0 : return result; 73 : } 74 : 75 0 : throw runtime_error("Unknown additional type: " + string(node.name())); 76 : }