ROJTRTurnDefLoader Class Reference

#include <ROJTRTurnDefLoader.h>

Inheritance diagram for ROJTRTurnDefLoader:

SUMOSAXHandler GenericSAXHandler

Detailed Description

Loader for the of turning percentages and source/sink definitions.

This handler parses XML-descriptions of jtrrouter-definitions, including percentage ratios at junctions and definitions of sink/source edges.

All read values are stored directly into the given network's structures (edges).

Definition at line 59 of file ROJTRTurnDefLoader.h.


Public Member Functions

void characters (const XMLCh *const chars, const XERCES3_SIZE_t length)
 The inherited method called when characters occured.
void endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
 The inherited method called when a tag is being closed.
const std::string & getFileName () const throw ()
 returns the current file name
void registerParent (const SumoXMLTag tag, GenericSAXHandler *handler)
 Assigning a parent handler which is enabled when the specified tag is closed.
 ROJTRTurnDefLoader (RONet &net) throw ()
 Constructor.
void setFileName (const std::string &name) throw ()
 Sets the current file name.
void startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs)
 The inherited method called when a new tag opens.
 ~ROJTRTurnDefLoader () throw ()
 Destructor.
SAX ErrorHandler callbacks
void error (const SAXParseException &exception) throw (ProcessError)
 Handler for XML-errors.
void fatalError (const SAXParseException &exception) throw (ProcessError)
 Handler for XML-errors.
void warning (const SAXParseException &exception) throw ()
 Handler for XML-warnings.

Protected Member Functions

std::string buildErrorMessage (const SAXParseException &exception) throw ()
 Builds an error message.
virtual void myEndElement (SumoXMLTag element) throw (ProcessError)
 Callback method for a closing tag to implement by derived classes.
inherited from GenericSAXHandler
void myCharacters (SumoXMLTag element, const std::string &chars) throw (ProcessError)
 Called when characters occure.
void myStartElement (SumoXMLTag element, const SUMOSAXAttributes &attrs) throw (ProcessError)
 Called on the opening of a tag;.

Private Member Functions

void addToEdge (const SUMOSAXAttributes &attrs) throw ()
 Parses the probability to use a certain outgoing edge.
void beginFromEdge (const SUMOSAXAttributes &attrs) throw ()
 Begins the processing of a incoming edge definition.

Private Attributes

ROJTREdgemyEdge
 The current incoming edge the turning probabilities are set into.
bool myHaveWarnedAboutDeprecatedSinks
bool myHaveWarnedAboutDeprecatedSources
 Whether the loader has warned about deprecated usage of characters.
SUMOTime myIntervalBegin
 The begin and the end of the current interval.
SUMOTime myIntervalEnd
RONetmyNet
 The network to set the information into.

Constructor & Destructor Documentation

ROJTRTurnDefLoader::ROJTRTurnDefLoader ( RONet net  )  throw ()

Constructor.

Parameters:
[in] net The net to add loaded turning percentages into

Definition at line 51 of file ROJTRTurnDefLoader.cpp.

00052         : SUMOSAXHandler("turn-definitions"), myNet(net),
00053         myIntervalBegin(0), myIntervalEnd(86400), myEdge(0),
00054         myHaveWarnedAboutDeprecatedSources(false),
00055         myHaveWarnedAboutDeprecatedSinks(false) {}

ROJTRTurnDefLoader::~ROJTRTurnDefLoader (  )  throw ()

Destructor.

Definition at line 58 of file ROJTRTurnDefLoader.cpp.

00058 {}


Member Function Documentation

void ROJTRTurnDefLoader::addToEdge ( const SUMOSAXAttributes attrs  )  throw () [private]

Parses the probability to use a certain outgoing edge.

Tries to retreive the outgoing edge and then the probability to use it. If one of both operations could not be accomplished, an error is generated.

If everything is ok, this means the destination edge is defined and known and the probability is valid, too, this probability is added to "myEdge", the last parsed incoming edge. As time, the previously parsed interval begin/end is used.

Parameters:
[in] attrs The SAX-attributes to parse the destination edge and the probability to use it from

Definition at line 162 of file ROJTRTurnDefLoader.cpp.

References ROJTREdge::addFollowerProbability(), RONet::getEdge(), MsgHandler::getErrorInstance(), MsgHandler::inform(), myEdge, myIntervalBegin, myIntervalEnd, myNet, SUMO_ATTR_PROB, and SUMOReal.

Referenced by myStartElement().

