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