SUMO - Simulation of Urban MObility

GUIVehicleControl.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // The class responsible for building and deletion of vehicles (gui-version)
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2011 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 <utils/foxtools/MFXMutex.h>
00031 #include "GUIVehicleControl.h"
00032 #include "GUIVehicle.h"
00033 #include "GUINet.h"
00034 #include <gui/GUIGlobals.h>
00035 
00036 #ifdef CHECK_MEMORY_LEAKS
00037 #include <foreign/nvwa/debug_new.h>
00038 #endif // CHECK_MEMORY_LEAKS
00039 
00040 
00041 // ===========================================================================
00042 // member method definitions
00043 // ===========================================================================
00044 GUIVehicleControl::GUIVehicleControl() throw()
00045     : MSVehicleControl() {}
00046 
00047 
00048 GUIVehicleControl::~GUIVehicleControl() throw() {
00049     // just to quit cleanly on a failure
00050     if (myLock.locked()) {
00051         myLock.unlock();
00052     }
00053 }
00054 
00055 
00056 SUMOVehicle*
00057 GUIVehicleControl::buildVehicle(SUMOVehicleParameter* defs,
00058                                 const MSRoute* route, const MSVehicleType* type) throw(ProcessError) {
00059     myLoadedVehNo++;
00060     MSVehicle* built = new GUIVehicle(defs, route, type, myLoadedVehNo-1);
00061     MSNet::getInstance()->informVehicleStateListener(built, MSNet::VEHICLE_STATE_BUILT);
00062     return built;
00063 }
00064 
00065 
00066 bool
00067 GUIVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) throw() {
00068     myLock.lock();
00069     const bool result = MSVehicleControl::addVehicle(id, v);
00070     myLock.unlock();
00071     return result;
00072 }
00073 
00074 
00075 void
00076 GUIVehicleControl::deleteVehicle(SUMOVehicle* veh) throw() {
00077     myLock.lock();
00078     MSVehicleControl::deleteVehicle(veh);
00079     myLock.unlock();
00080 }
00081 
00082 
00083 void
00084 GUIVehicleControl::insertVehicleIDs(std::vector<GUIGlID> &into) throw() {
00085     myLock.lock();
00086     into.reserve(myVehicleDict.size());
00087     for (VehicleDictType::iterator i=myVehicleDict.begin(); i!=myVehicleDict.end(); ++i) {
00088         SUMOVehicle* veh = (*i).second;
00089         if (veh->isOnRoad()) {
00090             into.push_back(static_cast<GUIVehicle*>((*i).second)->getGlID());
00091         }
00092     }
00093     myLock.unlock();
00094 }
00095 
00096 
00097 
00098 /****************************************************************************/
00099 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines