SUMO - Simulation of Urban MObility
NLEdgeControlBuilder.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // Interface for building edges
00010 /****************************************************************************/
00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00013 /****************************************************************************/
00014 //
00015 //   This file is part of SUMO.
00016 //   SUMO is free software: you can redistribute it and/or modify
00017 //   it under the terms of the GNU General Public License as published by
00018 //   the Free Software Foundation, either version 3 of the License, or
00019 //   (at your option) any later version.
00020 //
00021 /****************************************************************************/
00022 
00023 
00024 // ===========================================================================
00025 // included modules
00026 // ===========================================================================
00027 #ifdef _MSC_VER
00028 #include <windows_config.h>
00029 #else
00030 #include <config.h>
00031 #endif
00032 
00033 #include <vector>
00034 #include <string>
00035 #include <map>
00036 #include <algorithm>
00037 #include <iterator>
00038 #include <microsim/MSLane.h>
00039 #include <microsim/MSInternalLane.h>
00040 #include <microsim/MSEdge.h>
00041 #include <microsim/MSEdgeControl.h>
00042 #include <utils/common/StringTokenizer.h>
00043 #include <utils/common/UtilExceptions.h>
00044 #include "NLBuilder.h"
00045 #include "NLEdgeControlBuilder.h"
00046 #include <utils/options/OptionsCont.h>
00047 #include <utils/iodevices/OutputDevice.h>
00048 
00049 #ifdef HAVE_MESOSIM
00050 #include <mesosim/MELoop.h>
00051 #endif
00052 
00053 #ifdef CHECK_MEMORY_LEAKS
00054 #include <foreign/nvwa/debug_new.h>
00055 #endif // CHECK_MEMORY_LEAKS
00056 
00057 
00058 // ===========================================================================
00059 // method definitions
00060 // ===========================================================================
00061 NLEdgeControlBuilder::NLEdgeControlBuilder()
00062     : myCurrentNumericalLaneID(0), myCurrentNumericalEdgeID(0), myEdges(0) {
00063     myActiveEdge = (MSEdge*) 0;
00064     myLaneStorage = new std::vector<MSLane*>();
00065 }
00066 
00067 
00068 NLEdgeControlBuilder::~NLEdgeControlBuilder() {
00069     delete myLaneStorage;
00070 }
00071 
00072 
00073 void
00074 NLEdgeControlBuilder::beginEdgeParsing(
00075     const std::string& id, MSEdge::EdgeBasicFunction function,
00076     const std::string& streetName) {
00077     myActiveEdge = buildEdge(id, streetName);
00078     if (MSEdge::dictionary(id) != 0) {
00079         throw InvalidArgument("Another edge with the id '" + id + "' exists.");
00080     }
00081     myEdges.push_back(myActiveEdge);
00082     myFunction = function;
00083 }
00084 
00085 
00086 MSLane*
00087 NLEdgeControlBuilder::addLane(const std::string& id,
00088                               SUMOReal maxSpeed, SUMOReal length,
00089                               const PositionVector& shape, SUMOReal width,
00090                               SVCPermissions permissions) {
00091     MSLane* lane = 0;
00092     switch (myFunction) {
00093         case MSEdge::EDGEFUNCTION_INTERNAL:
00094             lane = new MSInternalLane(id, maxSpeed, length, myActiveEdge,
00095                                       myCurrentNumericalLaneID++, shape, width, permissions);
00096             break;
00097         case MSEdge::EDGEFUNCTION_NORMAL:
00098         case MSEdge::EDGEFUNCTION_CONNECTOR:
00099             lane = new MSLane(id, maxSpeed, length, myActiveEdge,
00100                               myCurrentNumericalLaneID++, shape, width, permissions);
00101             break;
00102         default:
00103             throw InvalidArgument("Unrecognised edge type.");
00104     }
00105     myLaneStorage->push_back(lane);
00106     return lane;
00107 }
00108 
00109 
00110 MSEdge*
00111 NLEdgeControlBuilder::closeEdge() {
00112     std::vector<MSLane*> *lanes = new std::vector<MSLane*>();
00113     lanes->reserve(myLaneStorage->size());
00114     copy(myLaneStorage->begin(), myLaneStorage->end(), back_inserter(*lanes));
00115     myLaneStorage->clear();
00116     myActiveEdge->initialize(lanes, myFunction);
00117     return myActiveEdge;
00118 }
00119 
00120 
00121 MSEdgeControl*
00122 NLEdgeControlBuilder::build() {
00123     for (EdgeCont::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
00124         (*i1)->closeBuilding();
00125 #ifdef HAVE_MESOSIM
00126         if (MSGlobals::gUseMesoSim) {
00127             MSGlobals::gMesoNet->buildSegmentsFor(**i1, OptionsCont::getOptions());
00128         }
00129 #endif
00130     }
00131     return new MSEdgeControl(myEdges);
00132 }
00133 
00134 
00135 MSEdge*
00136 NLEdgeControlBuilder::buildEdge(const std::string& id, const std::string& streetName) {
00137     return new MSEdge(id, myCurrentNumericalEdgeID++, streetName);
00138 }
00139 
00140 
00141 
00142 /****************************************************************************/
00143 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines