SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PCTypeDefHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A handler for loading polygon type maps
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
40 #include <utils/common/RGBColor.h>
41 #include "PCTypeMap.h"
42 #include "PCTypeDefHandler.h"
43 
44 #ifdef CHECK_MEMORY_LEAKS
45 #include <foreign/nvwa/debug_new.h>
46 #endif // CHECK_MEMORY_LEAKS
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
53  : SUMOSAXHandler("Detector-Defintion"),
54  myOptions(oc), myContainer(con) {}
55 
56 
58 
59 
60 void
62  const SUMOSAXAttributes& attrs) {
63  if (element == SUMO_TAG_POLYTYPE) {
64  bool ok = true;
65  // get the id, report an error if not given or empty...
66  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
67  if (!ok) {
68  return;
69  }
70  int layer = attrs.getOpt<int>(SUMO_ATTR_LAYER, id.c_str(), ok, myOptions.getInt("layer"));
71  bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, id.c_str(), ok, false);
72  bool allowFill = attrs.getOpt<bool>(SUMO_ATTR_FILL, id.c_str(), ok, true);
73  std::string type = attrs.getOpt<std::string>(SUMO_ATTR_NAME, id.c_str(), ok, myOptions.getString("type"));
74  std::string prefix = attrs.getOpt<std::string>(SUMO_ATTR_PREFIX, id.c_str(), ok, myOptions.getString("prefix"));
75  std::string color = attrs.getOpt<std::string>(SUMO_ATTR_COLOR, id.c_str(), ok, myOptions.getString("color"));
76  // !!! what about error handling?
77  if (!myContainer.add(id, type, color, prefix, layer, discard, allowFill)) {
78  WRITE_ERROR("Could not add polygon type '" + id + "' (probably the id is already used).");
79  }
80  }
81 }
82 
83 
84 /****************************************************************************/
85 
A layer number.
virtual ~PCTypeDefHandler()
Destructor.
SAX-handler base for SUMO-files.
PCTypeMap & myContainer
The type map to fill.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
A storage for type mappings.
Definition: PCTypeMap.h:51
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
Encapsulated SAX-Attributes.
PCTypeDefHandler(OptionsCont &oc, PCTypeMap &con)
Constructor.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:201
A storage for options typed value containers)
Definition: OptionsCont.h:108
OptionsCont & myOptions
The options (program settings)
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
A color information.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Fill the polygon.