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-2018 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, noLanes,
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 
NIVissimSingleTypeParser_Streckendefinition(NIImporter_Vissim &parent)
Constructor.
std::string myRead(std::istream &from)
reads from the stream and returns the lower case version of the read value
std::string readEndSecure(std::istream &from, const std::string &excl="")
as myRead, but returns "DATAEND" when the current field has ended
std::vector< NIVissimClosedLaneDef * > NIVissimClosedLanesVector
Importer for networks stored in Vissim format.
A temporary storage for edges imported from Vissim.
Definition: NIVissimEdge.h:53
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
A list of positions.
Position getPosition(std::istream &from)
returns the 2d-position saved as next within the stream
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
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.
std::string readName(std::istream &from)
Reads the structures name We cannot use the "<<" operator, as names may contain more than one word wh...
bool parse(std::istream &from)
Parses the data type from the given stream.
void push_back_noDoublePos(const Position &p)
insert in back a non double position
std::string overrideOptionalLabel(std::istream &from, const std::string &tag="")
overrides the optional label definition; returns the next tag as done by readEndSecure ...