Line data Source code
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 : /****************************************************************************/ 14 : /// @file NIVissimSingleTypeParser_Fahrzeugtypdefinition.cpp 15 : /// @author Daniel Krajzewicz 16 : /// @author Michael Behrisch 17 : /// @date Wed, 18 Dec 2002 18 : /// 19 : // 20 : /****************************************************************************/ 21 : #include <config.h> 22 : 23 : #include <iostream> 24 : #include <utils/common/StringUtils.h> 25 : #include <utils/common/ToString.h> 26 : #include <netimport/vissim/NIImporter_Vissim.h> 27 : #include <netimport/vissim/tempstructs/NIVissimVehicleType.h> 28 : #include "NIVissimSingleTypeParser_Fahrzeugtypdefinition.h" 29 : 30 : 31 : // =========================================================================== 32 : // method definitions 33 : // =========================================================================== 34 9 : NIVissimSingleTypeParser_Fahrzeugtypdefinition::NIVissimSingleTypeParser_Fahrzeugtypdefinition( 35 9 : NIImporter_Vissim& parent, NIImporter_Vissim::ColorMap& colorMap) 36 : : NIImporter_Vissim::VissimSingleTypeParser(parent), 37 9 : myColorMap(colorMap) {} 38 : 39 : 40 18 : NIVissimSingleTypeParser_Fahrzeugtypdefinition::~NIVissimSingleTypeParser_Fahrzeugtypdefinition() {} 41 : 42 : 43 : bool 44 28 : NIVissimSingleTypeParser_Fahrzeugtypdefinition::parse(std::istream& from) { 45 : // id 46 : int id; 47 28 : from >> id; // type-checking is missing! 48 : // name 49 : std::string tag; 50 28 : from >> tag; 51 28 : std::string name = readName(from); 52 : // category 53 : std::string category; 54 28 : from >> tag; 55 28 : from >> category; 56 : // color (optional) and length 57 28 : RGBColor color; 58 28 : tag = myRead(from); 59 112 : while (tag != "laenge") { 60 56 : if (tag == "farbe") { 61 0 : std::string colorName = myRead(from); 62 0 : NIImporter_Vissim::ColorMap::iterator i = myColorMap.find(colorName); 63 0 : if (i != myColorMap.end()) { 64 0 : color = (*i).second; 65 : } else { 66 : int r, g, b; 67 0 : r = StringUtils::toInt(colorName); 68 0 : if (!(from >> g)) { 69 0 : throw NumberFormatException(""); 70 : } 71 0 : if (!(from >> b)) { 72 0 : throw NumberFormatException(""); 73 : } 74 0 : if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) { 75 0 : throw NumberFormatException(""); 76 : } 77 0 : color = RGBColor((unsigned char)r, (unsigned char)g, (unsigned char)b, 255); 78 : } 79 : } 80 112 : tag = myRead(from); 81 : } 82 : double length; 83 : from >> length; 84 : // overread until "Maxbeschleunigung" 85 638 : while (tag != "maxbeschleunigung") { 86 1220 : tag = myRead(from); 87 : } 88 : double amax; 89 : from >> amax; // type-checking is missing! 90 : // overread until "Maxverzoegerung" 91 112 : while (tag != "maxverzoegerung") { 92 168 : tag = myRead(from); 93 : } 94 : double dmax; 95 : from >> dmax; // type-checking is missing! 96 224 : while (tag != "besetzungsgrad") { 97 392 : tag = myRead(from); 98 : } 99 1112 : while (tag != "DATAEND") { 100 2168 : tag = readEndSecure(from, "verlustzeit"); 101 : } 102 56 : return NIVissimVehicleType::dictionary(id, name, category, color); 103 : } 104 : 105 : 106 : /****************************************************************************/