SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NBJoinedEdgesMap.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A structure storing information about which edges were joined
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2013 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 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <cassert>
32 #include <iostream>
33 #include "NBJoinedEdgesMap.h"
34 #include "NBEdgeCont.h"
35 #include "NBEdge.h"
36 #include <algorithm>
37 #include <iterator>
38 
39 #ifdef CHECK_MEMORY_LEAKS
40 #include <foreign/nvwa/debug_new.h>
41 #endif // CHECK_MEMORY_LEAKS
42 
43 
44 // ===========================================================================
45 // member method definitions
46 // ===========================================================================
48 
49 
51 
52 
53 void
55  const std::vector<std::string> edgeNames = ec.getAllNames();
56  myMap.clear();
57  for (std::vector<std::string>::const_iterator i = edgeNames.begin(); i != edgeNames.end(); i++) {
59  e.push_back(*i);
60  myMap[*i] = e;
61  myLengths[*i] = ec.retrieve(*i)->getLength();
62  }
63 }
64 
65 
66 void
67 NBJoinedEdgesMap::appended(const std::string& to, const std::string& what) {
68  copy(myMap[what].begin(), myMap[what].end(), back_inserter(myMap[to]));
69  JoinedEdgesMap::iterator i = myMap.find(what);
70  assert(i != myMap.end());
71  myMap.erase(i);
72 }
73 
74 
75 std::ostream&
76 operator<<(std::ostream& os, const NBJoinedEdgesMap& jemap) {
77  NBJoinedEdgesMap::JoinedEdgesMap::const_iterator i;
78  for (i = jemap.myMap.begin(); i != jemap.myMap.end(); ++i) {
79  os << (*i).first << "\t";
80  const NBJoinedEdgesMap::MappedEdgesVector& e = (*i).second;
81  for (NBJoinedEdgesMap::MappedEdgesVector::const_iterator j = e.begin(); j != e.end(); ++j) {
82  os << (*j) << ":" << jemap.myLengths.find(*j)->second << "\t";
83  }
84  os << std::endl;
85  }
86  return os;
87 }
88 
89 
90 
91 /****************************************************************************/
92 
std::vector< std::string > getAllNames() const
Returns all ids of known edges.
Definition: NBEdgeCont.cpp:500
std::map< std::string, SUMOReal > myLengths
~NBJoinedEdgesMap()
Destructor.
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:251
A structure storing information about which edges were joined.
JoinedEdgesMap myMap
Map of edge names to lists of previous edges the current edge is made of.
NBJoinedEdgesMap()
Constructor.
void init(NBEdgeCont &ec)
Initialises the map using the list of edge names.
std::ostream & operator<<(std::ostream &os, const MTRand &mtrand)
void appended(const std::string &to, const std::string &what)
Informs the map that two edges have been joined.
std::vector< std::string > MappedEdgesVector
def. of a list of edges that make up an edge
SUMOReal getLength() const
Returns the computed length of the edge.
Definition: NBEdge.h:397