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_Fahrzeugklassendefinition.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 <utils/common/VectorHelper.h> 27 : #include <netimport/vissim/NIImporter_Vissim.h> 28 : #include <netimport/vissim/tempstructs/NIVissimVehTypeClass.h> 29 : #include "NIVissimSingleTypeParser_Fahrzeugklassendefinition.h" 30 : 31 : 32 : // =========================================================================== 33 : // method definitions 34 : // =========================================================================== 35 9 : NIVissimSingleTypeParser_Fahrzeugklassendefinition::NIVissimSingleTypeParser_Fahrzeugklassendefinition( 36 9 : NIImporter_Vissim& parent, NIImporter_Vissim::ColorMap& colorMap) 37 : : NIImporter_Vissim::VissimSingleTypeParser(parent), 38 9 : myColorMap(colorMap) {} 39 : 40 : 41 18 : NIVissimSingleTypeParser_Fahrzeugklassendefinition::~NIVissimSingleTypeParser_Fahrzeugklassendefinition() {} 42 : 43 : 44 : bool 45 28 : NIVissimSingleTypeParser_Fahrzeugklassendefinition::parse(std::istream& from) { 46 : // id 47 : int id; 48 28 : from >> id; // type-checking is missing! 49 : // name 50 : std::string tag; 51 28 : from >> tag; 52 28 : std::string name = readName(from); 53 : // color 54 28 : from >> tag; 55 28 : std::string colorName = myRead(from); 56 28 : RGBColor color; 57 28 : NIImporter_Vissim::ColorMap::iterator i = myColorMap.find(colorName); 58 28 : if (i != myColorMap.end()) { 59 28 : color = (*i).second; 60 : } else { 61 : int r, g, b; 62 0 : r = StringUtils::toInt(colorName); 63 0 : if (!(from >> g)) { 64 0 : throw NumberFormatException(""); 65 : } 66 0 : if (!(from >> b)) { 67 0 : throw NumberFormatException(""); 68 : } 69 0 : if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) { 70 0 : throw NumberFormatException(""); 71 : } 72 0 : color = RGBColor((unsigned char)r, (unsigned char)g, (unsigned char)b, 255); 73 : } 74 : // types 75 28 : from >> tag; 76 28 : if (tag == "ANM_ID") { 77 1 : readName(from); 78 1 : from >> tag; 79 : } 80 : std::vector<int> types; 81 28 : from >> tag; 82 : do { 83 28 : types.push_back(StringUtils::toInt(tag)); 84 56 : tag = readEndSecure(from); 85 28 : } while (tag != "DATAEND"); 86 56 : return NIVissimVehTypeClass::dictionary(id, name, color, types); 87 : } 88 : 89 : 90 : /****************************************************************************/