SUMO - Simulation of Urban MObility
NIVissimSingleTypeParser_Fahrzeugklassendefinition.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-2016 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>
36 #include "../NIImporter_Vissim.h"
37 #include "../tempstructs/NIVissimVehTypeClass.h"
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
50  : NIImporter_Vissim::VissimSingleTypeParser(parent),
51  myColorMap(colorMap) {}
52 
53 
55 
56 
57 bool
59  // id
60  int id;
61  from >> id; // type-checking is missing!
62  // name
63  std::string tag;
64  from >> tag;
65  std::string name = readName(from);
66  // color
67  from >> tag;
68  std::string colorName = myRead(from);
69  RGBColor color;
70  NIImporter_Vissim::ColorMap::iterator i = myColorMap.find(colorName);
71  if (i != myColorMap.end()) {
72  color = (*i).second;
73  } else {
74  int r, g, b;
75  r = TplConvert::_2int(colorName.c_str());
76  if (!(from >> g)) {
77  throw NumberFormatException();
78  }
79  if (!(from >> b)) {
80  throw NumberFormatException();
81  }
82  if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
83  throw NumberFormatException();
84  }
85  color = RGBColor((unsigned char)r, (unsigned char)g, (unsigned char)b, 255);
86  }
87  // types
88  from >> tag;
89  if (tag == "ANM_ID") {
90  readName(from);
91  from >> tag;
92  }
93  std::vector<int> types;
94  from >> tag;
95  do {
96  types.push_back(TplConvert::_2int(tag.c_str()));
97  tag = readEndSecure(from);
98  } while (tag != "DATAEND");
99  return NIVissimVehTypeClass::dictionary(id, name, color, types);
100 }
101 
102 
103 
104 /****************************************************************************/
105 
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:149