SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ROVehicle.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A vehicle as used by router
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
34 #include <utils/common/ToString.h>
39 #include <string>
40 #include <iostream>
41 #include "RORouteDef.h"
42 #include "ROVehicle.h"
43 #include "RORoute.h"
44 #include "ROHelper.h"
45 
46 #ifdef CHECK_MEMORY_LEAKS
47 #include <foreign/nvwa/debug_new.h>
48 #endif // CHECK_MEMORY_LEAKS
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
55  RORouteDef* route, const SUMOVTypeParameter* type)
56  : myParameter(pars), myType(type), myRoute(route) {}
57 
58 
60 
61 
62 void
64  OutputDevice* const typeos, bool withExitTimes) const {
65  // check whether the vehicle's type was saved before
66  if (myType != 0 && !myType->saved) {
67  // ... save if not
68  if (typeos != 0) {
69  myType->write(*typeos);
70  } else {
71  myType->write(os);
72  if (altos != 0) {
73  myType->write(*altos);
74  }
75  }
76  myType->saved = true;
77  }
78 
79  // write the vehicle (new style, with included routes)
81  if (altos != 0) {
83  }
84 
85  // check whether the route shall be saved
86  if (!myRoute->isSaved()) {
87  myRoute->writeXMLDefinition(os, this, false, withExitTimes);
88  if (altos != 0) {
89  myRoute->writeXMLDefinition(*altos, this, true, withExitTimes);
90  }
91  }
93  if (altos != 0) {
94  myParameter.writeStops(*altos);
95  }
96  os.closeTag();
97  if (altos != 0) {
98  altos->closeTag();
99  }
100 }
101 
102 
103 SUMOReal
105  return myType->maxSpeed;
106 }
107 
108 
109 ROVehicle*
110 ROVehicle::copy(const std::string& id, unsigned int depTime,
111  RORouteDef* newRoute) const {
113  pars.id = id;
114  pars.depart = depTime;
115  return new ROVehicle(pars, newRoute, myType);
116 }
117 
118 
119 /****************************************************************************/
120 
SUMOVehicleParameter myParameter
The vehicle&#39;s parameter.
Definition: ROVehicle.h:152
void writeStops(OutputDevice &dev) const
Writes the enclosed stops.
Structure representing possible vehicle parameter.
bool saved
Information whether this type was already saved (needed by routers)
bool isSaved() const
Returns the information whether this item was already saved.
SUMOReal getMaxSpeed() const
Returns the vehicle&#39;s maximum speed.
Definition: ROVehicle.cpp:104
RORouteDef *const myRoute
The route the vehicle takes.
Definition: ROVehicle.h:158
void saveAllAsXML(OutputDevice &os, OutputDevice *const altos, OutputDevice *const typeos, bool withExitTimes) const
Saves the complete vehicle description.
Definition: ROVehicle.cpp:63
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
A vehicle as used by router.
Definition: ROVehicle.h:57
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, bool asAlternatives, bool withExitTimes) const
Saves the built route / route alternatives.
Definition: RORouteDef.cpp:323
SUMOTime depart
The vehicle&#39;s departure time.
const SUMOVTypeParameter *const myType
The type of the vehicle.
Definition: ROVehicle.h:155
void write(OutputDevice &dev) const
Writes the vtype.
SUMOReal maxSpeed
The vehicle type&#39;s maximum speed [m/s].
Structure representing possible vehicle parameter.
ROVehicle(const SUMOVehicleParameter &pars, RORouteDef *route, const SUMOVTypeParameter *type)
Constructor.
Definition: ROVehicle.cpp:54
Base class for a vehicle&#39;s route definition.
Definition: RORouteDef.h:63
void write(OutputDevice &dev, const OptionsCont &oc) const
Writes the parameters as a beginning element.
virtual ROVehicle * copy(const std::string &id, unsigned int depTime, RORouteDef *newRoute) const
Returns a copy of the vehicle using a new id, departure time and route.
Definition: ROVehicle.cpp:110
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:221
virtual ~ROVehicle()
Destructor.
Definition: ROVehicle.cpp:59
std::string id
The vehicle&#39;s id.