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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 //
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <iostream>
29 #include "../NIImporter_Vissim.h"
30 #include "../tempstructs/NIVissimEdge.h"
31 #include "../tempstructs/NIVissimClosedLaneDef.h"
32 #include "../tempstructs/NIVissimClosedLanesVector.h"
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
40  : NIImporter_Vissim::VissimSingleTypeParser(parent) {}
41 
42 
44 
45 
46 bool
48  // read in the id
49  int id;
50  from >> id;
51  //
52  std::string tag;
53  // the following elements may occure: "Name", "Beschriftung", "Typ",
54  // followed by the mandatory "Laenge"
55  std::string name, label, type;
56  double length = -1;
57  while (length < 0) {
58  tag = overrideOptionalLabel(from);
59  if (tag == "name") {
60  name = readName(from);
61  } else if (tag == "typ") {
62  type = myRead(from);
63  } else if (tag == "laenge") {
64  from >> length; // type-checking is missing!
65  }
66  }
67  // read in the number of lanes
68  int noLanes;
69  tag = myRead(from);
70  from >> noLanes;
71  // skip some parameter, except optional "Zuschlag" until "Von" (mandatory)
72  // occurs
73  double zuschlag1, zuschlag2;
74  zuschlag1 = zuschlag2 = 0;
75  while (tag != "von") {
76  tag = myRead(from);
77  if (tag == "zuschlag") {
78  from >> zuschlag1; // type-checking is missing!
79  tag = myRead(from);
80  if (tag == "zuschlag") {
81  from >> zuschlag2; // type-checking is missing!
82  }
83  }
84  }
85  // Read the geometry information
86  PositionVector geom;
87  while (tag != "nach") {
89  tag = myRead(from);
90  try {
92  tag = myRead(from);
93  } catch (NumberFormatException&) {}
94  }
96  // Read definitions of closed lanes
98  // check whether a next close lane definition can be found
99  tag = readEndSecure(from);
100  while (tag != "DATAEND") {
101  if (tag == "keinspurwechsel") {
102  while (tag != "DATAEND") {
103  tag = readEndSecure(from);
104  }
105  } else if (tag == "spur") {
106  // get the lane number
107  int laneNo;
108  from >> laneNo; // unused and type-checking is missing!
109  // get the list of assigned car classes
110  std::vector<int> assignedVehicles;
111  tag = myRead(from);
112  tag = myRead(from);
113  while (tag != "DATAEND" && tag != "spur" && tag != "keinspurwechsel") {
114  int classes = StringUtils::toInt(tag);
115  assignedVehicles.push_back(classes);
116  tag = readEndSecure(from);
117  }
118  // build and add the definition
119  NIVissimClosedLaneDef* cld = new NIVissimClosedLaneDef(assignedVehicles);
120  clv.push_back(cld);
121  } else {
122  tag = readEndSecure(from);
123  }
124  }
125  NIVissimEdge* e = new NIVissimEdge(id, name, type, std::vector<double>(noLanes, NBEdge::UNSPECIFIED_WIDTH),
126  zuschlag1, zuschlag2, length, geom, clv);
127  if (!NIVissimEdge::dictionary(id, e)) {
128  return false;
129  }
130  return true;
131  //return NIVissimAbstractEdge::dictionary(id, e);
132 }
133 
134 
135 
136 /****************************************************************************/
137 
NIVissimClosedLanesVector
std::vector< NIVissimClosedLaneDef * > NIVissimClosedLanesVector
Definition: NIVissimClosedLanesVector.h:30
NIVissimClosedLaneDef
Definition: NIVissimClosedLaneDef.h:35
NIVissimEdge
A temporary storage for edges imported from Vissim.
Definition: NIVissimEdge.h:53
StringUtils::toDouble
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
Definition: StringUtils.cpp:313
NIImporter_Vissim::VissimSingleTypeParser::readName
std::string readName(std::istream &from)
Reads the structures name We cannot use the "<<" operator, as names may contain more than one word wh...
Definition: NIImporter_Vissim.cpp:798
NIImporter_Vissim
Importer for networks stored in Vissim format.
Definition: NIImporter_Vissim.h:59
NIImporter_Vissim::VissimSingleTypeParser::getPosition
Position getPosition(std::istream &from)
returns the 2d-position saved as next within the stream
Definition: NIImporter_Vissim.cpp:749
NIVissimSingleTypeParser_Streckendefinition::NIVissimSingleTypeParser_Streckendefinition
NIVissimSingleTypeParser_Streckendefinition(NIImporter_Vissim &parent)
Constructor.
Definition: NIVissimSingleTypeParser_Streckendefinition.cpp:39
PositionVector
A list of positions.
Definition: PositionVector.h:46
NIVissimSingleTypeParser_Streckendefinition.h
NIVissimSingleTypeParser_Streckendefinition::parse
bool parse(std::istream &from)
Parses the data type from the given stream.
Definition: NIVissimSingleTypeParser_Streckendefinition.cpp:47
NIVissimEdge::dictionary
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.
Definition: NIVissimEdge.cpp:139
NumberFormatException
Definition: UtilExceptions.h:96
VectorHelper.h
PositionVector::push_back_noDoublePos
void push_back_noDoublePos(const Position &p)
insert in back a non double position
Definition: PositionVector.cpp:1258
NIImporter_Vissim::VissimSingleTypeParser::readEndSecure
std::string readEndSecure(std::istream &from, const std::string &excl="")
as myRead, but returns "DATAEND" when the current field has ended
Definition: NIImporter_Vissim.cpp:680
NIVissimSingleTypeParser_Streckendefinition::~NIVissimSingleTypeParser_Streckendefinition
~NIVissimSingleTypeParser_Streckendefinition()
Destructor.
Definition: NIVissimSingleTypeParser_Streckendefinition.cpp:43
StringUtils.h
StringUtils::toInt
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
Definition: StringUtils.cpp:246
NBEdge::UNSPECIFIED_WIDTH
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:303
NIImporter_Vissim::VissimSingleTypeParser::overrideOptionalLabel
std::string overrideOptionalLabel(std::istream &from, const std::string &tag="")
overrides the optional label definition; returns the next tag as done by readEndSecure
Definition: NIImporter_Vissim.cpp:728
config.h
NIImporter_Vissim::VissimSingleTypeParser::myRead
std::string myRead(std::istream &from)
reads from the stream and returns the lower case version of the read value
Definition: NIImporter_Vissim.cpp:671
PositionVector.h