Eclipse 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.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
19 //
20 /****************************************************************************/
21 #include <config.h>
22 
23 #include <iostream>
25 #include <utils/common/ToString.h>
30 
31 
32 // ===========================================================================
33 // method definitions
34 // ===========================================================================
37  : NIImporter_Vissim::VissimSingleTypeParser(parent),
38  myColorMap(colorMap) {}
39 
40 
42 
43 
44 bool
46  // id
47  int id;
48  from >> id; // type-checking is missing!
49  // name
50  std::string tag;
51  from >> tag;
52  std::string name = readName(from);
53  // color
54  from >> tag;
55  std::string colorName = myRead(from);
56  RGBColor color;
57  NIImporter_Vissim::ColorMap::iterator i = myColorMap.find(colorName);
58  if (i != myColorMap.end()) {
59  color = (*i).second;
60  } else {
61  int r, g, b;
62  r = StringUtils::toInt(colorName);
63  if (!(from >> g)) {
64  throw NumberFormatException("");
65  }
66  if (!(from >> b)) {
67  throw NumberFormatException("");
68  }
69  if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
70  throw NumberFormatException("");
71  }
72  color = RGBColor((unsigned char)r, (unsigned char)g, (unsigned char)b, 255);
73  }
74  // types
75  from >> tag;
76  if (tag == "ANM_ID") {
77  readName(from);
78  from >> tag;
79  }
80  std::vector<int> types;
81  from >> tag;
82  do {
83  types.push_back(StringUtils::toInt(tag));
84  tag = readEndSecure(from);
85  } while (tag != "DATAEND");
86  return NIVissimVehTypeClass::dictionary(id, name, color, types);
87 }
88 
89 
90 /****************************************************************************/
std::string readEndSecure(std::istream &from, const std::string &excl="")
as myRead, but returns "DATAEND" when the current field has ended
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::string myRead(std::istream &from)
reads from the stream and returns the lower case version of the read value
Importer for networks stored in Vissim format.
std::map< std::string, RGBColor > ColorMap
definition of a map from color names to color definitions
NIVissimSingleTypeParser_Fahrzeugklassendefinition(NIImporter_Vissim &parent, NIImporter_Vissim::ColorMap &colorMap)
Constructor.
bool parse(std::istream &from)
Parses the data type from the given stream.
static bool dictionary(int id, const std::string &name, const RGBColor &color, std::vector< int > &types)
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...