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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // A container for distributions
18 /****************************************************************************/
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #ifdef _MSC_VER
23 #include <windows_config.h>
24 #else
25 #include <config.h>
26 #endif
27 
28 #include "DistributionCont.h"
29 
30 
31 // ===========================================================================
32 // static variable definitions
33 // ===========================================================================
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 bool
41 DistributionCont::dictionary(const std::string& type, const std::string& id,
42  Distribution* d) {
43  TypedDistDict::iterator i = myDict.find(type);
44 
45  if (i == myDict.end()) {
46  myDict[type][id] = d;
47  return true;
48  }
49  DistDict& dict = (*i).second;
50  DistDict::iterator j = dict.find(id);
51  if (j == dict.end()) {
52  myDict[type][id] = d;
53  return true;
54  }
55  return false;
56 }
57 
58 
60 DistributionCont::dictionary(const std::string& type,
61  const std::string& id) {
62  TypedDistDict::iterator i = myDict.find(type);
63  if (i == myDict.end()) {
64  return 0;
65  }
66  DistDict& dict = (*i).second;
67  DistDict::iterator j = dict.find(id);
68  if (j == dict.end()) {
69  return 0;
70  }
71  return (*j).second;
72 }
73 
74 
75 void
77  for (TypedDistDict::iterator i = myDict.begin(); i != myDict.end(); i++) {
78  DistDict& dict = (*i).second;
79  for (DistDict::iterator j = dict.begin(); j != dict.end(); j++) {
80  delete(*j).second;
81  }
82  }
83 }
84 
85 
86 /****************************************************************************/
static void clear()
delete all stored distributions
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.
static TypedDistDict myDict
Map from distribution types to distribution ids to distributions.
std::map< std::string, Distribution * > DistDict
Definition of a map from distribution ids to distributions.
std::map< std::string, DistDict > TypedDistDict
Definition of a map from distribution types to distribution ids to distributions. ...