ROVehicleCont.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // A container for vehicles sorted by their departure time
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 
00020 
00021 // ===========================================================================
00022 // included modules
00023 // ===========================================================================
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029 
00030 #include <string>
00031 #include <utils/common/NamedObjectCont.h>
00032 #include <queue>
00033 #include "ROVehicle.h"
00034 #include "ROHelper.h"
00035 #include "ROVehicleCont.h"
00036 
00037 #ifdef CHECK_MEMORY_LEAKS
00038 #include <foreign/nvwa/debug_new.h>
00039 #endif // CHECK_MEMORY_LEAKS
00040 
00041 
00042 // ===========================================================================
00043 // method definitions
00044 // ===========================================================================
00045 ROVehicleCont::ROVehicleCont() throw() {}
00046 
00047 
00048 ROVehicleCont::~ROVehicleCont() throw() {}
00049 
00050 
00051 const ROVehicle * const
00052 ROVehicleCont::getTopVehicle() const throw() {
00053     if (size()==0) {
00054         return 0;
00055     }
00056     return mySorted.top();
00057 }
00058 
00059 
00060 bool
00061 ROVehicleCont::add(const std::string &id, ROVehicle *item) throw() {
00062     if (NamedObjectCont<ROVehicle*>::add(id, item)) {
00063         mySorted.push(item);
00064         return true;
00065     }
00066     return false;
00067 }
00068 
00069 
00070 void
00071 ROVehicleCont::clear() throw() {
00072     mySorted = std::priority_queue<ROVehicle*, std::vector<ROVehicle*>, ROVehicleByDepartureComperator>();
00073     NamedObjectCont<ROVehicle*>::clear();
00074 }
00075 
00076 
00077 bool
00078 ROVehicleCont::erase(const std::string &id) throw() {
00079     const ROVehicle * const topVeh = getTopVehicle();
00080     bool wasTop = topVeh!=0&&topVeh->getID()==id;
00081     if (!NamedObjectCont<ROVehicle*>::erase(id)) {
00082         return false;
00083     }
00084     if (wasTop) {
00085         mySorted.pop();
00086     } else {
00087         rebuildSorted();
00088     }
00089     return true;
00090 }
00091 
00092 
00093 void
00094 ROVehicleCont::rebuildSorted() throw() {
00095     mySorted = std::priority_queue<ROVehicle*, std::vector<ROVehicle*>, ROVehicleByDepartureComperator>();
00096     std::map<std::string, ROVehicle*>::const_iterator i;
00097     const std::map<std::string, ROVehicle*> &mmap = getMyMap();
00098     for (i=mmap.begin(); i!=mmap.end(); ++i) {
00099         mySorted.push((*i).second);
00100     }
00101 }
00102 
00103 
00104 /****************************************************************************/

Generated on Wed May 5 00:06:36 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6