RODFDetectorHandler.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 <utils/options/OptionsCont.h>
00032 #include <utils/common/MsgHandler.h>
00033 #include <utils/common/StringTokenizer.h>
00034 #include <utils/common/UtilExceptions.h>
00035 #include <utils/common/TplConvertSec.h>
00036 #include <utils/xml/SUMOSAXHandler.h>
00037 #include <utils/xml/SUMOXMLDefinitions.h>
00038 #include "RODFDetectorHandler.h"
00039 #include "RODFNet.h"
00040
00041 #ifdef CHECK_MEMORY_LEAKS
00042 #include <foreign/nvwa/debug_new.h>
00043 #endif // CHECK_MEMORY_LEAKS
00044
00045
00046
00047
00048
00049 RODFDetectorHandler::RODFDetectorHandler(RODFNet *optNet, bool ignoreErrors, RODFDetectorCon &con,
00050 const std::string &file)
00051 : SUMOSAXHandler(file),
00052 myNet(optNet), myIgnoreErrors(ignoreErrors), myContainer(con) {}
00053
00054
00055 RODFDetectorHandler::~RODFDetectorHandler() throw() {}
00056
00057
00058 void
00059 RODFDetectorHandler::myStartElement(SumoXMLTag element,
00060 const SUMOSAXAttributes &attrs) throw(ProcessError) {
00061 if (element==SUMO_TAG_DETECTOR_DEFINITION) {
00062 try {
00063
00064 std::string id;
00065 if (!attrs.setIDFromAttributes("detector_definition", id, false)) {
00066 throw ProcessError("A detector_definition without an id occured within '" + getFileName() + "'.");
00067 }
00068 bool ok = true;
00069 std::string lane = attrs.getStringReporting(SUMO_ATTR_LANE, "detector_definition", id.c_str(), ok);
00070 if (!ok) {
00071 throw ProcessError();
00072 }
00073 ROEdge *edge = myNet->getEdge(lane.substr(0, lane.rfind('_')));
00074 unsigned int laneIndex = TplConvertSec<char>::_2intSec(lane.substr(lane.rfind('_')+1).c_str(), INT_MAX);
00075 if (edge == 0 || laneIndex >= edge->getLaneNo()) {
00076 throw ProcessError("Unknown lane '" + lane + "' for detector '" + id + "' in '" + getFileName() + "'.");
00077 }
00078 SUMOReal pos = attrs.getSUMORealReporting(SUMO_ATTR_POSITION, "detector_definition", id.c_str(), ok);
00079 std::string mml_type = attrs.getOptStringReporting(SUMO_ATTR_TYPE, "detector_definition", id.c_str(), ok, "");
00080 if (!ok) {
00081 throw ProcessError();
00082 }
00083 RODFDetectorType type = TYPE_NOT_DEFINED;
00084 if (mml_type=="between") {
00085 type = BETWEEN_DETECTOR;
00086 } else if (mml_type=="source"||mml_type=="highway_source") {
00087 type = SOURCE_DETECTOR;
00088 } else if (mml_type=="sink") {
00089 type = SINK_DETECTOR;
00090 }
00091 RODFDetector *detector = new RODFDetector(id, lane, pos, type);
00092 if (!myContainer.addDetector(detector)) {
00093 delete detector;
00094 throw ProcessError("Could not add detector '" + id + "' (probably the id is already used).");
00095 }
00096 } catch (ProcessError e) {
00097 if (myIgnoreErrors) {
00098 MsgHandler::getWarningInstance()->inform(e.what());
00099 } else {
00100 throw e;
00101 }
00102 }
00103 }
00104 }
00105
00106
00107
00108
00109