SUMO - Simulation of Urban MObility
PCTypeDefHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-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 handler for loading polygon type maps
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
33 #include <utils/common/RGBColor.h>
34 #include "PCTypeMap.h"
35 #include "PCTypeDefHandler.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
42  : SUMOSAXHandler("Detector-Defintion"),
43  myOptions(oc), myContainer(con) {}
44 
45 
47 
48 
49 void
51  const SUMOSAXAttributes& attrs) {
52  if (element == SUMO_TAG_POLYTYPE) {
53  bool ok = true;
54  // get the id, report an error if not given or empty...
55  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
56  if (!ok) {
57  return;
58  }
59  const double layer = attrs.getOpt<double>(SUMO_ATTR_LAYER, id.c_str(), ok, myOptions.getFloat("layer"));
60  const bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, id.c_str(), ok, false);
61  const bool allowFill = attrs.getOpt<bool>(SUMO_ATTR_FILL, id.c_str(), ok, myOptions.getBool("fill"));
62  const std::string type = attrs.getOpt<std::string>(SUMO_ATTR_NAME, id.c_str(), ok, myOptions.getString("type"));
63  const std::string prefix = attrs.getOpt<std::string>(SUMO_ATTR_PREFIX, id.c_str(), ok, myOptions.getString("prefix"));
64  const std::string color = attrs.getOpt<std::string>(SUMO_ATTR_COLOR, id.c_str(), ok, myOptions.getString("color"));
65  // !!! what about error handling?
66  if (!myContainer.add(id, type, color, prefix, layer, discard, allowFill)) {
67  WRITE_ERROR("Could not add polygon type '" + id + "' (probably the id is already used).");
68  }
69  }
70 }
71 
72 
73 /****************************************************************************/
74 
A layer number.
virtual ~PCTypeDefHandler()
Destructor.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
SAX-handler base for SUMO-files.
PCTypeMap & myContainer
The type map to fill.
A storage for type mappings.
Definition: PCTypeMap.h:45
Encapsulated SAX-Attributes.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
PCTypeDefHandler(OptionsCont &oc, PCTypeMap &con)
Constructor.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:247
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.
A storage for options typed value containers)
Definition: OptionsCont.h:92
OptionsCont & myOptions
The options (program settings)
type of polygon
A color information.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Fill the polygon.
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