Eclipse SUMO - Simulation of Urban MObility
NIVissimSingleTypeParser_Knotendefinition.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 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>
25 #include <utils/geom/Position.h>
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
40  : NIImporter_Vissim::VissimSingleTypeParser(parent) {}
41 
42 
44 
45 
46 bool
48  //
49  int id;
50  from >> id;
51  //
52  std::string tag;
53  from >> tag;
54  std::string name = readName(from);
55  //
56  tag = overrideOptionalLabel(from);
57  //
58  while (tag != "netzausschnitt") {
59  tag = myRead(from);
60  }
61  //
62  tag = myRead(from);
63  if (tag == "strecke") {
65  while (tag == "strecke") {
66  int edgeid;
67  double from_pos, to_pos;
68  from_pos = to_pos = -1.0;
69  from >> edgeid;
70  tag = readEndSecure(from, "strecke");
71  if (tag == "von") {
72  from >> from_pos; // type-checking is missing!
73  from >> tag;
74  from >> to_pos; // type-checking is missing!
75  tag = readEndSecure(from, "strecke");
76  }
77  edges.push_back(new NIVissimNodeParticipatingEdge(edgeid, from_pos, to_pos));
78  }
79  NIVissimNodeDef_Edges::dictionary(id, name, edges);
80  } else {
81  int no = StringUtils::toInt(tag);
82  PositionVector poly;
83  for (int i = 0; i < no; i++) {
84  poly.push_back(getPosition(from));
85  }
86  poly.closePolygon();
87  NIVissimNodeDef_Poly::dictionary(id, name, poly);
88  }
89  return true;
90 }
91 
92 
93 /****************************************************************************/
std::vector< NIVissimNodeParticipatingEdge * > NIVissimNodeParticipatingEdgeVector
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.
static bool dictionary(int id, const std::string &name, const NIVissimNodeParticipatingEdgeVector &edges)
static bool dictionary(int id, const std::string &name, const PositionVector &poly)
NIVissimSingleTypeParser_Knotendefinition(NIImporter_Vissim &parent)
Constructor.
bool parse(std::istream &from)
Parses the data type from the given stream.
A list of positions.
void closePolygon()
ensures that the last position equals the first
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...