00162                                                                     {
00163     if (myEdge==0) {
00164         return;
00165     }
00166     // get the id, report an error if not given or empty...
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 }

void ROJTRTurnDefLoader::beginFromEdge ( const SUMOSAXAttributes attrs  )  throw () [private]

Begins the processing of a incoming edge definition.

Tries to retrieve the currently described incoming edge. If the edge id is not given in the attributes or the edge is not known, an error is reported.

If everything is ok, the edge's address is stored in myEdge.

Parameters:
[in] attrs The SAX-attributes to parse incoming edge from

Definition at line 145 of file ROJTRTurnDefLoader.cpp.

References RONet::getEdge(), MsgHandler::getErrorInstance(), MsgHandler::inform(), myEdge, and myNet.

Referenced by myStartElement().

00145                                                                         {
00146     myEdge = 0;
00147     // get the id, report an error if not given or empty...
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 }

std::string SUMOSAXHandler::buildErrorMessage ( const SAXParseException &  exception  )  throw () [protected, inherited]

Builds an error message.

The error message includes the file name and the line/column information as supported by the given SAXParseException

Parameters:
[in] exception The name of the currently processed file
Returns:
A string describing the given exception

Definition at line 55 of file SUMOSAXHandler.cpp.

References GenericSAXHandler::getFileName().

Referenced by SUMOSAXHandler::error(), SUMOSAXHandler::fatalError(), and SUMOSAXHandler::warning().

00055                                                                             {
00056     std::ostringstream buf;
00057     char *pMsg = XMLString::transcode(exception.getMessage());
00058     buf << pMsg << std::endl;
00059     buf << " In file '" << getFileName() << "'" << std::endl;
00060     buf << " At line/column " << exception.getLineNumber()+1
00061     << '/' << exception.getColumnNumber() << "." << std::endl;
00062     XMLString::release(&pMsg);
00063     return buf.str();
00064 }

void GenericSAXHandler::characters ( const XMLCh *const   chars,
const XERCES3_SIZE_t  length 
) [inherited]

The inherited method called when characters occured.

The retrieved characters are converted into a string and appended into a private buffer. They are reported as soon as the element ends.

Todo:
recheck/describe what happens with characters when a new element is opened
Todo:
describe characters processing in the class' head

Definition at line 168 of file GenericSAXHandler.cpp.

References GenericSAXHandler::myCharactersVector.

00169                                                            {
00170     myCharactersVector.push_back(TplConvert<XMLCh>::_2str(chars, length));
00171 }

void GenericSAXHandler::endElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const   qname 
) [inherited]

The inherited method called when a tag is being closed.

This method calls the user-implemented methods myCharacters with the previously collected and converted characters.

Then, myEndElement is called, supplying it the qname converted to its enum- and string-representations.

Todo:
recheck/describe encoding of the string-representation
Todo:
do not generate and report the string-representation

Definition at line 118 of file GenericSAXHandler.cpp.

References TplConvert< E >::_2str(), GenericSAXHandler::convertTag(), GenericSAXHandler::myCharacters(), GenericSAXHandler::myCharactersVector, GenericSAXHandler::myEndElement(), GenericSAXHandler::myParentHandler, GenericSAXHandler::myParentIndicator, XMLSubSys::setHandler(), SUMO_TAG_INCLUDE, and SUMO_TAG_NOTHING.

00120                                                         {
00121     std::string name = TplConvert<XMLCh>::_2str(qname);
00122     SumoXMLTag element = convertTag(name);
00123     // collect characters
00124     if (myCharactersVector.size()!=0) {
00125         size_t len = 0;
00126         unsigned i;
00127         for (i=0; i<myCharactersVector.size(); ++i) {
00128             len += myCharactersVector[i].length();
00129         }
00130         char *buf = new char[len+1];
00131         size_t pos = 0;
00132         for (i=0; i<myCharactersVector.size(); ++i) {
00133             memcpy((unsigned char*) buf+pos, (unsigned char*) myCharactersVector[i].c_str(),
00134                    sizeof(char)*myCharactersVector[i].length());
00135             pos += myCharactersVector[i].length();
00136         }
00137         buf[pos] = 0;
00138 
00139         // call user handler
00140         try {
00141             myCharacters(element, buf);
00142         } catch (std::runtime_error &) {
00143             delete[] buf;
00144             throw;
00145         }
00146         delete[] buf;
00147     }
00148     if (element != SUMO_TAG_INCLUDE) {
00149         myEndElement(element);
00150         if (myParentHandler && myParentIndicator == element) {
00151             XMLSubSys::setHandler(*myParentHandler);
00152             myParentIndicator = SUMO_TAG_NOTHING;
00153             myParentHandler = 0;
00154         }
00155     }
00156 }

