MSXMLRawOut.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Realises dumping the complete network state
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 <cassert>
00031 #include <microsim/MSEdgeControl.h>
00032 #include <microsim/MSEdge.h>
00033 #include <microsim/MSLane.h>
00034 #include <microsim/MSGlobals.h>
00035 #include <utils/iodevices/OutputDevice.h>
00036 #include "MSXMLRawOut.h"
00037 
00038 #ifdef HAVE_MESOSIM
00039 #include <mesosim/MELoop.h>
00040 #endif
00041 
00042 #ifdef CHECK_MEMORY_LEAKS
00043 #include <foreign/nvwa/debug_new.h>
00044 #endif // CHECK_MEMORY_LEAKS
00045 
00046 
00047 // ===========================================================================
00048 // method definitions
00049 // ===========================================================================
00050 void
00051 MSXMLRawOut::write(OutputDevice &of, const MSEdgeControl &ec,
00052                    SUMOTime timestep) throw(IOError) {
00053     of.openTag("timestep") << " time=\"" << time2string(timestep) << "\">\n";
00054     const std::vector<MSEdge*> &edges = ec.getEdges();
00055     for (std::vector<MSEdge*>::const_iterator e=edges.begin(); e!=edges.end(); ++e) {
00056         writeEdge(of, **e);
00057     }
00058     of.closeTag();
00059 }
00060 
00061 
00062 void
00063 MSXMLRawOut::writeEdge(OutputDevice &of, const MSEdge &edge) throw(IOError) {
00064     //en
00065     bool dump = !MSGlobals::gOmitEmptyEdgesOnDump;
00066     if (!dump) {
00067 #ifdef HAVE_MESOSIM
00068         if (MSGlobals::gUseMesoSim) {
00069             MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
00070             while (seg != 0) {
00071                 if (seg->getCarNumber()!=0) {
00072                     dump = true;
00073                     break;
00074                 }
00075                 seg = seg->getNextSegment();
00076             }
00077         } else {
00078 #endif
00079             const std::vector<MSLane*> &lanes = edge.getLanes();
00080             for (std::vector<MSLane*>::const_iterator lane=lanes.begin(); lane!=lanes.end(); ++lane) {
00081                 if (((**lane).getVehicleNumber()!=0)) {
00082                     dump = true;
00083                     break;
00084                 }
00085             }
00086 #ifdef HAVE_MESOSIM
00087         }
00088 #endif
00089     }
00090     //en
00091     if (dump) {
00092         of.openTag("edge") << " id=\"" << edge.getID() << "\">\n";
00093 #ifdef HAVE_MESOSIM
00094         if (MSGlobals::gUseMesoSim) {
00095             MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge);
00096             while (seg != 0) {
00097                 seg->writeVehicles(of);
00098                 seg = seg->getNextSegment();
00099             }
00100         } else {
00101 #endif
00102             const std::vector<MSLane*> &lanes = edge.getLanes();
00103             for (std::vector<MSLane*>::const_iterator lane=lanes.begin(); lane!=lanes.end(); ++lane) {
00104                 writeLane(of, **lane);
00105             }
00106 #ifdef HAVE_MESOSIM
00107         }
00108 #endif
00109         of.closeTag();
00110     }
00111 }
00112 
00113 
00114 void
00115 MSXMLRawOut::writeLane(OutputDevice &of, const MSLane &lane) throw(IOError) {
00116     of.openTag("lane") << " id=\"" << lane.myID << "\"";
00117     if (lane.getVehicleNumber()!=0) {
00118         of << ">\n";
00119         for (std::vector<MSVehicle*>::const_iterator veh = lane.myVehBuffer.begin();
00120                 veh != lane.myVehBuffer.end(); ++veh) {
00121             writeVehicle(of, **veh);
00122         }
00123         for (MSLane::VehCont::const_iterator veh = lane.myVehicles.begin();
00124                 veh != lane.myVehicles.end(); ++veh) {
00125             writeVehicle(of, **veh);
00126         }
00127     }
00128     of.closeTag(lane.getVehicleNumber()==0);
00129 }
00130 
00131 
00132 void
00133 MSXMLRawOut::writeVehicle(OutputDevice &of, const SUMOVehicle &veh) throw(IOError) {
00134     of.openTag("vehicle") << " id=\"" << veh.getID() << "\" pos=\""
00135     << veh.getPositionOnLane() << "\" speed=\"" << veh.getSpeed() << "\"";
00136     of.closeTag(true);
00137 }
00138 
00139 
00140 
00141 /****************************************************************************/
00142 

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