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.org/sumo
3 // Copyright (C) 2001-2019 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 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <iostream>
26 #include <utils/common/ToString.h>
28 #include "../NIImporter_Vissim.h"
29 #include "../tempstructs/NIVissimVehTypeClass.h"
31 
32 
33 // ===========================================================================
34 // method definitions
35 // ===========================================================================
38  : NIImporter_Vissim::VissimSingleTypeParser(parent),
39  myColorMap(colorMap) {}
40 
41 
43 
44 
45 bool
47  // id
48  int id;
49  from >> id; // type-checking is missing!
50  // name
51  std::string tag;
52  from >> tag;
53  std::string name = readName(from);
54  // color
55  from >> tag;
56  std::string colorName = myRead(from);
57  RGBColor color;
58  NIImporter_Vissim::ColorMap::iterator i = myColorMap.find(colorName);
59  if (i != myColorMap.end()) {
60  color = (*i).second;
61  } else {
62  int r, g, b;
63  r = StringUtils::toInt(colorName);
64  if (!(from >> g)) {
65  throw NumberFormatException("");
66  }
67  if (!(from >> b)) {
68  throw NumberFormatException("");
69  }
70  if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
71  throw NumberFormatException("");
72  }
73  color = RGBColor((unsigned char)r, (unsigned char)g, (unsigned char)b, 255);
74  }
75  // types
76  from >> tag;
77  if (tag == "ANM_ID") {
78  readName(from);
79  from >> tag;
80  }
81  std::vector<int> types;
82  from >> tag;
83  do {
84  types.push_back(StringUtils::toInt(tag));
85  tag = readEndSecure(from);
86  } while (tag != "DATAEND");
87  return NIVissimVehTypeClass::dictionary(id, name, color, types);
88 }
89 
90 
91 
92 /****************************************************************************/
93 
ToString.h
NIImporter_Vissim::VissimSingleTypeParser::readName
std::string readName(std::istream &from)
Reads the structures name We cannot use the "<<" operator, as names may contain more than one word wh...
Definition: NIImporter_Vissim.cpp:797
NIImporter_Vissim
Importer for networks stored in Vissim format.
Definition: NIImporter_Vissim.h:58
NumberFormatException
Definition: UtilExceptions.h:95
VectorHelper.h
NIVissimSingleTypeParser_Fahrzeugklassendefinition::parse
bool parse(std::istream &from)
Parses the data type from the given stream.
Definition: NIVissimSingleTypeParser_Fahrzeugklassendefinition.cpp:46
RGBColor
Definition: RGBColor.h:39
NIVissimSingleTypeParser_Fahrzeugklassendefinition::myColorMap
NIImporter_Vissim::ColorMap & myColorMap
color definitions
Definition: NIVissimSingleTypeParser_Fahrzeugklassendefinition.h:51
NIImporter_Vissim::VissimSingleTypeParser::readEndSecure
std::string readEndSecure(std::istream &from, const std::string &excl="")
as myRead, but returns "DATAEND" when the current field has ended
Definition: NIImporter_Vissim.cpp:679
NIImporter_Vissim::ColorMap
std::map< std::string, RGBColor > ColorMap
definition of a map from color names to color definitions
Definition: NIImporter_Vissim.h:547
NIVissimSingleTypeParser_Fahrzeugklassendefinition::NIVissimSingleTypeParser_Fahrzeugklassendefinition
NIVissimSingleTypeParser_Fahrzeugklassendefinition(NIImporter_Vissim &parent, NIImporter_Vissim::ColorMap &colorMap)
Constructor.
Definition: NIVissimSingleTypeParser_Fahrzeugklassendefinition.cpp:36
NIVissimSingleTypeParser_Fahrzeugklassendefinition.h
NIVissimVehTypeClass::dictionary
static bool dictionary(int id, const std::string &name, const RGBColor &color, std::vector< int > &types)
Definition: NIVissimVehTypeClass.cpp:42
StringUtils.h
StringUtils::toInt
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
Definition: StringUtils.cpp:278
NIVissimSingleTypeParser_Fahrzeugklassendefinition::~NIVissimSingleTypeParser_Fahrzeugklassendefinition
~NIVissimSingleTypeParser_Fahrzeugklassendefinition()
Destructor.
Definition: NIVissimSingleTypeParser_Fahrzeugklassendefinition.cpp:42
config.h
NIImporter_Vissim::VissimSingleTypeParser::myRead
std::string myRead(std::istream &from)
reads from the stream and returns the lower case version of the read value
Definition: NIImporter_Vissim.cpp:670