NLEdgeControlBuilder.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 <vector>
00031 #include <string>
00032 #include <map>
00033 #include <algorithm>
00034 #include <microsim/MSLane.h>
00035 #include <microsim/MSInternalLane.h>
00036 #include <microsim/MSEdge.h>
00037 #include <microsim/MSEdgeControl.h>
00038 #include <utils/common/StringTokenizer.h>
00039 #include <utils/common/UtilExceptions.h>
00040 #include "NLBuilder.h"
00041 #include "NLEdgeControlBuilder.h"
00042 #include <utils/options/OptionsCont.h>
00043 #include <utils/iodevices/OutputDevice.h>
00044
00045 #ifdef HAVE_MESOSIM
00046 #include <mesosim/MELoop.h>
00047 #endif
00048
00049 #ifdef CHECK_MEMORY_LEAKS
00050 #include <foreign/nvwa/debug_new.h>
00051 #endif // CHECK_MEMORY_LEAKS
00052
00053
00054
00055
00056
00057 NLEdgeControlBuilder::NLEdgeControlBuilder()
00058 : myCurrentNumericalLaneID(0), myCurrentNumericalEdgeID(0), myEdges(0) {
00059 myActiveEdge = (MSEdge*) 0;
00060 m_pLaneStorage = new std::vector<MSLane*>();
00061 m_pDepartLane = (MSLane*) 0;
00062 m_iNoSingle = m_iNoMulti = 0;
00063 }
00064
00065
00066 NLEdgeControlBuilder::~NLEdgeControlBuilder() {
00067 delete m_pLaneStorage;
00068 }
00069
00070
00071 void
00072 NLEdgeControlBuilder::beginEdgeParsing(const std::string &id,
00073 MSEdge::EdgeBasicFunction function) throw(InvalidArgument) {
00074 myActiveEdge = buildEdge(id);
00075 if (!MSEdge::dictionary(id, myActiveEdge)) {
00076 throw InvalidArgument("Another edge with the id '" + id + "' exists.");
00077 }
00078 myEdges.push_back(myActiveEdge);
00079 m_pDepartLane = (MSLane*) 0;
00080 m_Function = function;
00081 }
00082
00083
00084 MSLane *
00085 NLEdgeControlBuilder::addLane(const std::string &id,
00086 SUMOReal maxSpeed, SUMOReal length, bool isDepart,
00087 const Position2DVector &shape,
00088 const std::vector<SUMOVehicleClass> &allowed,
00089 const std::vector<SUMOVehicleClass> &disallowed) {
00090
00091 if (isDepart&&m_pDepartLane!=0) {
00092 throw InvalidArgument("Lane's '" + id + "' edge already has a depart lane.");
00093 }
00094 MSLane *lane = 0;
00095 switch (m_Function) {
00096 case MSEdge::EDGEFUNCTION_INTERNAL:
00097 lane = new MSInternalLane(id, maxSpeed, length, myActiveEdge,
00098 myCurrentNumericalLaneID++, shape, allowed, disallowed);
00099 break;
00100 case MSEdge::EDGEFUNCTION_NORMAL:
00101 case MSEdge::EDGEFUNCTION_CONNECTOR:
00102 lane = new MSLane(id, maxSpeed, length, myActiveEdge,
00103 myCurrentNumericalLaneID++, shape, allowed, disallowed);
00104 break;
00105 default:
00106 throw InvalidArgument("Unrecognised edge type.");
00107 }
00108 m_pLaneStorage->push_back(lane);
00109 if (isDepart) {
00110 m_pDepartLane = lane;
00111 }
00112 return lane;
00113 }
00114
00115
00116 MSEdge *
00117 NLEdgeControlBuilder::closeEdge() {
00118 std::vector<MSLane*> *lanes = new std::vector<MSLane*>();
00119 lanes->reserve(m_pLaneStorage->size());
00120 copy(m_pLaneStorage->begin(), m_pLaneStorage->end(), back_inserter(*lanes));
00121 if (m_pLaneStorage->size()==1) {
00122 m_iNoSingle++;
00123 } else {
00124 m_iNoMulti++;
00125 }
00126 m_pLaneStorage->clear();
00127 myActiveEdge->initialize(m_pDepartLane, lanes, m_Function);
00128 return myActiveEdge;
00129 }
00130
00131
00132 MSEdgeControl *
00133 NLEdgeControlBuilder::build() {
00134 for (EdgeCont::iterator i1=myEdges.begin(); i1!=myEdges.end(); i1++) {
00135 (*i1)->closeBuilding();
00136 #ifdef HAVE_MESOSIM
00137 if (MSGlobals::gUseMesoSim) {
00138 MSGlobals::gMesoNet->buildSegmentsFor(**i1, OptionsCont::getOptions());
00139 }
00140 #endif
00141 }
00142 return new MSEdgeControl(myEdges);
00143 }
00144
00145
00146 MSEdge *
00147 NLEdgeControlBuilder::buildEdge(const std::string &id) throw() {
00148 return new MSEdge(id, myCurrentNumericalEdgeID++);
00149 }
00150
00151
00152
00153
00154