SUMO - Simulation of Urban MObility
DistributionCont.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00007 // A container for distributions
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This file is part of SUMO.
00014 //   SUMO is free software: you can redistribute it and/or modify
00015 //   it under the terms of the GNU General Public License as published by
00016 //   the Free Software Foundation, either version 3 of the License, or
00017 //   (at your option) any later version.
00018 //
00019 /****************************************************************************/
00020 // ===========================================================================
00021 // included modules
00022 // ===========================================================================
00023 #ifdef _MSC_VER
00024 #include <windows_config.h>
00025 #else
00026 #include <config.h>
00027 #endif
00028 
00029 #include "DistributionCont.h"
00030 
00031 #ifdef CHECK_MEMORY_LEAKS
00032 #include <foreign/nvwa/debug_new.h>
00033 #endif // CHECK_MEMORY_LEAKS
00034 
00035 
00036 // ===========================================================================
00037 // static variable definitions
00038 // ===========================================================================
00039 DistributionCont::TypedDistDict DistributionCont::myDict;
00040 
00041 
00042 // ===========================================================================
00043 // method definitions
00044 // ===========================================================================
00045 bool
00046 DistributionCont::dictionary(const std::string& type, const std::string& id,
00047                              Distribution* d) {
00048     TypedDistDict::iterator i = myDict.find(type);
00049 
00050     if (i == myDict.end()) {
00051         myDict[type][id] = d;
00052         return true;
00053     }
00054     DistDict& dict = (*i).second;
00055     DistDict::iterator j = dict.find(id);
00056     if (j == dict.end()) {
00057         myDict[type][id] = d;
00058         return true;
00059     }
00060     return false;
00061 }
00062 
00063 
00064 Distribution*
00065 DistributionCont::dictionary(const std::string& type,
00066                              const std::string& id) {
00067     TypedDistDict::iterator i = myDict.find(type);
00068     if (i == myDict.end()) {
00069         return 0;
00070     }
00071     DistDict& dict = (*i).second;
00072     DistDict::iterator j = dict.find(id);
00073     if (j == dict.end()) {
00074         return 0;
00075     }
00076     return (*j).second;
00077 }
00078 
00079 
00080 
00081 /****************************************************************************/
00082 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines