PCTypeDefHandler.cpp

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

Generated on Wed May 5 00:06:35 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6