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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <iostream>
35 #include "../NIImporter_Vissim.h"
36 #include "../tempstructs/NIVissimEdge.h"
37 #include "../tempstructs/NIVissimClosedLaneDef.h"
38 #include "../tempstructs/NIVissimClosedLanesVector.h"
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
46  : NIImporter_Vissim::VissimSingleTypeParser(parent) {}
47 
48 
50 
51 
52 bool
54  // read in the id
55  int id;
56  from >> id;
57  //
58  std::string tag;
59  // the following elements may occure: "Name", "Beschriftung", "Typ",
60  // followed by the mandatory "Laenge"
61  std::string name, label, type;
62  double length = -1;
63  while (length < 0) {
64  tag = overrideOptionalLabel(from);
65  if (tag == "name") {
66  name = readName(from);
67  } else if (tag == "typ") {
68  type = myRead(from);
69  } else if (tag == "laenge") {
70  from >> length; // type-checking is missing!
71  }
72  }
73  // read in the number of lanes
74  int noLanes;
75  tag = myRead(from);
76  from >> noLanes;
77  // skip some parameter, except optional "Zuschlag" until "Von" (mandatory)
78  // occurs
79  double zuschlag1, zuschlag2;
80  zuschlag1 = zuschlag2 = 0;
81  while (tag != "von") {
82  tag = myRead(from);
83  if (tag == "zuschlag") {
84  from >> zuschlag1; // type-checking is missing!
85  tag = myRead(from);
86  if (tag == "zuschlag") {
87  from >> zuschlag2; // type-checking is missing!
88  }
89  }
90  }
91  // Read the geometry information
92  PositionVector geom;
93  while (tag != "nach") {
95  tag = myRead(from);
96  try {
97  TplConvert::_2double(tag.c_str());
98  tag = myRead(from);
99  } catch (NumberFormatException&) {}
100  }
102  // Read definitions of closed lanes
104  // check whether a next close lane definition can be found
105  tag = readEndSecure(from);
106  while (tag != "DATAEND") {
107  if (tag == "keinspurwechsel") {
108  while (tag != "DATAEND") {
109  tag = readEndSecure(from);
110  }
111  } else if (tag == "spur") {
112  // get the lane number
113  int laneNo;
114  from >> laneNo; // unused and type-checking is missing!
115  // get the list of assigned car classes
116  std::vector<int> assignedVehicles;
117  tag = myRead(from);
118  tag = myRead(from);
119  while (tag != "DATAEND" && tag != "spur" && tag != "keinspurwechsel") {
120  int classes = TplConvert::_2int(tag.c_str());
121  assignedVehicles.push_back(classes);
122  tag = readEndSecure(from);
123  }
124  // build and add the definition
125  NIVissimClosedLaneDef* cld = new NIVissimClosedLaneDef(assignedVehicles);
126  clv.push_back(cld);
127  } else {
128  tag = readEndSecure(from);
129  }
130  }
131  NIVissimEdge* e = new NIVissimEdge(id, name, type, noLanes,
132  zuschlag1, zuschlag2, length, geom, clv);
133  if (!NIVissimEdge::dictionary(id, e)) {
134  return false;
135  }
136  return true;
137  //return NIVissimAbstractEdge::dictionary(id, e);
138 }
139 
140 
141 
142 /****************************************************************************/
143 
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:59
A list of positions.
Position getPosition(std::istream &from)
returns the 2d-position saved as next within the stream
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...
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:155
bool parse(std::istream &from)
Parses the data type from the given stream.
static double _2double(const E *const data)
converts a char-type array into the double value described by it
Definition: TplConvert.h:311
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 ...