SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00010 // Importer for edge type information stored in XML 00011 /****************************************************************************/ 00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00014 /****************************************************************************/ 00015 // 00016 // This file is part of SUMO. 00017 // SUMO is free software: you can redistribute it and/or modify 00018 // it under the terms of the GNU General Public License as published by 00019 // the Free Software Foundation, either version 3 of the License, or 00020 // (at your option) any later version. 00021 // 00022 /****************************************************************************/ 00023 00024 00025 // =========================================================================== 00026 // included modules 00027 // =========================================================================== 00028 #ifdef _MSC_VER 00029 #include <windows_config.h> 00030 #else 00031 #include <config.h> 00032 #endif 00033 00034 #include <string> 00035 #include <iostream> 00036 #include <xercesc/sax/HandlerBase.hpp> 00037 #include <xercesc/sax/AttributeList.hpp> 00038 #include <xercesc/sax/SAXParseException.hpp> 00039 #include <xercesc/sax/SAXException.hpp> 00040 #include "NIXMLTypesHandler.h" 00041 #include <netbuild/NBTypeCont.h> 00042 #include <utils/xml/SUMOSAXHandler.h> 00043 #include <utils/xml/SUMOXMLDefinitions.h> 00044 #include <utils/common/TplConvert.h> 00045 #include <utils/common/MsgHandler.h> 00046 #include <utils/common/ToString.h> 00047 #include <utils/common/SUMOVehicleClass.h> 00048 00049 #ifdef CHECK_MEMORY_LEAKS 00050 #include <foreign/nvwa/debug_new.h> 00051 #endif // CHECK_MEMORY_LEAKS 00052 00053 00054 // =========================================================================== 00055 // method definitions 00056 // =========================================================================== 00057 NIXMLTypesHandler::NIXMLTypesHandler(NBTypeCont& tc) 00058 : SUMOSAXHandler("xml-types - file"), 00059 myTypeCont(tc), myHaveWarnedAboutDeprecatedNoLanes(false) {} 00060 00061 00062 NIXMLTypesHandler::~NIXMLTypesHandler() {} 00063 00064 00065 void 00066 NIXMLTypesHandler::myStartElement(int element, 00067 const SUMOSAXAttributes& attrs) { 00068 if (element != SUMO_TAG_TYPE) { 00069 return; 00070 } 00071 bool ok = true; 00072 // get the id, report a warning if not given or empty... 00073 std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok); 00074 int priority = attrs.getOptIntReporting(SUMO_ATTR_PRIORITY, id.c_str(), ok, myTypeCont.getPriority("")); 00075 int noLanes = myTypeCont.getNumLanes(""); 00076 if (attrs.hasAttribute(SUMO_ATTR_NOLANES__DEPRECATED)) { 00077 noLanes = attrs.getIntReporting(SUMO_ATTR_NOLANES__DEPRECATED, id.c_str(), ok); 00078 if (!myHaveWarnedAboutDeprecatedNoLanes) { 00079 myHaveWarnedAboutDeprecatedNoLanes = true; 00080 WRITE_WARNING("'" + toString(SUMO_ATTR_NOLANES__DEPRECATED) + "' is deprecated, please use '" + toString(SUMO_ATTR_NUMLANES) + "' instead."); 00081 } 00082 } 00083 noLanes = attrs.getOptIntReporting(SUMO_ATTR_NUMLANES, id.c_str(), ok, noLanes); 00084 SUMOReal speed = attrs.getOptSUMORealReporting(SUMO_ATTR_SPEED, id.c_str(), ok, (SUMOReal) myTypeCont.getSpeed("")); 00085 std::string allowS = attrs.getOptStringReporting(SUMO_ATTR_ALLOW, id.c_str(), ok, ""); 00086 std::string disallowS = attrs.getOptStringReporting(SUMO_ATTR_DISALLOW, id.c_str(), ok, ""); 00087 bool oneway = attrs.getOptBoolReporting(SUMO_ATTR_ONEWAY, id.c_str(), ok, false); 00088 bool discard = attrs.getOptBoolReporting(SUMO_ATTR_DISCARD, id.c_str(), ok, false); 00089 SUMOReal width = attrs.getOptSUMORealReporting(SUMO_ATTR_WIDTH, id.c_str(), ok, NBEdge::UNSPECIFIED_WIDTH); 00090 if (!ok) { 00091 return; 00092 } 00093 // build the type 00094 SVCPermissions permissions = parseVehicleClasses(allowS, disallowS); 00095 if (!myTypeCont.insert(id, noLanes, speed, priority, permissions, width, oneway)) { 00096 WRITE_ERROR("Duplicate type occured. ID='" + id + "'"); 00097 } else { 00098 if (discard) { 00099 myTypeCont.markAsToDiscard(id); 00100 } 00101 } 00102 } 00103 00104 00105 00106 /****************************************************************************/ 00107