SUMO - Simulation of Urban MObility
MSRouteLoaderControl.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00008 // Class responsible for loading of routes from some files
00009 /****************************************************************************/
00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00012 /****************************************************************************/
00013 //
00014 //   This file is part of SUMO.
00015 //   SUMO is free software: you can redistribute it and/or modify
00016 //   it under the terms of the GNU General Public License as published by
00017 //   the Free Software Foundation, either version 3 of the License, or
00018 //   (at your option) any later version.
00019 //
00020 /****************************************************************************/
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include <vector>
00033 #include "MSRouteLoader.h"
00034 #include "MSRouteLoaderControl.h"
00035 
00036 #ifdef CHECK_MEMORY_LEAKS
00037 #include <foreign/nvwa/debug_new.h>
00038 #endif // CHECK_MEMORY_LEAKS
00039 
00040 
00041 // ===========================================================================
00042 // method definitions
00043 // ===========================================================================
00044 MSRouteLoaderControl::MSRouteLoaderControl(MSNet&, SUMOTime inAdvanceStepNo, LoaderVector loader): 
00045     myLastLoadTime(-inAdvanceStepNo),
00046     myInAdvanceStepNo(inAdvanceStepNo),
00047     myRouteLoaders(loader),
00048     myAllLoaded(false) 
00049 {
00050     myLoadAll = myInAdvanceStepNo <= 0;
00051     myAllLoaded = false;
00052     myLastLoadTime = -1 * (int) myInAdvanceStepNo;
00053     // initialize all used loaders
00054     for (LoaderVector::iterator i = myRouteLoaders.begin();
00055             i != myRouteLoaders.end(); ++i) {
00056         (*i)->init();
00057     }
00058 }
00059 
00060 
00061 MSRouteLoaderControl::~MSRouteLoaderControl() {
00062     for (LoaderVector::iterator i = myRouteLoaders.begin();
00063             i != myRouteLoaders.end(); ++i) {
00064         delete(*i);
00065     }
00066 }
00067 
00068 
00069 void
00070 MSRouteLoaderControl::loadNext(SUMOTime step) {
00071     // check whether new vehicles shall be loaded
00072     //  return if not
00073     if (myAllLoaded) {
00074         return;
00075     }
00076     SUMOTime loadMaxTime = myLoadAll ? SUMOTime_MAX : step + myInAdvanceStepNo;
00077 
00078     // load all routes for the specified time period
00079     bool furtherAvailable = false;
00080     for (LoaderVector::iterator i = myRouteLoaders.begin(); i != myRouteLoaders.end(); ++i) {
00081         (*i)->loadUntil(loadMaxTime);
00082         furtherAvailable |= (*i)->moreAvailable();
00083     }
00084     myAllLoaded = !furtherAvailable;
00085 }
00086 
00087 
00088 
00089 /****************************************************************************/
00090 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines