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 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <iostream>
28 #include "../NIImporter_Vissim.h"
29 #include "../tempstructs/NIVissimEdge.h"
30 #include "../tempstructs/NIVissimClosedLaneDef.h"
31 #include "../tempstructs/NIVissimClosedLanesVector.h"
33 
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
39  : NIImporter_Vissim::VissimSingleTypeParser(parent) {}
40 
41 
43 
44 
45 bool
47  // read in the id
48  int id;
49  from >> id;
50  //
51  std::string tag;
52  // the following elements may occure: "Name", "Beschriftung", "Typ",
53  // followed by the mandatory "Laenge"
54  std::string name, label, type;
55  double length = -1;
56  while (length < 0) {
57  tag = overrideOptionalLabel(from);
58  if (tag == "name") {
59  name = readName(from);
60  } else if (tag == "typ") {
61  type = myRead(from);
62  } else if (tag == "laenge") {
63  from >> length; // type-checking is missing!
64  }
65  }
66  // read in the number of lanes
67  int noLanes;
68  tag = myRead(from);
69  from >> noLanes;
70  // skip some parameter, except optional "Zuschlag" until "Von" (mandatory)
71  // occurs
72  double zuschlag1, zuschlag2;
73  zuschlag1 = zuschlag2 = 0;
74  while (tag != "von") {
75  tag = myRead(from);
76  if (tag == "zuschlag") {
77  from >> zuschlag1; // type-checking is missing!
78  tag = myRead(from);
79  if (tag == "zuschlag") {
80  from >> zuschlag2; // type-checking is missing!
81  }
82  }
83  }
84  // Read the geometry information
85  PositionVector geom;
86  while (tag != "nach") {
88  tag = myRead(from);
89  try {
91  tag = myRead(from);
92  } catch (NumberFormatException&) {}
93  }
95  // Read definitions of closed lanes
97  // check whether a next close lane definition can be found
98  tag = readEndSecure(from);
99  while (tag != "DATAEND") {
100  if (tag == "keinspurwechsel") {
101  while (tag != "DATAEND") {
102  tag = readEndSecure(from);
103  }
104  } else if (tag == "spur") {
105  // get the lane number
106  int laneNo;
107  from >> laneNo; // unused and type-checking is missing!
108  // get the list of assigned car classes
109  std::vector<int> assignedVehicles;
110  tag = myRead(from);
111  tag = myRead(from);
112  while (tag != "DATAEND" && tag != "spur" && tag != "keinspurwechsel") {
113  int classes = StringUtils::toInt(tag);
114  assignedVehicles.push_back(classes);
115  tag = readEndSecure(from);
116  }
117  // build and add the definition
118  NIVissimClosedLaneDef* cld = new NIVissimClosedLaneDef(assignedVehicles);
119  clv.push_back(cld);
120  } else {
121  tag = readEndSecure(from);
122  }
123  }
124  NIVissimEdge* e = new NIVissimEdge(id, name, type, std::vector<double>(noLanes, NBEdge::UNSPECIFIED_WIDTH),
125  zuschlag1, zuschlag2, length, geom, clv);
126  if (!NIVissimEdge::dictionary(id, e)) {
127  return false;
128  }
129  return true;
130  //return NIVissimAbstractEdge::dictionary(id, e);
131 }
132 
133 
134 
135 /****************************************************************************/
136 
NIVissimClosedLanesVector
std::vector< NIVissimClosedLaneDef * > NIVissimClosedLanesVector
Definition: NIVissimClosedLanesVector.h:29
NIVissimClosedLaneDef
Definition: NIVissimClosedLaneDef.h:34
NIVissimEdge
A temporary storage for edges imported from Vissim.
Definition: NIVissimEdge.h:52
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:345
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:797
NIImporter_Vissim
Importer for networks stored in Vissim format.
Definition: NIImporter_Vissim.h:58
NIImporter_Vissim::VissimSingleTypeParser::getPosition
Position getPosition(std::istream &from)
returns the 2d-position saved as next within the stream
Definition: NIImporter_Vissim.cpp:748
NIVissimSingleTypeParser_Streckendefinition::NIVissimSingleTypeParser_Streckendefinition
NIVissimSingleTypeParser_Streckendefinition(NIImporter_Vissim &parent)
Constructor.
Definition: NIVissimSingleTypeParser_Streckendefinition.cpp:38
PositionVector
A list of positions.
Definition: PositionVector.h:45
NIVissimSingleTypeParser_Streckendefinition.h
NIVissimSingleTypeParser_Streckendefinition::parse
bool parse(std::istream &from)
Parses the data type from the given stream.
Definition: NIVissimSingleTypeParser_Streckendefinition.cpp:46
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:138
NumberFormatException
Definition: UtilExceptions.h:95
VectorHelper.h
PositionVector::push_back_noDoublePos
void push_back_noDoublePos(const Position &p)
insert in back a non double position
Definition: PositionVector.cpp:1295
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:679
NIVissimSingleTypeParser_Streckendefinition::~NIVissimSingleTypeParser_Streckendefinition
~NIVissimSingleTypeParser_Streckendefinition()
Destructor.
Definition: NIVissimSingleTypeParser_Streckendefinition.cpp:42
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:278
NBEdge::UNSPECIFIED_WIDTH
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:315
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:727
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:670
PositionVector.h