SUMO - Simulation of Urban MObility
NIVissimSingleTypeParser_Fahrzeugtypdefinition.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 //
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <iostream>
34 #include <utils/common/ToString.h>
35 #include "../NIImporter_Vissim.h"
36 #include "../tempstructs/NIVissimVehicleType.h"
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
45  : NIImporter_Vissim::VissimSingleTypeParser(parent),
46  myColorMap(colorMap) {}
47 
48 
50 
51 
52 bool
54  // id
55  int id;
56  from >> id; // type-checking is missing!
57  // name
58  std::string tag;
59  from >> tag;
60  std::string name = readName(from);
61  // category
62  std::string category;
63  from >> tag;
64  from >> category;
65  // color (optional) and length
66  RGBColor color;
67  tag = myRead(from);
68  while (tag != "laenge") {
69  if (tag == "farbe") {
70  std::string colorName = myRead(from);
71  NIImporter_Vissim::ColorMap::iterator i = myColorMap.find(colorName);
72  if (i != myColorMap.end()) {
73  color = (*i).second;
74  } else {
75  int r, g, b;
76  r = TplConvert::_2int(colorName.c_str());
77  if (!(from >> g)) {
78  throw NumberFormatException();
79  }
80  if (!(from >> b)) {
81  throw NumberFormatException();
82  }
83  if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
84  throw NumberFormatException();
85  }
86  color = RGBColor((unsigned char)r, (unsigned char)g, (unsigned char)b, 255);
87  }
88  }
89  tag = myRead(from);
90  }
91  double length;
92  from >> length;
93  // overread until "Maxbeschleunigung"
94  while (tag != "maxbeschleunigung") {
95  tag = myRead(from);
96  }
97  double amax;
98  from >> amax; // type-checking is missing!
99  // overread until "Maxverzoegerung"
100  while (tag != "maxverzoegerung") {
101  tag = myRead(from);
102  }
103  double dmax;
104  from >> dmax; // type-checking is missing!
105  while (tag != "besetzungsgrad") {
106  tag = myRead(from);
107  }
108  while (tag != "DATAEND") {
109  tag = readEndSecure(from, "verlustzeit");
110  }
111  return NIVissimVehicleType::dictionary(id, name, category, color);
112 }
113 
114 
115 
116 /****************************************************************************/
117 
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:149