Eclipse SUMO - Simulation of Urban MObility
PCTypeMap.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2005-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 /****************************************************************************/
16 // A storage for type mappings
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <string>
26 #include <map>
28 #include "PCTypeMap.h"
29 
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
35  myDefaultType.id = oc.getString("type");
37  myDefaultType.layer = oc.getFloat("layer");
38  myDefaultType.discard = oc.getBool("discard");
39  myDefaultType.allowFill = oc.getBool("fill");
40  myDefaultType.prefix = oc.getString("prefix");
41 }
42 
43 
45 
46 
47 bool
48 PCTypeMap::add(const std::string& id, const std::string& newid,
49  const std::string& color, const std::string& prefix,
50  double layer, double angle, const std::string& imgFile,
51  bool discard, bool allowFill) {
52  if (has(id)) {
53  return false;
54  }
55  TypeDef td;
56  td.id = newid;
57  td.color = RGBColor::parseColor(color);
58  td.layer = layer;
59  td.angle = angle;
60  td.imgFile = imgFile;
61  td.discard = discard;
62  td.allowFill = allowFill;
63  td.prefix = prefix;
64  myTypes[id] = td;
65  return true;
66 }
67 
68 
69 const PCTypeMap::TypeDef&
70 PCTypeMap::get(const std::string& id) {
71  return myTypes.find(id)->second;
72 }
73 
74 
75 bool
76 PCTypeMap::has(const std::string& id) {
77  return myTypes.find(id) != myTypes.end();
78 }
79 
80 
81 
82 /****************************************************************************/
83 
PCTypeMap::TypeDef::imgFile
std::string imgFile
The image file to use.
Definition: PCTypeMap.h:70
PCTypeMap::TypeDef::layer
double layer
The layer to use.
Definition: PCTypeMap.h:66
OptionsCont.h
PCTypeMap::TypeDef::discard
bool discard
Information whether polygons of this type shall be discarded.
Definition: PCTypeMap.h:72
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:201
PCTypeMap::~PCTypeMap
~PCTypeMap()
Destructor.
Definition: PCTypeMap.cpp:44
OptionsCont::getBool
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Definition: OptionsCont.cpp:222
PCTypeMap.h
PCTypeMap::myTypes
std::map< std::string, TypeDef > myTypes
A map of type names to type definitions.
Definition: PCTypeMap.h:120
PCTypeMap::get
const TypeDef & get(const std::string &id)
Returns a type definition.
Definition: PCTypeMap.cpp:70
PCTypeMap::PCTypeMap
PCTypeMap(const OptionsCont &oc)
Constructor. The default type is constructed based on the given options.
Definition: PCTypeMap.cpp:34
RGBColor::parseColor
static RGBColor parseColor(std::string coldef)
Parses a color information.
Definition: RGBColor.cpp:176
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
PCTypeMap::TypeDef::prefix
std::string prefix
The prefix to use.
Definition: PCTypeMap.h:64
OptionsCont::getFloat
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
Definition: OptionsCont.cpp:208
PCTypeMap::has
bool has(const std::string &id)
Returns the information whether the named type is known.
Definition: PCTypeMap.cpp:76
PCTypeMap::add
bool add(const std::string &id, const std::string &newid, const std::string &color, const std::string &prefix, double layer, double angle, const std::string &imgFile, bool discard, bool allowFill)
Adds a type definition.
Definition: PCTypeMap.cpp:48
PCTypeMap::myDefaultType
TypeDef myDefaultType
Definition: PCTypeMap.h:122
config.h
PCTypeMap::TypeDef::id
std::string id
The new type id to use.
Definition: PCTypeMap.h:60
PCTypeMap::TypeDef::color
RGBColor color
The color to use.
Definition: PCTypeMap.h:62
PCTypeMap::TypeDef::allowFill
bool allowFill
Information whether polygons of this type can be filled.
Definition: PCTypeMap.h:74
PCTypeMap::TypeDef
A single definition of values that shall be used for a given type.
Definition: PCTypeMap.h:58
PCTypeMap::TypeDef::angle
double angle
The angle to use.
Definition: PCTypeMap.h:68