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