SUMO - Simulation of Urban MObility
PCTypeDefHandler.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // A handler for loading polygon type maps
00010 /****************************************************************************/
00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00013 /****************************************************************************/
00014 //
00015 //   This file is part of SUMO.
00016 //   SUMO is free software: you can redistribute it and/or modify
00017 //   it under the terms of the GNU General Public License as published by
00018 //   the Free Software Foundation, either version 3 of the License, or
00019 //   (at your option) any later version.
00020 //
00021 /****************************************************************************/
00022 
00023 
00024 // ===========================================================================
00025 // included modules
00026 // ===========================================================================
00027 #ifdef _MSC_VER
00028 #include <windows_config.h>
00029 #else
00030 #include <config.h>
00031 #endif
00032 
00033 #include <string>
00034 #include <utils/options/OptionsCont.h>
00035 #include <utils/common/MsgHandler.h>
00036 #include <utils/common/StringTokenizer.h>
00037 #include <utils/common/UtilExceptions.h>
00038 #include <utils/xml/SUMOSAXHandler.h>
00039 #include <utils/xml/SUMOXMLDefinitions.h>
00040 #include <utils/common/RGBColor.h>
00041 #include "PCTypeMap.h"
00042 #include "PCTypeDefHandler.h"
00043 
00044 #ifdef CHECK_MEMORY_LEAKS
00045 #include <foreign/nvwa/debug_new.h>
00046 #endif // CHECK_MEMORY_LEAKS
00047 
00048 
00049 // ===========================================================================
00050 // method definitions
00051 // ===========================================================================
00052 PCTypeDefHandler::PCTypeDefHandler(OptionsCont& oc, PCTypeMap& con)
00053     : SUMOSAXHandler("Detector-Defintion"),
00054       myOptions(oc),  myContainer(con) {}
00055 
00056 
00057 PCTypeDefHandler::~PCTypeDefHandler() {}
00058 
00059 
00060 void
00061 PCTypeDefHandler::myStartElement(int element,
00062                                  const SUMOSAXAttributes& attrs) {
00063     if (element == SUMO_TAG_POLYTYPE || element == SUMO_TAG_POLYTYPE__DEPRECATED) {
00064         bool ok = true;
00065         // get the id, report an error if not given or empty...
00066         std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok);
00067         if (!ok) {
00068             return;
00069         }
00070         int layer = attrs.getOptIntReporting(SUMO_ATTR_LAYER, id.c_str(), ok, myOptions.getInt("layer"));
00071         bool discard = attrs.getOptBoolReporting(SUMO_ATTR_DISCARD, id.c_str(), ok, false);
00072         bool allowFill = attrs.getOptBoolReporting(SUMO_ATTR_FILL, id.c_str(), ok, true);
00073         std::string type = attrs.getOptStringReporting(SUMO_ATTR_NAME, id.c_str(), ok, myOptions.getString("type"));
00074         std::string prefix = attrs.getOptStringReporting(SUMO_ATTR_PREFIX, id.c_str(), ok, myOptions.getString("prefix"));
00075         std::string color = attrs.getOptStringReporting(SUMO_ATTR_COLOR, id.c_str(), ok, myOptions.getString("color"));
00076         // !!! what about error handling?
00077         if (!myContainer.add(id, type, color, prefix, layer, discard, allowFill)) {
00078             WRITE_ERROR("Could not add polygon type '" + id + "' (probably the id is already used).");
00079         }
00080     }
00081 }
00082 
00083 
00084 /****************************************************************************/
00085 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines