SUMO - Simulation of Urban MObility
NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00009 //
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 <iostream>
00034 #include <utils/common/TplConvert.h>
00035 #include <utils/common/MsgHandler.h>
00036 #include "../NIImporter_Vissim.h"
00037 #include "../tempstructs/NIVissimExtendedEdgePoint.h"
00038 #include "../tempstructs/NIVissimDisturbance.h"
00039 #include "NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition.h"
00040 
00041 #ifdef CHECK_MEMORY_LEAKS
00042 #include <foreign/nvwa/debug_new.h>
00043 #endif // CHECK_MEMORY_LEAKS
00044 
00045 
00046 // ===========================================================================
00047 // method definitions
00048 // ===========================================================================
00049 NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition::NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition(NIImporter_Vissim& parent)
00050     : NIImporter_Vissim::VissimSingleTypeParser(parent) {}
00051 
00052 
00053 NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition::~NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition() {}
00054 
00055 
00056 bool
00057 NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition::parse(std::istream& from) {
00058     std::string tag;
00059     tag = myRead(from);
00060     if (tag == "nureigenestrecke") {
00061         return parseOnlyMe(from);
00062     } else if (tag == "ort") {
00063         return parsePositionDescribed(from);
00064     } else if (tag == "nummer") {
00065         return parseNumbered(from);
00066     }
00067     WRITE_ERROR(
00068         "NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition: format problem");
00069     throw 1;
00070 }
00071 
00072 bool
00073 NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition::parseOnlyMe(std::istream& from) {
00074     std::string tag;
00075     from >> tag;
00076     return true;
00077 }
00078 
00079 
00080 bool
00081 NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition::parsePositionDescribed(std::istream& from) {
00082     std::string tag = myRead(from);
00083     NIVissimExtendedEdgePoint edge = parsePos(from);
00084 //    from >> tag; // "Durch"
00085     bool ok = true;
00086     do {
00087         from >> tag; // "Strecke"
00088         NIVissimExtendedEdgePoint by = parsePos(from);
00089         //
00090         SUMOReal timegap;
00091         from >> timegap;
00092 
00093         from >> tag;
00094         SUMOReal waygap;
00095         from >> waygap;
00096 
00097         SUMOReal vmax = -1;
00098         tag = readEndSecure(from);
00099         if (tag == "vmax") {
00100             from >> vmax;
00101         }
00102         ok = NIVissimDisturbance::dictionary(-1, "", edge, by,
00103                                              timegap, waygap, vmax);
00104         if (tag != "DATAEND") {
00105             tag = readEndSecure(from);
00106         }
00107     } while (tag != "DATAEND" && ok);
00108     return ok;
00109 }
00110 
00111 
00112 
00113 bool
00114 NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition::parseNumbered(std::istream& from) {
00115     //
00116     int id;
00117     from >> id;
00118     //
00119     std::string tag;
00120     from >> tag;
00121     std::string name = readName(from);
00122     // skip optional "Beschriftung"
00123     while (tag != "ort") {
00124         tag = myRead(from);
00125     }
00126     //
00127     from >> tag; // "Strecke"
00128     NIVissimExtendedEdgePoint edge = parsePos(from);
00129     bool ok = true;
00130     do {
00131         from >> tag; // "Ort"
00132         from >> tag; // "Strecke"
00133         NIVissimExtendedEdgePoint by = parsePos(from);
00134         //
00135         SUMOReal timegap;
00136         from >> timegap;
00137 
00138         SUMOReal waygap;
00139         from >> tag;
00140         from >> waygap;
00141 
00142         SUMOReal vmax = -1;
00143         tag = readEndSecure(from);
00144         if (tag == "vmax") {
00145             from >> vmax;
00146         }
00147 
00148         ok = NIVissimDisturbance::dictionary(id, name, edge, by,
00149                                              timegap, waygap, vmax);
00150         if (tag != "DATAEND") {
00151             tag = readEndSecure(from);
00152         }
00153     } while (tag != "DATAEND" && ok);
00154     return ok;
00155 }
00156 
00157 
00158 
00159 NIVissimExtendedEdgePoint
00160 NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition::parsePos(std::istream& from) {
00161     int edgeid;
00162     from >> edgeid; // type-checking is missing!
00163     //
00164     std::string tag;
00165     from >> tag;
00166     from >> tag;
00167     std::vector<int> lanes;
00168     if (tag == "ALLE") {
00169         //lanes.push_back(1); // !!!
00170     } else {
00171         lanes.push_back(TplConvert<char>::_2int(tag.c_str()));
00172     }
00173     //
00174     SUMOReal position;
00175     from >> tag;
00176     from >> position;
00177     // assigned vehicle types
00178     std::vector<int> types;
00179     from >> tag;
00180     while (tag != "zeitluecke" && tag != "durch" && tag != "DATAEND" && tag != "alle") {
00181         tag = readEndSecure(from);
00182         if (tag != "DATAEND") {
00183             if (tag == "alle") {
00184                 types.push_back(-1);
00185                 from >> tag;
00186                 tag = "alle";
00187             } else if (tag != "zeitluecke" && tag != "durch" && tag != "DATAEND") {
00188                 int tmp = TplConvert<char>::_2int(tag.c_str());
00189                 types.push_back(tmp);
00190             }
00191         }
00192     }
00193     return NIVissimExtendedEdgePoint(edgeid, lanes, position, types);
00194 }
00195 
00196 
00197 
00198 /****************************************************************************/
00199 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines