SUMO - Simulation of Urban MObility
DistributionCont.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A container for distributions
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include "DistributionCont.h"
30 
31 
32 // ===========================================================================
33 // static variable definitions
34 // ===========================================================================
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
41 bool
42 DistributionCont::dictionary(const std::string& type, const std::string& id,
43  Distribution* d) {
44  TypedDistDict::iterator i = myDict.find(type);
45 
46  if (i == myDict.end()) {
47  myDict[type][id] = d;
48  return true;
49  }
50  DistDict& dict = (*i).second;
51  DistDict::iterator j = dict.find(id);
52  if (j == dict.end()) {
53  myDict[type][id] = d;
54  return true;
55  }
56  return false;
57 }
58 
59 
61 DistributionCont::dictionary(const std::string& type,
62  const std::string& id) {
63  TypedDistDict::iterator i = myDict.find(type);
64  if (i == myDict.end()) {
65  return 0;
66  }
67  DistDict& dict = (*i).second;
68  DistDict::iterator j = dict.find(id);
69  if (j == dict.end()) {
70  return 0;
71  }
72  return (*j).second;
73 }
74 
75 
76 void
78  for (TypedDistDict::iterator i = myDict.begin(); i != myDict.end(); i++) {
79  DistDict& dict = (*i).second;
80  for (DistDict::iterator j = dict.begin(); j != dict.end(); j++) {
81  delete(*j).second;
82  }
83  }
84 }
85 
86 
87 /****************************************************************************/
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. ...