SUMO - Simulation of Urban MObility

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 (C) 2001-2011 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/PositionVector.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     PositionVector geom;
00096     while (tag!="nach") {
00097         geom.push_back_noDoublePos(getPosition(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(getPosition(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=="keinspurwechsel") {
00111             while (tag!="DATAEND") {
00112                 tag = readEndSecure(from);
00113             }
00114         } else if (tag=="spur") {
00115             // get the lane number
00116             int laneNo;
00117             from >> laneNo; // type-checking is missing!
00118             // get the list of assigned car classes
00119             IntVector assignedVehicles;
00120             tag = myRead(from);
00121             tag = myRead(from);
00122             while (tag!="DATAEND"&&tag!="spur"&&tag!="keinspurwechsel") {
00123                 int classes = TplConvert<char>::_2int(tag.c_str());
00124                 assignedVehicles.push_back(classes);
00125                 tag = readEndSecure(from);
00126             }
00127             // build and add the definition
00128             NIVissimClosedLaneDef* cld = new NIVissimClosedLaneDef(laneNo, assignedVehicles);
00129             clv.push_back(cld);
00130         } else {
00131             tag = readEndSecure(from);
00132         }
00133     }
00134     NIVissimEdge* e = new NIVissimEdge(id, name, type, noLanes,
00135                                        zuschlag1, zuschlag2, length, geom, clv);
00136     if (!NIVissimEdge::dictionary(id, e)) {
00137         return false;
00138     }
00139     return true;
00140     //return NIVissimAbstractEdge::dictionary(id, e);
00141 }
00142 
00143 
00144 
00145 /****************************************************************************/
00146 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines