MSRouteLoaderControl.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Class responsible for loading of routes from some files
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 <vector>
00031 #include "MSRouteLoader.h"
00032 #include "MSRouteLoaderControl.h"
00033 
00034 #ifdef CHECK_MEMORY_LEAKS
00035 #include <foreign/nvwa/debug_new.h>
00036 #endif // CHECK_MEMORY_LEAKS
00037 
00038 
00039 // ===========================================================================
00040 // method definitions
00041 // ===========================================================================
00042 MSRouteLoaderControl::MSRouteLoaderControl(MSNet &,
00043         int inAdvanceStepNo,
00044         LoaderVector loader)
00045         : myLastLoadTime(-inAdvanceStepNo),
00046         myInAdvanceStepNo(inAdvanceStepNo),
00047         myRouteLoaders(loader),
00048         myAllLoaded(false) {
00049     myLoadAll = myInAdvanceStepNo<=0;
00050     myAllLoaded = false;
00051     myLastLoadTime = -1 * (int) myInAdvanceStepNo;
00052     // initialize all used loaders
00053     for (LoaderVector::iterator i=myRouteLoaders.begin();
00054             i!=myRouteLoaders.end(); ++i) {
00055         (*i)->init();
00056     }
00057 }
00058 
00059 
00060 MSRouteLoaderControl::~MSRouteLoaderControl() {
00061     for (LoaderVector::iterator i=myRouteLoaders.begin();
00062             i!=myRouteLoaders.end(); ++i) {
00063         delete(*i);
00064     }
00065 }
00066 
00067 
00068 void
00069 MSRouteLoaderControl::loadNext(SUMOTime step, MSEmitControl* into) {
00070     // check whether new vehicles shall be loaded
00071     //  return if not
00072     if ((myLoadAll&&myAllLoaded) || (myLastLoadTime>=0&&myLastLoadTime/*+myInAdvanceStepNo*/>=step)) {
00073         return;
00074     }
00075     // load all routes for the specified time period
00076     SUMOTime run = step;
00077     bool furtherAvailable = true;
00078     for (;
00079             furtherAvailable &&
00080             (myLoadAll||run<=step+(SUMOTime) myInAdvanceStepNo);
00081             run++) {
00082         furtherAvailable = false;
00083         for (LoaderVector::iterator i=myRouteLoaders.begin();
00084                 i!=myRouteLoaders.end(); ++i) {
00085             if ((*i)->moreAvailable()) {
00086                 (*i)->loadUntil(run, into);
00087             }
00088             furtherAvailable |= (*i)->moreAvailable();
00089         }
00090     }
00091     // no further loading when all was loaded
00092     if (myLoadAll||!furtherAvailable) {
00093         myAllLoaded = true;
00094     }
00095     // set the step information
00096     myLastLoadTime = run - 1;
00097 }
00098 
00099 
00100 
00101 /****************************************************************************/
00102 

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