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-2015 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 #ifdef CHECK_MEMORY_LEAKS
40 #include <foreign/nvwa/debug_new.h>
41 #endif // CHECK_MEMORY_LEAKS
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
49  : NIImporter_Vissim::VissimSingleTypeParser(parent),
50  myColorMap(colorMap) {}
51 
52 
54 
55 
56 bool
58  // id
59  int id;
60  from >> id; // type-checking is missing!
61  // name
62  std::string tag;
63  from >> tag;
64  std::string name = readName(from);
65  // category
66  std::string category;
67  from >> tag;
68  from >> category;
69  // color (optional) and length
70  RGBColor color;
71  tag = myRead(from);
72  while (tag != "laenge") {
73  if (tag == "farbe") {
74  std::string colorName = myRead(from);
75  NIImporter_Vissim::ColorMap::iterator i = myColorMap.find(colorName);
76  if (i != myColorMap.end()) {
77  color = (*i).second;
78  } else {
79  int r, g, b;
80  r = TplConvert::_2int(colorName.c_str());
81  if (!(from >> g)) {
82  throw NumberFormatException();
83  }
84  if (!(from >> b)) {
85  throw NumberFormatException();
86  }
87  if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
88  throw NumberFormatException();
89  }
90  color = RGBColor((unsigned char)r, (unsigned char)g, (unsigned char)b, 255);
91  }
92  }
93  tag = myRead(from);
94  }
95  SUMOReal length;
96  from >> length;
97  // overread until "Maxbeschleunigung"
98  while (tag != "maxbeschleunigung") {
99  tag = myRead(from);
100  }
101  SUMOReal amax;
102  from >> amax; // type-checking is missing!
103  // overread until "Maxverzoegerung"
104  while (tag != "maxverzoegerung") {
105  tag = myRead(from);
106  }
107  SUMOReal dmax;
108  from >> dmax; // type-checking is missing!
109  while (tag != "besetzungsgrad") {
110  tag = myRead(from);
111  }
112  while (tag != "DATAEND") {
113  tag = readEndSecure(from, "verlustzeit");
114  }
115  return NIVissimVehicleType::dictionary(id, name, category, color);
116 }
117 
118 
119 
120 /****************************************************************************/
121 
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)
Definition: TplConvert.h:114
#define SUMOReal
Definition: config.h:218