NIVissimSingleTypeParser_Streckendefinition.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 //
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 <iostream>
00031 #include <utils/common/TplConvert.h>
00032 #include <utils/common/VectorHelper.h>
00033 #include <utils/geom/Position2DVector.h>
00034 #include "../NIImporter_Vissim.h"
00035 #include "../tempstructs/NIVissimEdge.h"
00036 #include "../tempstructs/NIVissimClosedLaneDef.h"
00037 #include "../tempstructs/NIVissimClosedLanesVector.h"
00038 #include "NIVissimSingleTypeParser_Streckendefinition.h"
00039 
00040 #ifdef CHECK_MEMORY_LEAKS
00041 #include <foreign/nvwa/debug_new.h>
00042 #endif // CHECK_MEMORY_LEAKS
00043 
00044 
00045 // ===========================================================================
00046 // method definitions
00047 // ===========================================================================
00048 NIVissimSingleTypeParser_Streckendefinition::NIVissimSingleTypeParser_Streckendefinition(NIImporter_Vissim &parent)
00049         : NIImporter_Vissim::VissimSingleTypeParser(parent) {}
00050 
00051 
00052 NIVissimSingleTypeParser_Streckendefinition::~NIVissimSingleTypeParser_Streckendefinition() {}
00053 
00054 
00055 bool
00056 NIVissimSingleTypeParser_Streckendefinition::parse(std::istream &from) {
00057     // read in the id
00058     int id;
00059     from >> id;
00060     //
00061     std::string tag;
00062     // the following elements may occure: "Name", "Beschriftung", "Typ",
00063     //  followed by the mandatory "Laenge"
00064     std::string name, label, type;
00065     SUMOReal length = -1;
00066     while (length<0) {
00067         tag = overrideOptionalLabel(from);
00068         if (tag=="name") {
00069             name = readName(from);
00070         } else if (tag=="typ") {
00071             type = myRead(from);
00072         } else if (tag=="laenge") {
00073             from >> length; // type-checking is missing!
00074         }
00075     }
00076     // read in the number of lanes
00077     int noLanes;
00078     tag = myRead(from);
00079     from >> noLanes;
00080     // skip some parameter, except optional "Zuschlag" until "Von" (mandatory)
00081     //  occurs
00082     SUMOReal zuschlag1, zuschlag2;
00083     zuschlag1 = zuschlag2 = 0;
00084     while (tag!="von") {
00085         tag = myRead(from);
00086         if (tag=="zuschlag") {
00087             from >> zuschlag1; // type-checking is missing!
00088             tag = myRead(from);
00089             if (tag=="zuschlag") {
00090                 from >> zuschlag2; // type-checking is missing!
00091             }
00092         }
00093     }
00094     // Read the geometry information
00095     Position2DVector geom;
00096     while (tag!="nach") {
00097         geom.push_back_noDoublePos(getPosition2D(from));
00098         tag = myRead(from);
00099         try {
00100             TplConvert<char>::_2SUMOReal(tag.c_str());
00101             tag = myRead(from);
00102         } catch (NumberFormatException &) {}
00103     }
00104     geom.push_back_noDoublePos(getPosition2D(from));
00105     // Read definitions of closed lanes
00106     NIVissimClosedLanesVector clv;
00107     // check whether a next close lane definition can be found
00108     tag = readEndSecure(from);
00109     while (tag!="DATAEND") {
00110         if (tag=="spur") {
00111             // get the lane number
00112             int laneNo;
00113             from >> laneNo; // type-checking is missing!
00114             // get the list of assigned car classes
00115             IntVector assignedVehicles;
00116             tag = myRead(from);
00117             tag = myRead(from);
00118             while (tag!="DATAEND"&&tag!="spur") {
00119                 int classes = TplConvert<char>::_2int(tag.c_str());
00120                 assignedVehicles.push_back(classes);
00121                 tag = readEndSecure(from);
00122             }
00123             // build and add the definition
00124             NIVissimClosedLaneDef *cld = new NIVissimClosedLaneDef(laneNo, assignedVehicles);
00125             clv.push_back(cld);
00126         } else {
00127             tag = readEndSecure(from);
00128         }
00129     }
00130     NIVissimEdge *e = new NIVissimEdge(id, name, type, noLanes,
00131                                        zuschlag1, zuschlag2, length, geom, clv);
00132     if (!NIVissimEdge::dictionary(id, e)) {
00133         return false;
00134     }
00135     return true;
00136     //return NIVissimAbstractEdge::dictionary(id, e);
00137 }
00138 
00139 
00140 
00141 /****************************************************************************/
00142 

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