void SUMOSAXHandler::error ( const SAXParseException &  exception  )  throw (ProcessError) [inherited]

Handler for XML-errors.

The message is built using buildErrorMessage and thrown within a ProcessError.

Parameters:
[in] exception The occured exception to process
Exceptions:
ProcessError On any call

Definition at line 74 of file SUMOSAXHandler.cpp.

References SUMOSAXHandler::buildErrorMessage().

00074                                                                             {
00075     throw ProcessError(buildErrorMessage(exception));
00076 }

void SUMOSAXHandler::fatalError ( const SAXParseException &  exception  )  throw (ProcessError) [inherited]

Handler for XML-errors.

The message is built using buildErrorMessage and thrown within a ProcessError.

Exceptions:
ProcessError On any call
Parameters:
[in] exception The occured exception to process

Definition at line 80 of file SUMOSAXHandler.cpp.

References SUMOSAXHandler::buildErrorMessage().

00080                                                                                  {
00081     throw ProcessError(buildErrorMessage(exception));
00082 }

const std::string & GenericSAXHandler::getFileName (  )  const throw () [inherited]

void ROJTRTurnDefLoader::myCharacters ( SumoXMLTag  element,
const std::string &  chars 
) throw (ProcessError) [protected, virtual]

Called when characters occure.

Parameters:
[in] element ID of the last opened element
[in] chars The read characters (complete)
Exceptions:
ProcessError If something fails
See also:
GenericSAXHandler::myCharacters

Reimplemented from GenericSAXHandler.

Definition at line 111 of file ROJTRTurnDefLoader.cpp.

References ROEdge::ET_SINK, ROEdge::ET_SOURCE, RONet::getEdge(), MsgHandler::getWarningInstance(), MsgHandler::inform(), myHaveWarnedAboutDeprecatedSinks, myHaveWarnedAboutDeprecatedSources, myNet, ROEdge::setType(), SUMO_TAG_SINK, and SUMO_TAG_SOURCE.

00112                                                                              {
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 }

void GenericSAXHandler::myEndElement ( SumoXMLTag  element  )  throw (ProcessError) [protected, virtual, inherited]

Callback method for a closing tag to implement by derived classes.

Called by "endElement" (see there).

Parameters:
[in] element The closed element, given as a SumoXMLTag ProcessError These method may throw a ProcessError if something fails

Reimplemented in MSRouteHandler, MSLaneSpeedTrigger, MSTriggeredRerouter, NIImporter_OpenDrive, NIImporter_OpenStreetMap::NodesHandler, NIImporter_OpenStreetMap::EdgesHandler, NIImporter_SUMO, NIXMLEdgesHandler, NLHandler, ODDistrictHandler, PCLoaderOSM::NodesHandler, PCLoaderOSM::EdgesHandler, RORDGenerator_ODAmounts, RORDLoader_SUMOBase, RORDLoader_TripDefs, traci::TraCIHandler, and SAXWeightsHandler.

Definition at line 193 of file GenericSAXHandler.cpp.

Referenced by GenericSAXHandler::endElement().

00193 {}

void ROJTRTurnDefLoader::myStartElement ( SumoXMLTag  element,
const SUMOSAXAttributes attrs 
) throw (ProcessError) [protected, virtual]

Called on the opening of a tag;.

Parameters:
[in] element ID of the currently opened element
[in] attrs Attributes within the currently opened element
Exceptions:
ProcessError If something fails
See also:
GenericSAXHandler::myStartElement

Reimplemented from GenericSAXHandler.

Definition at line 62 of file ROJTRTurnDefLoader.cpp.

References addToEdge(), beginFromEdge(), ROEdge::ET_SINK, ROEdge::ET_SOURCE, RONet::getEdge(), StringTokenizer::hasNext(), myIntervalBegin, myIntervalEnd, myNet, StringTokenizer::next(), ROEdge::setType(), SUMO_ATTR_BEGIN, SUMO_ATTR_EDGES, SUMO_ATTR_END, SUMO_TAG_FROMEDGE, SUMO_TAG_INTERVAL, SUMO_TAG_SINK, SUMO_TAG_SOURCE, SUMO_TAG_TOEDGE, and StringTokenizer::WHITECHARS.

