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-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>
33 #include <utils/common/ToString.h>
34 #include "../NIImporter_Vissim.h"
35 #include "../tempstructs/NIVissimVehicleType.h"
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
44  : NIImporter_Vissim::VissimSingleTypeParser(parent),
45  myColorMap(colorMap) {}
46 
47 
49 
50 
51 bool
53  // id
54  int id;
55  from >> id; // type-checking is missing!
56  // name
57  std::string tag;
58  from >> tag;
59  std::string name = readName(from);
60  // category
61  std::string category;
62  from >> tag;
63  from >> category;
64  // color (optional) and length
65  RGBColor color;
66  tag = myRead(from);
67  while (tag != "laenge") {
68  if (tag == "farbe") {
69  std::string colorName = myRead(from);
70  NIImporter_Vissim::ColorMap::iterator i = myColorMap.find(colorName);
71  if (i != myColorMap.end()) {
72  color = (*i).second;
73  } else {
74  int r, g, b;
75  r = TplConvert::_2int(colorName.c_str());
76  if (!(from >> g)) {
77  throw NumberFormatException();
78  }
79  if (!(from >> b)) {
80  throw NumberFormatException();
81  }
82  if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
83  throw NumberFormatException();
84  }
85  color = RGBColor((unsigned char)r, (unsigned char)g, (unsigned char)b, 255);
86  }
87  }
88  tag = myRead(from);
89  }
90  double length;
91  from >> length;
92  // overread until "Maxbeschleunigung"
93  while (tag != "maxbeschleunigung") {
94  tag = myRead(from);
95  }
96  double amax;
97  from >> amax; // type-checking is missing!
98  // overread until "Maxverzoegerung"
99  while (tag != "maxverzoegerung") {
100  tag = myRead(from);
101  }
102  double dmax;
103  from >> dmax; // type-checking is missing!
104  while (tag != "besetzungsgrad") {
105  tag = myRead(from);
106  }
107  while (tag != "DATAEND") {
108  tag = readEndSecure(from, "verlustzeit");
109  }
110  return NIVissimVehicleType::dictionary(id, name, category, color);
111 }
112 
113 
114 
115 /****************************************************************************/
116 
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
NIVissimSingleTypeParser_Fahrzeugtypdefinition(NIImporter_Vissim &parent, NIImporter_Vissim::ColorMap &colorMap)
Constructor.
Importer for networks stored in Vissim format.
static bool dictionary(int id, const std::string &name, const std::string &category, const RGBColor &color)
NIImporter_Vissim::ColorMap & myColorMap
The color map to use.
std::string readName(std::istream &from)
Reads the structures name We cannot use the "<<" operator, as names may contain more than one word wh...
bool parse(std::istream &from)
Parses the data type from the given stream.
std::map< std::string, RGBColor > ColorMap
definition of a map from color names to color definitions
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:155