SUMO - Simulation of Urban MObility

ROVehicle.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00009 // A vehicle as used by router
00010 /****************************************************************************/
00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00013 /****************************************************************************/
00014 //
00015 //   This file is part of SUMO.
00016 //   SUMO is free software: you can redistribute it and/or modify
00017 //   it under the terms of the GNU General Public License as published by
00018 //   the Free Software Foundation, either version 3 of the License, or
00019 //   (at your option) any later version.
00020 //
00021 /****************************************************************************/
00022 
00023 
00024 // ===========================================================================
00025 // included modules
00026 // ===========================================================================
00027 #ifdef _MSC_VER
00028 #include <windows_config.h>
00029 #else
00030 #include <config.h>
00031 #endif
00032 
00033 #include <utils/common/TplConvert.h>
00034 #include <utils/common/ToString.h>
00035 #include <utils/common/MsgHandler.h>
00036 #include <utils/common/SUMOVTypeParameter.h>
00037 #include <utils/options/OptionsCont.h>
00038 #include <utils/iodevices/OutputDevice.h>
00039 #include <string>
00040 #include <iostream>
00041 #include "RORouteDef.h"
00042 #include "ROVehicle.h"
00043 #include "RORouteDef_Alternatives.h"
00044 #include "RORoute.h"
00045 #include "ROHelper.h"
00046 
00047 #ifdef CHECK_MEMORY_LEAKS
00048 #include <foreign/nvwa/debug_new.h>
00049 #endif // CHECK_MEMORY_LEAKS
00050 
00051 
00052 // ===========================================================================
00053 // method definitions
00054 // ===========================================================================
00055 ROVehicle::ROVehicle(const SUMOVehicleParameter& pars,
00056                      RORouteDef* route, SUMOVTypeParameter* type)
00057     : myParameter(pars), myType(type), myRoute(route) {}
00058 
00059 
00060 ROVehicle::~ROVehicle() {}
00061 
00062 
00063 void
00064 ROVehicle::saveAllAsXML(SUMOAbstractRouter<ROEdge, ROVehicle> &router, OutputDevice& os,
00065                         OutputDevice* const altos, bool withExitTimes) const {
00066     // check whether the vehicle's type was saved before
00067     if (myType != 0 && !myType->saved) {
00068         // ... save if not
00069         myType->write(os);
00070         if (altos != 0) {
00071             myType->write(*altos);
00072         }
00073         myType->saved = true;
00074     }
00075 
00076     // write the vehicle (new style, with included routes)
00077     myParameter.writeAs("vehicle", os, OptionsCont::getOptions());
00078     if (altos != 0) {
00079         myParameter.writeAs("vehicle", *altos, OptionsCont::getOptions());
00080     }
00081 
00082     // check whether the route shall be saved
00083     if (!myRoute->isSaved()) {
00084         myRoute->writeXMLDefinition(router, os, this, false, withExitTimes);
00085         if (altos != 0) {
00086             myRoute->writeXMLDefinition(router, *altos, this, true, withExitTimes);
00087         }
00088     }
00089     os.closeTag();
00090     if (altos != 0) {
00091         altos->closeTag();
00092     }
00093 }
00094 
00095 
00096 ROVehicle*
00097 ROVehicle::copy(const std::string& id, unsigned int depTime,
00098                 RORouteDef* newRoute) {
00099     SUMOVehicleParameter pars(myParameter);
00100     pars.id = id;
00101     pars.depart = depTime;
00102     return new ROVehicle(pars, newRoute, myType);
00103 }
00104 
00105 
00106 /****************************************************************************/
00107 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines