Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NIVissimSingleTypeParser_Fahrzeugtypdefinition.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-2023 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>
29
30
31// ===========================================================================
32// method definitions
33// ===========================================================================
38
39
41
42
43bool
45 // id
46 int id;
47 from >> id; // type-checking is missing!
48 // name
49 std::string tag;
50 from >> tag;
51 std::string name = readName(from);
52 // category
53 std::string category;
54 from >> tag;
55 from >> category;
56 // color (optional) and length
57 RGBColor color;
58 tag = myRead(from);
59 while (tag != "laenge") {
60 if (tag == "farbe") {
61 std::string colorName = myRead(from);
62 NIImporter_Vissim::ColorMap::iterator i = myColorMap.find(colorName);
63 if (i != myColorMap.end()) {
64 color = (*i).second;
65 } else {
66 int r, g, b;
67 r = StringUtils::toInt(colorName);
68 if (!(from >> g)) {
69 throw NumberFormatException("");
70 }
71 if (!(from >> b)) {
72 throw NumberFormatException("");
73 }
74 if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
75 throw NumberFormatException("");
76 }
77 color = RGBColor((unsigned char)r, (unsigned char)g, (unsigned char)b, 255);
78 }
79 }
80 tag = myRead(from);
81 }
82 double length;
83 from >> length;
84 // overread until "Maxbeschleunigung"
85 while (tag != "maxbeschleunigung") {
86 tag = myRead(from);
87 }
88 double amax;
89 from >> amax; // type-checking is missing!
90 // overread until "Maxverzoegerung"
91 while (tag != "maxverzoegerung") {
92 tag = myRead(from);
93 }
94 double dmax;
95 from >> dmax; // type-checking is missing!
96 while (tag != "besetzungsgrad") {
97 tag = myRead(from);
98 }
99 while (tag != "DATAEND") {
100 tag = readEndSecure(from, "verlustzeit");
101 }
102 return NIVissimVehicleType::dictionary(id, name, category, color);
103}
104
105
106/****************************************************************************/
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 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.
std::map< std::string, RGBColor > ColorMap
definition of a map from color names to color definitions
bool parse(std::istream &from)
Parses the data type from the given stream.
NIVissimSingleTypeParser_Fahrzeugtypdefinition(NIImporter_Vissim &parent, NIImporter_Vissim::ColorMap &colorMap)
Constructor.
static bool dictionary(int id, const std::string &name, const std::string &category, const RGBColor &color)
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...