SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PCTypeMap.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A storage for type mappings
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
10 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <string>
32 #include <map>
34 #include "PCTypeMap.h"
35 
36 #ifdef CHECK_MEMORY_LEAKS
37 #include <foreign/nvwa/debug_new.h>
38 #endif // CHECK_MEMORY_LEAKS
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
45  myDefaultType.id = oc.getString("type");
47  myDefaultType.layer = oc.getInt("layer");
48  myDefaultType.discard = oc.getBool("discard");
49  myDefaultType.allowFill = true;
50  myDefaultType.prefix = oc.getString("prefix");
51 }
52 
53 
55 
56 
57 bool
58 PCTypeMap::add(const std::string& id, const std::string& newid,
59  const std::string& color, const std::string& prefix,
60  int layer, bool discard, bool allowFill) {
61  if (has(id)) {
62  return false;
63  }
64  TypeDef td;
65  td.id = newid;
66  td.color = RGBColor::parseColor(color);
67  td.layer = layer;
68  td.discard = discard;
69  td.allowFill = allowFill;
70  td.prefix = prefix;
71  myTypes[id] = td;
72  return true;
73 }
74 
75 
76 const PCTypeMap::TypeDef&
77 PCTypeMap::get(const std::string& id) {
78  return myTypes.find(id)->second;
79 }
80 
81 
82 bool
83 PCTypeMap::has(const std::string& id) {
84  return myTypes.find(id) != myTypes.end();
85 }
86 
87 
88 
89 /****************************************************************************/
90 
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:154
A single definition of values that shall be used for a given type.
Definition: PCTypeMap.h:65
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
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
const TypeDef & get(const std::string &id)
Returns a type definition.
Definition: PCTypeMap.cpp:77
bool add(const std::string &id, const std::string &newid, const std::string &color, const std::string &prefix, int layer, bool discard, bool allowFill)
Adds a type definition.
Definition: PCTypeMap.cpp:58
bool has(const std::string &id)
Returns the information whether the named type is known.
Definition: PCTypeMap.cpp:83
PCTypeMap(const OptionsCont &oc)
Constructor. The default type is constructed based on the given options.
Definition: PCTypeMap.cpp:44
~PCTypeMap()
Destructor.
Definition: PCTypeMap.cpp:54
std::string prefix
The prefix to use.
Definition: PCTypeMap.h:71
A storage for options typed value containers)
Definition: OptionsCont.h:108
std::map< std::string, TypeDef > myTypes
A map of type names to type definitions.
Definition: PCTypeMap.h:120
int layer
The layer to use.
Definition: PCTypeMap.h:73
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
bool allowFill
Information whether polygons of this type can be filled.
Definition: PCTypeMap.h:77