SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NLEdgeControlBuilder.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Interface for building edges
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <vector>
34 #include <string>
35 #include <map>
36 #include <algorithm>
37 #include <iterator>
38 #include <microsim/MSLane.h>
40 #include <microsim/MSEdge.h>
41 #include <microsim/MSEdgeControl.h>
44 #include "NLBuilder.h"
45 #include "NLEdgeControlBuilder.h"
48 
49 #ifdef HAVE_MESOSIM
50 #include <mesosim/MELoop.h>
51 #endif
52 
53 #ifdef CHECK_MEMORY_LEAKS
54 #include <foreign/nvwa/debug_new.h>
55 #endif // CHECK_MEMORY_LEAKS
56 
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
62  : myCurrentNumericalLaneID(0), myCurrentNumericalEdgeID(0), myEdges(0) {
63  myActiveEdge = (MSEdge*) 0;
64  myLaneStorage = new std::vector<MSLane*>();
65 }
66 
67 
69  delete myLaneStorage;
70 }
71 
72 
73 void
75  const std::string& id, MSEdge::EdgeBasicFunction function,
76  const std::string& streetName) {
77  myActiveEdge = buildEdge(id, streetName);
78  if (MSEdge::dictionary(id) != 0) {
79  throw InvalidArgument("Another edge with the id '" + id + "' exists.");
80  }
81  myEdges.push_back(myActiveEdge);
82  myFunction = function;
83 }
84 
85 
86 MSLane*
87 NLEdgeControlBuilder::addLane(const std::string& id,
88  SUMOReal maxSpeed, SUMOReal length,
89  const PositionVector& shape, SUMOReal width,
90  SVCPermissions permissions) {
91  MSLane* lane = 0;
92  switch (myFunction) {
94  lane = new MSInternalLane(id, maxSpeed, length, myActiveEdge,
95  myCurrentNumericalLaneID++, shape, width, permissions);
96  break;
99  lane = new MSLane(id, maxSpeed, length, myActiveEdge,
100  myCurrentNumericalLaneID++, shape, width, permissions);
101  break;
102  default:
103  throw InvalidArgument("Unrecognised edge type.");
104  }
105  myLaneStorage->push_back(lane);
106  return lane;
107 }
108 
109 
110 MSEdge*
112  std::vector<MSLane*> *lanes = new std::vector<MSLane*>();
113  lanes->reserve(myLaneStorage->size());
114  copy(myLaneStorage->begin(), myLaneStorage->end(), back_inserter(*lanes));
115  myLaneStorage->clear();
117  return myActiveEdge;
118 }
119 
120 
123  for (EdgeCont::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
124  (*i1)->closeBuilding();
125 #ifdef HAVE_MESOSIM
127  MSGlobals::gMesoNet->buildSegmentsFor(**i1, OptionsCont::getOptions());
128  }
129 #endif
130  }
131  return new MSEdgeControl(myEdges);
132 }
133 
134 
135 MSEdge*
136 NLEdgeControlBuilder::buildEdge(const std::string& id, const std::string& streetName) {
137  return new MSEdge(id, myCurrentNumericalEdgeID++, streetName);
138 }
139 
140 
141 
142 /****************************************************************************/
143