SUMO - Simulation of Urban MObility

RODFDetectorHandler.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // A handler for loading detector descriptions
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 <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/common/ToString.h>
00037 #include <utils/xml/SUMOSAXHandler.h>
00038 #include <utils/xml/SUMOXMLDefinitions.h>
00039 #include "RODFDetectorHandler.h"
00040 #include "RODFNet.h"
00041 
00042 #ifdef CHECK_MEMORY_LEAKS
00043 #include <foreign/nvwa/debug_new.h>
00044 #endif // CHECK_MEMORY_LEAKS
00045 
00046 
00047 // ===========================================================================
00048 // method definitions
00049 // ===========================================================================
00050 RODFDetectorHandler::RODFDetectorHandler(RODFNet* optNet, bool ignoreErrors, RODFDetectorCon& con,
00051         const std::string& file)
00052     : SUMOSAXHandler(file),
00053       myNet(optNet), myIgnoreErrors(ignoreErrors), myContainer(con),
00054       myHaveWarnedAboutDeprecatedDetectorDefinition(false) {}
00055 
00056 
00057 RODFDetectorHandler::~RODFDetectorHandler() throw() {}
00058 
00059 
00060 void
00061 RODFDetectorHandler::myStartElement(int element,
00062                                     const SUMOSAXAttributes& attrs) throw(ProcessError) {
00063     if (element==SUMO_TAG_DETECTOR_DEFINITION__DEPRECATED&&!myHaveWarnedAboutDeprecatedDetectorDefinition) {
00064         myHaveWarnedAboutDeprecatedDetectorDefinition = true;
00065         WRITE_WARNING("Using '" + toString(SUMO_TAG_DETECTOR_DEFINITION__DEPRECATED) + "' is deprecated. Please use '" + toString(SUMO_TAG_DETECTOR_DEFINITION) + "' instead.");
00066     }
00067     if (element==SUMO_TAG_DETECTOR_DEFINITION||element==SUMO_TAG_DETECTOR_DEFINITION__DEPRECATED) {
00068         try {
00069             bool ok = true;
00070             // get the id, report an error if not given or empty...
00071             std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok);
00072             if (!ok) {
00073                 throw ProcessError();
00074             }
00075             std::string lane = attrs.getStringReporting(SUMO_ATTR_LANE, id.c_str(), ok);
00076             if (!ok) {
00077                 throw ProcessError();
00078             }
00079             ROEdge* edge = myNet->getEdge(lane.substr(0, lane.rfind('_')));
00080             unsigned int laneIndex = TplConvertSec<char>::_2intSec(lane.substr(lane.rfind('_')+1).c_str(), INT_MAX);
00081             if (edge == 0 || laneIndex >= edge->getLaneNo()) {
00082                 throw ProcessError("Unknown lane '" + lane + "' for detector '" + id + "' in '" + getFileName() + "'.");
00083             }
00084             SUMOReal pos = attrs.getSUMORealReporting(SUMO_ATTR_POSITION, id.c_str(), ok);
00085             std::string mml_type = attrs.getOptStringReporting(SUMO_ATTR_TYPE, id.c_str(), ok, "");
00086             if (!ok) {
00087                 throw ProcessError();
00088             }
00089             RODFDetectorType type = TYPE_NOT_DEFINED;
00090             if (mml_type=="between") {
00091                 type = BETWEEN_DETECTOR;
00092             } else if (mml_type=="source"||mml_type=="highway_source") { // !!! highway-source is legacy (removed accoring output on 06.08.2007)
00093                 type = SOURCE_DETECTOR;
00094             } else if (mml_type=="sink") {
00095                 type = SINK_DETECTOR;
00096             }
00097             RODFDetector* detector = new RODFDetector(id, lane, pos, type);
00098             if (!myContainer.addDetector(detector)) {
00099                 delete detector;
00100                 throw ProcessError("Could not add detector '" + id + "' (probably the id is already used).");
00101             }
00102         } catch (ProcessError& e) {
00103             if (myIgnoreErrors) {
00104                 WRITE_WARNING(e.what());
00105             } else {
00106                 throw e;
00107             }
00108         }
00109     }
00110 }
00111 
00112 
00113 
00114 /****************************************************************************/
00115 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines