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-2018 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, 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.discard = discard;
60  td.allowFill = allowFill;
61  td.prefix = prefix;
62  myTypes[id] = td;
63  return true;
64 }
65 
66 
67 const PCTypeMap::TypeDef&
68 PCTypeMap::get(const std::string& id) {
69  return myTypes.find(id)->second;
70 }
71 
72 
73 bool
74 PCTypeMap::has(const std::string& id) {
75  return myTypes.find(id) != myTypes.end();
76 }
77 
78 
79 
80 /****************************************************************************/
81 
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
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:116
bool discard
Information whether polygons of this type shall be discarded.
Definition: PCTypeMap.h:69
RGBColor color
The color to use.
Definition: PCTypeMap.h:63
const TypeDef & get(const std::string &id)
Returns a type definition.
Definition: PCTypeMap.cpp:68
bool has(const std::string &id)
Returns the information whether the named type is known.
Definition: PCTypeMap.cpp:74
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
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:92
std::map< std::string, TypeDef > myTypes
A map of type names to type definitions.
Definition: PCTypeMap.h:114
bool add(const std::string &id, const std::string &newid, const std::string &color, const std::string &prefix, double layer, bool discard, bool allowFill)
Adds a type definition.
Definition: PCTypeMap.cpp:49
bool allowFill
Information whether polygons of this type can be filled.
Definition: PCTypeMap.h:71