|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A structure storing information about which edges were joined 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 // included modules 00021 // =========================================================================== 00022 #ifdef _MSC_VER 00023 #include <windows_config.h> 00024 #else 00025 #include <config.h> 00026 #endif 00027 00028 #include <cassert> 00029 #include <iostream> 00030 #include "NBJoinedEdgesMap.h" 00031 #include "NBEdgeCont.h" 00032 #include "NBEdge.h" 00033 #include <algorithm> 00034 #include <iterator> 00035 00036 #ifdef CHECK_MEMORY_LEAKS 00037 #include <foreign/nvwa/debug_new.h> 00038 #endif // CHECK_MEMORY_LEAKS 00039 00040 00041 // =========================================================================== 00042 // member method definitions 00043 // =========================================================================== 00044 NBJoinedEdgesMap::NBJoinedEdgesMap() {} 00045 00046 00047 NBJoinedEdgesMap::~NBJoinedEdgesMap() {} 00048 00049 00050 void 00051 NBJoinedEdgesMap::init(NBEdgeCont& ec) { 00052 const std::vector<std::string> edgeNames = ec.getAllNames(); 00053 myMap.clear(); 00054 for (std::vector<std::string>::const_iterator i=edgeNames.begin(); i!=edgeNames.end(); i++) { 00055 MappedEdgesVector e; 00056 e.push_back(*i); 00057 myMap[*i] = e; 00058 myLengths[*i] = ec.retrieve(*i)->getLength(); 00059 } 00060 } 00061 00062 00063 void 00064 NBJoinedEdgesMap::appended(const std::string& to, const std::string& what) { 00065 copy(myMap[what].begin(), myMap[what].end(), back_inserter(myMap[to])); 00066 JoinedEdgesMap::iterator i = myMap.find(what); 00067 assert(i!=myMap.end()); 00068 myMap.erase(i); 00069 } 00070 00071 00072 std::ostream& 00073 operator<<(std::ostream& os, const NBJoinedEdgesMap& jemap) { 00074 NBJoinedEdgesMap::JoinedEdgesMap::const_iterator i; 00075 for (i=jemap.myMap.begin(); i!=jemap.myMap.end(); ++i) { 00076 os << (*i).first << "\t"; 00077 const NBJoinedEdgesMap::MappedEdgesVector& e = (*i).second; 00078 for (NBJoinedEdgesMap::MappedEdgesVector::const_iterator j=e.begin(); j!=e.end(); ++j) { 00079 os << (*j) << ":" << jemap.myLengths.find(*j)->second << "\t"; 00080 } 00081 os << std::endl; 00082 } 00083 return os; 00084 } 00085 00086 00087 00088 /****************************************************************************/ 00089