SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2015 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 #ifdef CHECK_MEMORY_LEAKS
32 #include <foreign/nvwa/debug_new.h>
33 #endif // CHECK_MEMORY_LEAKS
34 
35 
36 // ===========================================================================
37 // static variable definitions
38 // ===========================================================================
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 bool
46 DistributionCont::dictionary(const std::string& type, const std::string& id,
47  Distribution* d) {
48  TypedDistDict::iterator i = myDict.find(type);
49 
50  if (i == myDict.end()) {
51  myDict[type][id] = d;
52  return true;
53  }
54  DistDict& dict = (*i).second;
55  DistDict::iterator j = dict.find(id);
56  if (j == dict.end()) {
57  myDict[type][id] = d;
58  return true;
59  }
60  return false;
61 }
62 
63 
65 DistributionCont::dictionary(const std::string& type,
66  const std::string& id) {
67  TypedDistDict::iterator i = myDict.find(type);
68  if (i == myDict.end()) {
69  return 0;
70  }
71  DistDict& dict = (*i).second;
72  DistDict::iterator j = dict.find(id);
73  if (j == dict.end()) {
74  return 0;
75  }
76  return (*j).second;
77 }
78 
79 
80 
81 /****************************************************************************/
82 
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. ...