00063                                                                                        {
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 }

void GenericSAXHandler::registerParent ( const SumoXMLTag  tag,
GenericSAXHandler handler 
) [inherited]

Assigning a parent handler which is enabled when the specified tag is closed.

Definition at line 160 of file GenericSAXHandler.cpp.

References GenericSAXHandler::myParentHandler, GenericSAXHandler::myParentIndicator, and XMLSubSys::setHandler().

Referenced by NLTriggerBuilder::parseAndBuildLaneSpeedTrigger().

00160                                                                                   {
00161     myParentHandler = handler;
00162     myParentIndicator = tag;
00163     XMLSubSys::setHandler(*this);
00164 }

void GenericSAXHandler::setFileName ( const std::string &  name  )  throw () [inherited]

Sets the current file name.

Parameters:
[in] name The name of the currently processed file
Todo:
Hmmm - this is as unsafe as having a direct access to the variable; recheck

Definition at line 72 of file GenericSAXHandler.cpp.

References GenericSAXHandler::myFileName.

Referenced by PCNetProjectionLoader::loadIfSet(), ROLoader::loadNet(), NIImporter_OpenStreetMap::loadNetwork(), NILoader::loadXMLType(), and traci::TraCIServer::TraCIServer().

00072                                                             {
00073     myFileName = name;
00074 }

void GenericSAXHandler::startElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const   qname,
const Attributes &  attrs 
) [inherited]

The inherited method called when a new tag opens.

The method parses the supplied XMLCh*-qname using the internal name/enum-map to obtain the enum representation of the attribute name.

Then, "myStartElement" is called supplying the enumeration value, the string-representation of the name and the attributes.

Todo:
recheck/describe encoding of the string-representation
Todo:
do not generate and report the string-representation

Definition at line 97 of file GenericSAXHandler.cpp.

References TplConvert< E >::_2str(), GenericSAXHandler::convertTag(), FileHelpers::getConfigurationRelative(), GenericSAXHandler::getFileName(), SUMOSAXAttributesImpl_Xerces::getString(), FileHelpers::isAbsolute(), GenericSAXHandler::myCharactersVector, GenericSAXHandler::myPredefinedTags, GenericSAXHandler::myPredefinedTagsMML, GenericSAXHandler::myStartElement(), XMLSubSys::runParser(), SUMO_ATTR_HREF, and SUMO_TAG_INCLUDE.

00100                                                          {
00101     std::string name = TplConvert<XMLCh>::_2str(qname);
00102     SumoXMLTag element = convertTag(name);
00103     myCharactersVector.clear();
00104     SUMOSAXAttributesImpl_Xerces na(attrs, myPredefinedTags, myPredefinedTagsMML);
00105     if (element == SUMO_TAG_INCLUDE) {
00106         std::string file = na.getString(SUMO_ATTR_HREF);
00107         if (!FileHelpers::isAbsolute(file)) {
00108             file = FileHelpers::getConfigurationRelative(getFileName(), file);
00109         }
00110         XMLSubSys::runParser(*this, file);
00111     } else {
00112         myStartElement(element, na);
00113     }
00114 }

void SUMOSAXHandler::warning ( const SAXParseException &  exception  )  throw () [inherited]

Handler for XML-warnings.

The message is built using buildErrorMessage and reported to the warning-instance of the MsgHandler.

Parameters:
[in] exception The occured exception to process

Definition at line 68 of file SUMOSAXHandler.cpp.

References SUMOSAXHandler::buildErrorMessage(), MsgHandler::getWarningInstance(), and MsgHandler::inform().


Field Documentation

The current incoming edge the turning probabilities are set into.

Definition at line 137 of file ROJTRTurnDefLoader.h.

Referenced by addToEdge(), and beginFromEdge().

Definition at line 140 of file ROJTRTurnDefLoader.h.

Referenced by myCharacters().

Whether the loader has warned about deprecated usage of characters.

Definition at line 140 of file ROJTRTurnDefLoader.h.

Referenced by myCharacters().

The begin and the end of the current interval.

Definition at line 134 of file ROJTRTurnDefLoader.h.

Referenced by addToEdge(), and myStartElement().

Definition at line 134 of file ROJTRTurnDefLoader.h.

Referenced by addToEdge(), and myStartElement().

The network to set the information into.

Definition at line 131 of file ROJTRTurnDefLoader.h.

Referenced by addToEdge(), beginFromEdge(), myCharacters(), and myStartElement().


The documentation for this class was generated from the following files:

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