Eclipse SUMO - Simulation of Urban MObility
NIVissimSingleTypeParser_Streckendefinition.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
19//
20/****************************************************************************/
21#include <config.h>
22
23#include <iostream>
32
33
34// ===========================================================================
35// method definitions
36// ===========================================================================
38 : NIImporter_Vissim::VissimSingleTypeParser(parent) {}
39
40
42
43
44bool
46 // read in the id
47 int id;
48 from >> id;
49 //
50 std::string tag;
51 // the following elements may occure: "Name", "Beschriftung", "Typ",
52 // followed by the mandatory "Laenge"
53 std::string name, label, type;
54 double length = -1;
55 while (length < 0) {
56 tag = overrideOptionalLabel(from);
57 if (tag == "name") {
58 name = readName(from);
59 } else if (tag == "typ") {
60 type = myRead(from);
61 } else if (tag == "laenge") {
62 from >> length; // type-checking is missing!
63 }
64 }
65 // read in the number of lanes
66 int noLanes;
67 tag = myRead(from);
68 from >> noLanes;
69 // skip some parameter, except optional "Zuschlag" until "Von" (mandatory)
70 // occurs
71 double zuschlag1, zuschlag2;
72 zuschlag1 = zuschlag2 = 0;
73 while (tag != "von") {
74 tag = myRead(from);
75 if (tag == "zuschlag") {
76 from >> zuschlag1; // type-checking is missing!
77 tag = myRead(from);
78 if (tag == "zuschlag") {
79 from >> zuschlag2; // type-checking is missing!
80 }
81 }
82 }
83 // Read the geometry information
84 PositionVector geom;
85 while (tag != "nach") {
87 tag = myRead(from);
88 try {
90 tag = myRead(from);
91 } catch (NumberFormatException&) {}
92 }
94 // Read definitions of closed lanes
96 // check whether a next close lane definition can be found
97 tag = readEndSecure(from);
98 while (tag != "DATAEND") {
99 if (tag == "keinspurwechsel") {
100 while (tag != "DATAEND") {
101 tag = readEndSecure(from);
102 }
103 } else if (tag == "spur") {
104 // get the lane number
105 int laneNo;
106 from >> laneNo; // unused and type-checking is missing!
107 // get the list of assigned car classes
108 std::vector<int> assignedVehicles;
109 tag = myRead(from);
110 tag = myRead(from);
111 while (tag != "DATAEND" && tag != "spur" && tag != "keinspurwechsel") {
112 int classes = StringUtils::toInt(tag);
113 assignedVehicles.push_back(classes);
114 tag = readEndSecure(from);
115 }
116 // build and add the definition
117 NIVissimClosedLaneDef* cld = new NIVissimClosedLaneDef(assignedVehicles);
118 clv.push_back(cld);
119 } else {
120 tag = readEndSecure(from);
121 }
122 }
123 NIVissimEdge* e = new NIVissimEdge(id, name, type, std::vector<double>(noLanes, NBEdge::UNSPECIFIED_WIDTH),
124 zuschlag1, zuschlag2, length, geom, clv);
125 if (!NIVissimEdge::dictionary(id, e)) {
126 return false;
127 }
128 return true;
129 //return NIVissimAbstractEdge::dictionary(id, e);
130}
131
132
133/****************************************************************************/
std::vector< NIVissimClosedLaneDef * > NIVissimClosedLanesVector
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:357
Position getPosition(std::istream &from)
returns the 2d-position saved as next within the stream
std::string readEndSecure(std::istream &from, const std::string &excl="")
as myRead, but returns "DATAEND" when the current field has ended
std::string readName(std::istream &from)
Reads the structures name We cannot use the "<<" operator, as names may contain more than one word wh...
std::string overrideOptionalLabel(std::istream &from, const std::string &tag="")
overrides the optional label definition; returns the next tag as done by readEndSecure
std::string myRead(std::istream &from)
reads from the stream and returns the lower case version of the read value
Importer for networks stored in Vissim format.
A temporary storage for edges imported from Vissim.
Definition: NIVissimEdge.h:51
static bool dictionary(int id, const std::string &name, const std::string &type, int noLanes, double zuschlag1, double zuschlag2, double length, const PositionVector &geom, const NIVissimClosedLanesVector &clv)
Adds the described item to the dictionary Builds the edge first.
NIVissimSingleTypeParser_Streckendefinition(NIImporter_Vissim &parent)
Constructor.
bool parse(std::istream &from)
Parses the data type from the given stream.
A list of positions.
void push_back_noDoublePos(const Position &p)
insert in back a non double position
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...