Eclipse SUMO - Simulation of Urban MObility
DistributionCont.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
14 // A container for distributions
15 /****************************************************************************/
16 // ===========================================================================
17 // included modules
18 // ===========================================================================
19 #include <config.h>
20 
21 #include "DistributionCont.h"
22 
23 
24 // ===========================================================================
25 // static variable definitions
26 // ===========================================================================
28 
29 
30 // ===========================================================================
31 // method definitions
32 // ===========================================================================
33 bool
34 DistributionCont::dictionary(const std::string& type, const std::string& id,
35  Distribution* d) {
36  TypedDistDict::iterator i = myDict.find(type);
37 
38  if (i == myDict.end()) {
39  myDict[type][id] = d;
40  return true;
41  }
42  DistDict& dict = (*i).second;
43  DistDict::iterator j = dict.find(id);
44  if (j == dict.end()) {
45  myDict[type][id] = d;
46  return true;
47  }
48  return false;
49 }
50 
51 
53 DistributionCont::dictionary(const std::string& type,
54  const std::string& id) {
55  TypedDistDict::iterator i = myDict.find(type);
56  if (i == myDict.end()) {
57  return nullptr;
58  }
59  DistDict& dict = (*i).second;
60  DistDict::iterator j = dict.find(id);
61  if (j == dict.end()) {
62  return nullptr;
63  }
64  return (*j).second;
65 }
66 
67 
68 void
70  for (TypedDistDict::iterator i = myDict.begin(); i != myDict.end(); i++) {
71  DistDict& dict = (*i).second;
72  for (DistDict::iterator j = dict.begin(); j != dict.end(); j++) {
73  delete (*j).second;
74  }
75  }
76 }
77 
78 
79 /****************************************************************************/
DistributionCont::clear
static void clear()
delete all stored distributions
Definition: DistributionCont.cpp:69
Distribution
Definition: Distribution.h:37
DistributionCont::dictionary
static bool dictionary(const std::string &type, const std::string &id, Distribution *d)
Adds a distribution of the given type and name to the container.
Definition: DistributionCont.cpp:34
DistributionCont::DistDict
std::map< std::string, Distribution * > DistDict
Definition of a map from distribution ids to distributions.
Definition: DistributionCont.h:52
DistributionCont::myDict
static TypedDistDict myDict
Map from distribution types to distribution ids to distributions.
Definition: DistributionCont.h:58
config.h
DistributionCont::TypedDistDict
std::map< std::string, DistDict > TypedDistDict
Definition of a map from distribution types to distribution ids to distributions.
Definition: DistributionCont.h:55
DistributionCont.h