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-2018 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>
29 #include "../NIImporter_Vissim.h"
30 #include "../tempstructs/NIVissimVehTypeClass.h"
32 
33 
34 // ===========================================================================
35 // method definitions
36 // ===========================================================================
39  : NIImporter_Vissim::VissimSingleTypeParser(parent),
40  myColorMap(colorMap) {}
41 
42 
44 
45 
46 bool
48  // id
49  int id;
50  from >> id; // type-checking is missing!
51  // name
52  std::string tag;
53  from >> tag;
54  std::string name = readName(from);
55  // color
56  from >> tag;
57  std::string colorName = myRead(from);
58  RGBColor color;
59  NIImporter_Vissim::ColorMap::iterator i = myColorMap.find(colorName);
60  if (i != myColorMap.end()) {
61  color = (*i).second;
62  } else {
63  int r, g, b;
64  r = StringUtils::toInt(colorName);
65  if (!(from >> g)) {
66  throw NumberFormatException("");
67  }
68  if (!(from >> b)) {
69  throw NumberFormatException("");
70  }
71  if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
72  throw NumberFormatException("");
73  }
74  color = RGBColor((unsigned char)r, (unsigned char)g, (unsigned char)b, 255);
75  }
76  // types
77  from >> tag;
78  if (tag == "ANM_ID") {
79  readName(from);
80  from >> tag;
81  }
82  std::vector<int> types;
83  from >> tag;
84  do {
85  types.push_back(StringUtils::toInt(tag));
86  tag = readEndSecure(from);
87  } while (tag != "DATAEND");
88  return NIVissimVehTypeClass::dictionary(id, name, color, types);
89 }
90 
91 
92 
93 /****************************************************************************/
94 
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.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
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