SUMO - Simulation of Urban MObility
NIVissimSingleTypeParser_Fahrzeugklassendefinition.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>
35 #include "../NIImporter_Vissim.h"
36 #include "../tempstructs/NIVissimVehTypeClass.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  // color
62  from >> tag;
63  std::string colorName = myRead(from);
64  RGBColor color;
65  NIImporter_Vissim::ColorMap::iterator i = myColorMap.find(colorName);
66  if (i != myColorMap.end()) {
67  color = (*i).second;
68  } else {
69  int r, g, b;
70  r = TplConvert::_2int(colorName.c_str());
71  if (!(from >> g)) {
72  throw NumberFormatException();
73  }
74  if (!(from >> b)) {
75  throw NumberFormatException();
76  }
77  if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
78  throw NumberFormatException();
79  }
80  color = RGBColor((unsigned char)r, (unsigned char)g, (unsigned char)b, 255);
81  }
82  // types
83  from >> tag;
84  if (tag == "ANM_ID") {
85  readName(from);
86  from >> tag;
87  }
88  std::vector<int> types;
89  from >> tag;
90  do {
91  types.push_back(TplConvert::_2int(tag.c_str()));
92  tag = readEndSecure(from);
93  } while (tag != "DATAEND");
94  return NIVissimVehTypeClass::dictionary(id, name, color, types);
95 }
96 
97 
98 
99 /****************************************************************************/
100 
static bool dictionary(int id, const std::string &name, const RGBColor &color, std::vector< int > &types)
bool parse(std::istream &from)
Parses the data type from the given stream.
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
Importer for networks stored in Vissim format.
NIVissimSingleTypeParser_Fahrzeugklassendefinition(NIImporter_Vissim &parent, NIImporter_Vissim::ColorMap &colorMap)
Constructor.
std::string readName(std::istream &from)
Reads the structures name We cannot use the "<<" operator, as names may contain more than one word wh...
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