Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netbuild/NBDistrictCont.cpp
169666 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file NBDistrictCont.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Michael Behrisch
17
/// @date Tue, 20 Nov 2001
18
///
19
// A container for districts
20
/****************************************************************************/
21
#include <config.h>
22
23
#include <string>
24
#include <iostream>
25
#include <utils/common/MsgHandler.h>
26
#include <utils/common/ToString.h>
27
#include <utils/iodevices/OutputDevice.h>
28
#include "NBDistrict.h"
29
#include "NBDistrictCont.h"
30
31
32
// ===========================================================================
33
// method definitions
34
// ===========================================================================
35
NBDistrictCont::NBDistrictCont() {}
36
37
38
NBDistrictCont::~NBDistrictCont() {
39
for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
40
delete ((*i).second);
41
}
42
myDistricts.clear();
43
}
44
45
46
bool
47
NBDistrictCont::insert(NBDistrict* const district) {
48
DistrictCont::const_iterator i = myDistricts.find(district->getID());
49
if (i != myDistricts.end()) {
50
return false;
51
}
52
myDistricts.insert(DistrictCont::value_type(district->getID(), district));
53
return true;
54
}
55
56
57
NBDistrict*
58
NBDistrictCont::retrieve(const std::string& id) const {
59
DistrictCont::const_iterator i = myDistricts.find(id);
60
if (i == myDistricts.end()) {
61
return nullptr;
62
}
63
return (*i).second;
64
}
65
66
67
int
68
NBDistrictCont::size() const {
69
return (int)myDistricts.size();
70
}
71
72
73
bool
74
NBDistrictCont::addSource(const std::string& dist, NBEdge* const source,
75
double weight) {
76
NBDistrict* o = retrieve(dist);
77
if (o == nullptr) {
78
return false;
79
}
80
return o->addSource(source, weight);
81
}
82
83
84
bool
85
NBDistrictCont::addSink(const std::string& dist, NBEdge* const destination,
86
double weight) {
87
NBDistrict* o = retrieve(dist);
88
if (o == nullptr) {
89
return false;
90
}
91
return o->addSink(destination, weight);
92
}
93
94
95
void
96
NBDistrictCont::removeFromSinksAndSources(NBEdge* const e) {
97
for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
98
(*i).second->removeFromSinksAndSources(e);
99
}
100
}
101
102
103
/****************************************************************************/
104
105