NIXMLTypesHandler.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00043 #ifdef CHECK_MEMORY_LEAKS
00044 #include <foreign/nvwa/debug_new.h>
00045 #endif // CHECK_MEMORY_LEAKS
00046
00047
00048
00049
00050
00051 NIXMLTypesHandler::NIXMLTypesHandler(NBTypeCont &tc)
00052 : SUMOSAXHandler("xml-types - file"),
00053 myTypeCont(tc), myHaveReportedAboutFunctionDeprecation(false) {}
00054
00055
00056 NIXMLTypesHandler::~NIXMLTypesHandler() throw() {}
00057
00058
00059 void
00060 NIXMLTypesHandler::myStartElement(SumoXMLTag element,
00061 const SUMOSAXAttributes &attrs) throw(ProcessError) {
00062 if (element!=SUMO_TAG_TYPE) {
00063 return;
00064 }
00065
00066 std::string id;
00067 if (!attrs.setIDFromAttributes("type", id), false) {
00068 WRITE_WARNING("No type id given... Skipping.");
00069 return;
00070 }
00071
00072 if (!myHaveReportedAboutFunctionDeprecation&&attrs.hasAttribute(SUMO_ATTR_FUNCTION)) {
00073 MsgHandler::getWarningInstance()->inform("While parsing type '" + id + "': 'function' is deprecated.\n All occurences are ignored.");
00074 myHaveReportedAboutFunctionDeprecation = true;
00075 }
00076
00077 bool ok = true;
00078 int priority = attrs.getOptIntReporting(SUMO_ATTR_PRIORITY, "type", id.c_str(), ok, myTypeCont.getDefaultPriority());
00079 int noLanes = attrs.getOptIntReporting(SUMO_ATTR_NOLANES, "type", id.c_str(), ok, myTypeCont.getDefaultNoLanes());
00080 SUMOReal speed = attrs.getOptSUMORealReporting(SUMO_ATTR_SPEED, "type", id.c_str(), ok, (SUMOReal) myTypeCont.getDefaultSpeed());
00081 bool discard = attrs.getOptBoolReporting(SUMO_ATTR_DISCARD, 0, 0, ok, false);
00082 if (!ok) {
00083 return;
00084 }
00085
00086 if (!myTypeCont.insert(id, noLanes, speed, priority)) {
00087 MsgHandler::getErrorInstance()->inform("Duplicate type occured. ID='" + id + "'");
00088 } else {
00089 if (discard) {
00090 myTypeCont.markAsToDiscard(id);
00091 }
00092 }
00093 }
00094
00095
00096
00097
00098