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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A storage for type mappings
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include <map>
35 #include "PCTypeMap.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
42  myDefaultType.id = oc.getString("type");
44  myDefaultType.layer = oc.getFloat("layer");
45  myDefaultType.discard = oc.getBool("discard");
46  myDefaultType.allowFill = oc.getBool("fill");
47  myDefaultType.prefix = oc.getString("prefix");
48 }
49 
50 
52 
53 
54 bool
55 PCTypeMap::add(const std::string& id, const std::string& newid,
56  const std::string& color, const std::string& prefix,
57  double layer, bool discard, bool allowFill) {
58  if (has(id)) {
59  return false;
60  }
61  TypeDef td;
62  td.id = newid;
63  td.color = RGBColor::parseColor(color);
64  td.layer = layer;
65  td.discard = discard;
66  td.allowFill = allowFill;
67  td.prefix = prefix;
68  myTypes[id] = td;
69  return true;
70 }
71 
72 
73 const PCTypeMap::TypeDef&
74 PCTypeMap::get(const std::string& id) {
75  return myTypes.find(id)->second;
76 }
77 
78 
79 bool
80 PCTypeMap::has(const std::string& id) {
81  return myTypes.find(id) != myTypes.end();
82 }
83 
84 
85 
86 /****************************************************************************/
87 
std::string id
The new type id to use.
Definition: PCTypeMap.h:67
static RGBColor parseColor(std::string coldef)
Parses a color information.
Definition: RGBColor.cpp:179
A single definition of values that shall be used for a given type.
Definition: PCTypeMap.h:65
double layer
The layer to use.
Definition: PCTypeMap.h:73
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
TypeDef myDefaultType
Definition: PCTypeMap.h:122
bool discard
Information whether polygons of this type shall be discarded.
Definition: PCTypeMap.h:75
RGBColor color
The color to use.
Definition: PCTypeMap.h:69
const TypeDef & get(const std::string &id)
Returns a type definition.
Definition: PCTypeMap.cpp:74
bool has(const std::string &id)
Returns the information whether the named type is known.
Definition: PCTypeMap.cpp:80
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:41
~PCTypeMap()
Destructor.
Definition: PCTypeMap.cpp:51
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:71
A storage for options typed value containers)
Definition: OptionsCont.h:98
std::map< std::string, TypeDef > myTypes
A map of type names to type definitions.
Definition: PCTypeMap.h:120
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:55
bool allowFill
Information whether polygons of this type can be filled.
Definition: PCTypeMap.h:77