ROJTRTurnDefLoader.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029
00030 #include <set>
00031 #include <string>
00032 #include <utils/common/FileHelpers.h>
00033 #include <utils/xml/XMLSubSys.h>
00034 #include <utils/common/UtilExceptions.h>
00035 #include <utils/common/MsgHandler.h>
00036 #include <utils/common/UtilExceptions.h>
00037 #include <utils/common/TplConvert.h>
00038 #include <utils/xml/SUMOXMLDefinitions.h>
00039 #include <router/RONet.h>
00040 #include "ROJTREdge.h"
00041 #include "ROJTRTurnDefLoader.h"
00042
00043 #ifdef CHECK_MEMORY_LEAKS
00044 #include <foreign/nvwa/debug_new.h>
00045 #endif // CHECK_MEMORY_LEAKS
00046
00047
00048
00049
00050
00051 ROJTRTurnDefLoader::ROJTRTurnDefLoader(RONet &net) throw()
00052 : SUMOSAXHandler("turn-definitions"), myNet(net),
00053 myIntervalBegin(0), myIntervalEnd(86400), myEdge(0),
00054 myHaveWarnedAboutDeprecatedSources(false),
00055 myHaveWarnedAboutDeprecatedSinks(false) {}
00056
00057
00058 ROJTRTurnDefLoader::~ROJTRTurnDefLoader() throw() {}
00059
00060
00061 void
00062 ROJTRTurnDefLoader::myStartElement(SumoXMLTag element,
00063 const SUMOSAXAttributes &attrs) throw(ProcessError) {
00064 bool ok = true;
00065 switch (element) {
00066 case SUMO_TAG_INTERVAL:
00067 myIntervalBegin = attrs.getSUMOTimeReporting(SUMO_ATTR_BEGIN, "interval", 0, ok);
00068 myIntervalEnd = attrs.getSUMOTimeReporting(SUMO_ATTR_END, "interval", 0, ok);
00069 break;
00070 case SUMO_TAG_FROMEDGE:
00071 beginFromEdge(attrs);
00072 break;
00073 case SUMO_TAG_TOEDGE:
00074 addToEdge(attrs);
00075 break;
00076 case SUMO_TAG_SINK:
00077 if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
00078 std::string edges = attrs.getStringReporting(SUMO_ATTR_EDGES, "sink", 0, ok);
00079 StringTokenizer st(edges, StringTokenizer::WHITECHARS);
00080 while (st.hasNext()) {
00081 std::string id = st.next();
00082 ROEdge *edge = myNet.getEdge(id);
00083 if (edge==0) {
00084 throw ProcessError("The edge '" + id + "' declared as a sink is not known.");
00085 }
00086 edge->setType(ROEdge::ET_SINK);
00087 }
00088 }
00089 break;
00090 case SUMO_TAG_SOURCE:
00091 if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
00092 std::string edges = attrs.getStringReporting(SUMO_ATTR_EDGES, "source", 0, ok);
00093 StringTokenizer st(edges, StringTokenizer::WHITECHARS);
00094 while (st.hasNext()) {
00095 std::string id = st.next();
00096 ROEdge *edge = myNet.getEdge(id);
00097 if (edge==0) {
00098 throw ProcessError("The edge '" + id + "' declared as a source is not known.");
00099 }
00100 edge->setType(ROEdge::ET_SOURCE);
00101 }
00102 }
00103 break;
00104 default:
00105 break;
00106 }
00107 }
00108
00109
00110 void
00111 ROJTRTurnDefLoader::myCharacters(SumoXMLTag element,
00112 const std::string &chars) throw(ProcessError) {
00113 switch (element) {
00114 case SUMO_TAG_SINK: {
00115 ROEdge *edge = myNet.getEdge(chars);
00116 if (edge==0) {
00117 throw ProcessError("The edge '" + chars + "' declared as a sink is not known.");
00118 }
00119 if (!myHaveWarnedAboutDeprecatedSinks) {
00120 myHaveWarnedAboutDeprecatedSinks = true;
00121 MsgHandler::getWarningInstance()->inform("Using characters for sinks is deprecated; use attribute 'edges' instead.");
00122 }
00123 edge->setType(ROEdge::ET_SINK);
00124 }
00125 break;
00126 case SUMO_TAG_SOURCE: {
00127 ROEdge *edge = myNet.getEdge(chars);
00128 if (edge==0) {
00129 throw ProcessError("The edge '" + chars + "' declared as a source is not known.");
00130 }
00131 if (!myHaveWarnedAboutDeprecatedSources) {
00132 myHaveWarnedAboutDeprecatedSources = true;
00133 MsgHandler::getWarningInstance()->inform("Using characters for sources is deprecated; use attribute 'edges' instead.");
00134 }
00135 edge->setType(ROEdge::ET_SOURCE);
00136 }
00137 break;
00138 default:
00139 break;
00140 }
00141 }
00142
00143
00144 void
00145 ROJTRTurnDefLoader::beginFromEdge(const SUMOSAXAttributes &attrs) throw() {
00146 myEdge = 0;
00147
00148 std::string id;
00149 if (!attrs.setIDFromAttributes("from-edge", id)) {
00150 return;
00151 }
00152
00153 myEdge = static_cast<ROJTREdge*>(myNet.getEdge(id));
00154 if (myEdge==0) {
00155 MsgHandler::getErrorInstance()->inform("The edge '" + id + "' is not known within the network (within a 'from-edge' tag).");
00156 return;
00157 }
00158 }
00159
00160
00161 void
00162 ROJTRTurnDefLoader::addToEdge(const SUMOSAXAttributes &attrs) throw() {
00163 if (myEdge==0) {
00164 return;
00165 }
00166
00167 std::string id;
00168 if (!attrs.setIDFromAttributes("to-edge", id)) {
00169 return;
00170 }
00171
00172 ROJTREdge *edge = static_cast<ROJTREdge*>(myNet.getEdge(id));
00173 if (edge==0) {
00174 MsgHandler::getErrorInstance()->inform("The edge '" + id + "' is not known within the network (within a 'to-edge' tag).");
00175 return;
00176 }
00177 bool ok = true;
00178 SUMOReal probability = attrs.getSUMORealReporting(SUMO_ATTR_PROB, "to-edge", id.c_str(), ok);
00179 if (ok) {
00180 if (probability<0) {
00181 MsgHandler::getErrorInstance()->inform("'probability' must be positive (in definition of to-edge '" + id + "').");
00182 } else {
00183 myEdge->addFollowerProbability(edge, myIntervalBegin, myIntervalEnd, probability);
00184 }
00185 }
00186 }
00187
00188
00189
00190
00191