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