SUMO - Simulation of Urban MObility

NIXMLTypesHandler.cpp

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