RORDLoader_SUMOBase Class Reference

#include <RORDLoader_SUMOBase.h>

Inheritance diagram for RORDLoader_SUMOBase:

ROTypedXMLRoutesLoader ROAbstractRouteDefLoader SUMOSAXHandler GenericSAXHandler

Detailed Description

The base class for SUMO-native route handlers.

As both the SUMO-routes and the SUMO-route alternatives handlers share a set of processing functions, we've joined these functions within a single class (this one).

Definition at line 61 of file RORDLoader_SUMOBase.h.


Public Member Functions

void characters (const XMLCh *const chars, const XERCES3_SIZE_t length)
 The inherited method called when characters occured.
void endDocument ()
 Called when the document has ended.
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.
 RORDLoader_SUMOBase (RONet &net, SUMOTime begin, SUMOTime end, SUMOReal gawronBeta, SUMOReal gawronA, int maxRouteNumber, bool tryRepair, bool withTaz, const std::string &file="") throw (ProcessError)
 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.
 ~RORDLoader_SUMOBase () throw ()
 Destructor.
inherited from ROAbstractRouteDefLoader
bool ended () const throw ()
 Returns the information whether no routes are available from this loader anymore.
bool readRoutesAtLeastUntil (SUMOTime time, bool skipping) throw (ProcessError)
 Adds routes from the file until the given time is reached.
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.
inherited from ROAbstractRouteDefLoader
SUMOTime getLastReadTimeStep () const throw ()
 Returns the time the current (last read) route starts at.

Protected Member Functions

std::string buildErrorMessage (const SAXParseException &exception) throw ()
 Builds an error message.
bool closeVehicle () throw ()
void startAlternative (const SUMOSAXAttributes &attrs)
 Begins the parsing of the next route alternative in the file.
void startRoute (const SUMOSAXAttributes &attrs)
 Begins the parsing of a route alternative of the opened route.
inherited from ROTypedXMLRoutesLoader
void beginNextRoute () throw ()
 Returns Initialises the reading of a further route.
bool nextRouteRead () throw ()
inherited from GenericSAXHandler
void myCharacters (SumoXMLTag element, const std::string &chars) throw (ProcessError)
 Called when characters occure.
virtual void myEndElement (SumoXMLTag element) throw (ProcessError)
 Called when a closing tag occurs.
virtual void myStartElement (SumoXMLTag element, const SUMOSAXAttributes &attrs) throw (ProcessError)
 Called on the opening of a tag;.

Protected Attributes

bool myAltIsValid
 Information whether the currently parsed alternatives set is valid.
SUMOTime myBegin
 The time for which the first route shall be loaded.
RGBColormyColor
 The color of the current route/vehicle.
SUMOReal myCost
 The costs of the current alternative.
RORouteDef_AlternativesmyCurrentAlternatives
 The currently parsed route alternatives.
SUMOTime myCurrentDepart
 The currently read vehicle's depart.
bool myCurrentIsOk
 Information whether the currently parsed item is valid.
RORouteDef_CompletemyCurrentRoute
 The currently parsed route.
std::string myCurrentRouteName
 The name of the currently parsed route.
SUMOVTypeParametermyCurrentVType
 The currently parsed vehicle type.
SUMOTime myEnd
 The time for which the first route shall be loaded.
bool myEnded
 Information whether the whole file has been parsed.
SUMOReal myGawronA
 gawron beta - value
SUMOReal myGawronBeta
 gawron beta - value
bool myHaveNextRoute
 Information whether a further route has been read.
int myMaxRouteNumber
 The maximum route alternatives number.
RONetmyNet
 The network to add routes to.
SAX2XMLReader * myParser
 The parser used.
SUMOReal myProbability
 The probability of the current alternative's usage.
XMLPScanToken myToken
 Information about the current position within the file.
bool myTryRepair
 Information whether a read route shall be tried to be repaired.
SUMOVehicleParametermyVehicleParameter
 The parsed vehicle parameter.
const bool myWithTaz
 Information whether zones (districts) are used as origins / destinations.

Private Member Functions

RORDLoader_SUMOBaseoperator= (const RORDLoader_SUMOBase &src)
 Invalidated assignment operator.
 RORDLoader_SUMOBase (const RORDLoader_SUMOBase &src)
 Invalidated copy constructor.

Constructor & Destructor Documentation

RORDLoader_SUMOBase::RORDLoader_SUMOBase ( RONet net,
SUMOTime  begin,
SUMOTime  end,
SUMOReal  gawronBeta,
SUMOReal  gawronA,
int  maxRouteNumber,
bool  tryRepair,
bool  withTaz,
const std::string &  file = "" 
) throw (ProcessError)

Constructor.

Definition at line 52 of file RORDLoader_SUMOBase.cpp.

00057         : ROTypedXMLRoutesLoader(net, begin, end, file),
00058         myVehicleParameter(0), myCurrentIsOk(true), myAltIsValid(true), myHaveNextRoute(false),
00059         myCurrentAlternatives(0),
00060         myGawronBeta(gawronBeta), myGawronA(gawronA), myMaxRouteNumber(maxRouteNumber),
00061         myCurrentRoute(0), myCurrentDepart(-1), myTryRepair(tryRepair), myWithTaz(withTaz),
00062         myColor(0), myCurrentVType(0) {
00063 }

RORDLoader_SUMOBase::~RORDLoader_SUMOBase (  )  throw ()

Destructor.

Definition at line 66 of file RORDLoader_SUMOBase.cpp.

References myColor, myCurrentAlternatives, myCurrentRoute, and myVehicleParameter.

00066                                                   {
00067     // clean up (on failure)
00068     delete myCurrentAlternatives;
00069     delete myCurrentRoute;
00070     delete myVehicleParameter;
00071     delete myColor;
00072 }

RORDLoader_SUMOBase::RORDLoader_SUMOBase ( const RORDLoader_SUMOBase src  )  [private]

Invalidated copy constructor.


Member Function Documentation

void RORDLoader_SUMOBase::beginNextRoute (  )  throw () [protected, virtual]

Returns Initialises the reading of a further route.

Todo:
recheck/refactor
See also:
ROTypedXMLRoutesLoader::beginNextRoute

Implements ROTypedXMLRoutesLoader.

Definition at line 330 of file RORDLoader_SUMOBase.cpp.

References myHaveNextRoute.

00330                                             {
00331     myHaveNextRoute = false;
00332 }

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 }

bool RORDLoader_SUMOBase::closeVehicle (  )  throw () [protected]

Definition at line 301 of file RORDLoader_SUMOBase.cpp.

References RONet::addVehicle(), SUMOVehicleParameter::depart, MsgHandler::getErrorInstance(), RONet::getRouteDef(), RONet::getVehicleTypeSecure(), SUMOVehicleParameter::id, MsgHandler::inform(), ROAbstractRouteDefLoader::myBegin, myCurrentIsOk, ROAbstractRouteDefLoader::myEnd, ROAbstractRouteDefLoader::myNet, myVehicleParameter, SUMOVehicleParameter::routeid, and SUMOVehicleParameter::vtypeid.

Referenced by myEndElement().

00301                                           {
00302     // get the vehicle id
00303     if (myVehicleParameter->depart<myBegin||myVehicleParameter->depart>=myEnd) {
00304         myCurrentIsOk = false;
00305         return false;
00306     }
00307     // get vehicle type
00308     SUMOVTypeParameter *type = myNet.getVehicleTypeSecure(myVehicleParameter->vtypeid);
00309     // get the route
00310     RORouteDef *route = myNet.getRouteDef(myVehicleParameter->routeid);
00311     if (route==0) {
00312         route = myNet.getRouteDef("!" + myVehicleParameter->id);
00313     }
00314     if (route==0) {
00315         MsgHandler::getErrorInstance()->inform("The route of the vehicle '" + myVehicleParameter->id + "' is not known.");
00316         myCurrentIsOk = false;
00317         return false;
00318     }
00319     // build the vehicle
00320     if (!MsgHandler::getErrorInstance()->wasInformed()) {
00321         ROVehicle *veh = new ROVehicle(*myVehicleParameter, route, type);
00322         myNet.addVehicle(myVehicleParameter->id, veh);
00323         return true;
00324     }
00325     return false;
00326 }

void ROTypedXMLRoutesLoader::endDocument (  )  [inherited]

Called when the document has ended.

Todo:
Recheck usage of route loaders; it is not very fine to have one that use a parser and other that do not

Definition at line 81 of file ROTypedXMLRoutesLoader.cpp.

References ROTypedXMLRoutesLoader::myEnded.

00081                                     {
00082     myEnded = true;
00083 }

bool ROTypedXMLRoutesLoader::ended (  )  const throw () [inline, virtual, inherited]

Returns the information whether no routes are available from this loader anymore.

Returns:
Whether the whole input has been processed

Implements ROAbstractRouteDefLoader.

Definition at line 97 of file ROTypedXMLRoutesLoader.h.

References ROTypedXMLRoutesLoader::myEnded.

Referenced by ROTypedXMLRoutesLoader::readRoutesAtLeastUntil().

00097                                {
00098         return myEnded;
00099     }

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]

SUMOTime RORDLoader_SUMOBase::getLastReadTimeStep (  )  const throw () [inline, virtual]

Returns the time the current (last read) route starts at.

Returns:
The least time step that was read by this reader

Implements ROAbstractRouteDefLoader.

Definition at line 82 of file RORDLoader_SUMOBase.h.

References myCurrentDepart.

00082                                                  {
00083         return myCurrentDepart;
00084     }

void RORDLoader_SUMOBase::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 185 of file RORDLoader_SUMOBase.cpp.

References RORouteDef_Alternatives::addLoadedAlternative(), SUMOVehicleParameter::fromTaz, RONet::getEdge(), MsgHandler::getErrorInstance(), Named::getID(), StringTokenizer::hasNext(), SUMOVehicleParameter::id, MsgHandler::inform(), myAltIsValid, myColor, myCost, myCurrentAlternatives, myCurrentIsOk, myCurrentRoute, myCurrentRouteName, ROAbstractRouteDefLoader::myNet, myProbability, myTryRepair, myVehicleParameter, myWithTaz, StringTokenizer::next(), SUMO_TAG_ROUTE, SUMOVehicleParameter::toTaz, VEHPARS_TAZ_SET, and SUMOVehicleParameter::wasSet().

Referenced by startRoute().

00186                                                                               {
00187     // process routes only, all other elements do
00188     //  not have embedded characters
00189     if (element!=SUMO_TAG_ROUTE) {
00190         return;
00191     }
00192     if (!myAltIsValid) {
00193         return;
00194     }
00195     if (myCurrentRoute!=0) {
00196         return;
00197     }
00198     // check whether the costs and the probability are valid
00199     if (myCurrentAlternatives!=0) {
00200         if (myCost<0||myProbability<0||!myCurrentIsOk) {
00201             return;
00202         }
00203     }
00204     // build the list of edges
00205     std::vector<const ROEdge*> *list = new std::vector<const ROEdge*>();
00206     if (myWithTaz && myVehicleParameter->wasSet(VEHPARS_TAZ_SET)) {
00207         ROEdge *edge = myNet.getEdge(myVehicleParameter->fromTaz+"-source");
00208         if (edge!=0) {
00209             list->push_back(edge);
00210         } else {
00211             MsgHandler::getErrorInstance()->inform("The vehicle '" + myVehicleParameter->id + "' contains the unknown zone '" + myVehicleParameter->fromTaz + "'.");
00212             myCurrentIsOk = false;
00213         }
00214     }
00215     StringTokenizer st(chars);
00216     while (myCurrentIsOk&&st.hasNext()) { // !!! too slow !!!
00217         const std::string id = st.next();
00218         ROEdge *edge = myNet.getEdge(id);
00219         if (edge!=0) {
00220             list->push_back(edge);
00221         } else {
00222             if (!myTryRepair) {
00223                 std::string rid = myCurrentAlternatives!=0 ? myCurrentAlternatives->getID() : myCurrentRouteName;
00224                 MsgHandler::getErrorInstance()->inform("The route '" + rid + "' contains the unknown edge '" + id + "'.");
00225                 myCurrentIsOk = false;
00226             }
00227         }
00228     }
00229     if (myWithTaz && myVehicleParameter->wasSet(VEHPARS_TAZ_SET)) {
00230         ROEdge *edge = myNet.getEdge(myVehicleParameter->toTaz);
00231         if (edge!=0) {
00232             list->push_back(edge);
00233         } else {
00234             MsgHandler::getErrorInstance()->inform("The vehicle '" + myVehicleParameter->id + "' contains the unknown zone '" + myVehicleParameter->fromTaz + "'.");
00235             myCurrentIsOk = false;
00236         }
00237     }
00238     if (myCurrentIsOk) {
00239         if (myCurrentAlternatives!=0) {
00240             myCurrentAlternatives->addLoadedAlternative(
00241                 new RORoute(myCurrentAlternatives->getID(), myCost, myProbability, *list, myColor));
00242         } else {
00243             myCurrentRoute = new RORouteDef_Complete(myCurrentRouteName, myColor, *list, myTryRepair);
00244         }
00245         myColor = 0;
00246     }
00247     delete list;
00248 }

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

Called when a closing tag occurs.

Parameters:
[in] element ID of the currently opened element
Exceptions:
ProcessError If something fails
See also:
GenericSAXHandler::myEndElement

Reimplemented from GenericSAXHandler.

Definition at line 252 of file RORDLoader_SUMOBase.cpp.

References RONet::addRouteDef(), RONet::addVehicleType(), closeVehicle(), SUMOVehicleParserHelper::closeVTypeParsing(), myAltIsValid, myCurrentAlternatives, myCurrentIsOk, myCurrentRoute, myCurrentVType, myHaveNextRoute, ROAbstractRouteDefLoader::myNet, myVehicleParameter, SUMO_TAG_ROUTE, SUMO_TAG_ROUTE_DISTRIBUTION, SUMO_TAG_VEHICLE, and SUMO_TAG_VTYPE.

00252                                                                         {
00253     switch (element) {
00254     case SUMO_TAG_ROUTE:
00255         if (!myAltIsValid) {
00256             return;
00257         }
00258         if (myCurrentRoute!=0&&myCurrentIsOk) {
00259             if (myCurrentAlternatives==0) {
00260                 myNet.addRouteDef(myCurrentRoute);
00261                 myCurrentRoute = 0;
00262             }
00263             if (myVehicleParameter==0) {
00264                 myHaveNextRoute = true;
00265             }
00266             myCurrentRoute = 0;
00267         }
00268         break;
00269     case SUMO_TAG_ROUTE_DISTRIBUTION:
00270         if (!myCurrentIsOk) {
00271             return;
00272         }
00273         if (myVehicleParameter==0) {
00274             myHaveNextRoute = true;
00275         }
00276         myNet.addRouteDef(myCurrentAlternatives);
00277         myCurrentRoute = 0;
00278         myCurrentAlternatives = 0;
00279         break;
00280     case SUMO_TAG_VEHICLE:
00281         closeVehicle();
00282         delete myVehicleParameter;
00283         myVehicleParameter = 0;
00284         myHaveNextRoute = true;
00285         break;
00286     case SUMO_TAG_VTYPE: {
00287         SUMOVehicleParserHelper::closeVTypeParsing(*myCurrentVType);
00288         myNet.addVehicleType(myCurrentVType);
00289         myCurrentVType = 0;
00290     }
00291     default:
00292         break;
00293     }
00294     if (!myCurrentIsOk) {
00295         throw ProcessError();
00296     }
00297 }

void RORDLoader_SUMOBase::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 76 of file RORDLoader_SUMOBase.cpp.

References SUMOVehicleParserHelper::beginVTypeParsing(), SUMOVehicleParameter::depart, myAltIsValid, myCurrentDepart, myCurrentIsOk, myCurrentVType, myVehicleParameter, SUMOVehicleParserHelper::parseVehicleAttributes(), SUMOVehicleParserHelper::parseVTypeEmbedded(), startAlternative(), startRoute(), SUMO_TAG_ROUTE, SUMO_TAG_ROUTE_DISTRIBUTION, SUMO_TAG_VEHICLE, and SUMO_TAG_VTYPE.

00077                                                                                         {
00078     switch (element) {
00079     case SUMO_TAG_ROUTE:
00080         startRoute(attrs);
00081         break;
00082     case SUMO_TAG_VEHICLE:
00083         // try to parse the vehicle definition
00084         delete myVehicleParameter;
00085         myVehicleParameter = 0;
00086         myVehicleParameter = SUMOVehicleParserHelper::parseVehicleAttributes(attrs);
00087         if (myVehicleParameter!=0) {
00088             myCurrentDepart = myVehicleParameter->depart;
00089         }
00090         myCurrentIsOk = myVehicleParameter!=0;
00091         break;
00092     case SUMO_TAG_VTYPE:
00093         myCurrentVType = SUMOVehicleParserHelper::beginVTypeParsing(attrs);
00094         break;
00095     case SUMO_TAG_ROUTE_DISTRIBUTION:
00096         myAltIsValid = true;
00097         startAlternative(attrs);
00098         if (!myCurrentIsOk) {
00099             myAltIsValid = false;
00100         }
00101         break;
00102     default:
00103         break;
00104     }
00105     // parse embedded vtype information
00106     if (myCurrentVType!=0&&element!=SUMO_TAG_VTYPE) {
00107         SUMOVehicleParserHelper::parseVTypeEmbedded(*myCurrentVType, element, attrs);
00108         return;
00109     }
00110     if (!myCurrentIsOk) {
00111         throw ProcessError();
00112     }
00113 }

bool RORDLoader_SUMOBase::nextRouteRead (  )  throw () [inline, protected, virtual]

Returns the information whether a route was read

Returns:
Whether a further route was read
See also:
ROTypedXMLRoutesLoader::nextRouteRead

Implements ROTypedXMLRoutesLoader.

Definition at line 141 of file RORDLoader_SUMOBase.h.

References myHaveNextRoute.

00141                                  {
00142         return myHaveNextRoute;
00143     }

RORDLoader_SUMOBase& RORDLoader_SUMOBase::operator= ( const RORDLoader_SUMOBase src  )  [private]

Invalidated assignment operator.

bool ROTypedXMLRoutesLoader::readRoutesAtLeastUntil ( SUMOTime  time,
bool  skipping 
) throw (ProcessError) [virtual, inherited]

Adds routes from the file until the given time is reached.

Parameters:
[in] time The time until which route definitions shall be loaded
[in] skipping Whether routes shall not be added
Returns:
Whether any errors occured
Exceptions:
ProcessError If a major error occured
See also:
ROAbstractRouteDefLoader::readRoutesAtLeastUntil

Implements ROAbstractRouteDefLoader.

Reimplemented in RORDGenerator_ODAmounts.

Definition at line 69 of file ROTypedXMLRoutesLoader.cpp.

References ROTypedXMLRoutesLoader::beginNextRoute(), ROTypedXMLRoutesLoader::ended(), ROAbstractRouteDefLoader::getLastReadTimeStep(), ROTypedXMLRoutesLoader::myParser, ROTypedXMLRoutesLoader::myToken, and ROTypedXMLRoutesLoader::nextRouteRead().

00069                                                                                                {
00070     while (getLastReadTimeStep()<time&&!ended()) {
00071         beginNextRoute();
00072         while (!nextRouteRead()&&!ended()) {
00073             myParser->parseNext(myToken);
00074         }
00075     }
00076     return true;
00077 }

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 RORDLoader_SUMOBase::startAlternative ( const SUMOSAXAttributes attrs  )  [protected]

Begins the parsing of the next route alternative in the file.

Definition at line 155 of file RORDLoader_SUMOBase.cpp.

References MsgHandler::getErrorInstance(), SUMOSAXAttributes::getIntReporting(), SUMOVehicleParameter::id, MsgHandler::inform(), myCurrentAlternatives, myCurrentIsOk, myGawronA, myGawronBeta, myMaxRouteNumber, myVehicleParameter, SUMOSAXAttributes::setIDFromAttributes(), and SUMO_ATTR_LAST.

Referenced by myStartElement().

00155                                                                     {
00156     // try to get the id
00157     myCurrentIsOk = true;
00158     std::string id;
00159     if (myVehicleParameter!=0) {
00160         id = myVehicleParameter->id;
00161         if (id=="") {
00162             MsgHandler::getErrorInstance()->inform("Missing 'id' of a routeDistribution.");
00163             myCurrentIsOk = false;
00164             return;
00165         }
00166         id = "!" + id;
00167     } else {
00168         if (!attrs.setIDFromAttributes("routeDistribution", id)) {
00169             myCurrentIsOk = false;
00170             return;
00171         }
00172     }
00173     // try to get the index of the last element
00174     int index = attrs.getIntReporting(SUMO_ATTR_LAST, "route", id.c_str(), myCurrentIsOk);
00175     if (myCurrentIsOk&&index<0) {
00176         MsgHandler::getErrorInstance()->inform("Negative index of a route alternative (id='" + id + "').");
00177         myCurrentIsOk = false;
00178         return;
00179     }
00180     // build the alternative cont
00181     myCurrentAlternatives = new RORouteDef_Alternatives(id, index, myGawronBeta, myGawronA, myMaxRouteNumber);
00182 }

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 RORDLoader_SUMOBase::startRoute ( const SUMOSAXAttributes attrs  )  [protected]

Begins the parsing of a route alternative of the opened route.

Definition at line 117 of file RORDLoader_SUMOBase.cpp.

References MsgHandler::getErrorInstance(), Named::getID(), SUMOSAXAttributes::getOptStringReporting(), SUMOSAXAttributes::getString(), SUMOSAXAttributes::getStringReporting(), SUMOSAXAttributes::getSUMORealReporting(), SUMOSAXAttributes::hasAttribute(), SUMOVehicleParameter::id, MsgHandler::inform(), myAltIsValid, myCharacters(), myColor, myCost, myCurrentAlternatives, myCurrentIsOk, myCurrentRouteName, myProbability, myVehicleParameter, RGBColor::parseColorReporting(), SUMO_ATTR_COLOR, SUMO_ATTR_COST, SUMO_ATTR_EDGES, SUMO_ATTR_ID, SUMO_ATTR_PROB, and SUMO_TAG_ROUTE.

Referenced by myStartElement().

00117                                                               {
00118     delete myColor;
00119     myColor = 0;
00120     if (!myAltIsValid) {
00121         return;
00122     }
00123     if (attrs.hasAttribute(SUMO_ATTR_COLOR)) {
00124         myColor = new RGBColor(RGBColor::parseColorReporting(attrs.getString(SUMO_ATTR_COLOR), "route", 0, true, myCurrentIsOk));
00125     }
00126     if (myCurrentAlternatives==0) {
00127         myCurrentIsOk = true;
00128         if (myVehicleParameter!=0) {
00129             myCurrentRouteName = attrs.getOptStringReporting(SUMO_ATTR_ID, "route", 0, myCurrentIsOk, "!" + myVehicleParameter->id);
00130         } else {
00131             myCurrentRouteName = attrs.getStringReporting(SUMO_ATTR_ID, "route", 0, myCurrentIsOk);
00132         }
00133     } else {
00134         // parse route alternative...
00135         myCost = attrs.getSUMORealReporting(SUMO_ATTR_COST, "route(alternative)", myCurrentAlternatives->getID().c_str(), myCurrentIsOk);
00136         myProbability = attrs.getSUMORealReporting(SUMO_ATTR_PROB, "route(alternative)", myCurrentAlternatives->getID().c_str(), myCurrentIsOk);
00137         if (myCurrentIsOk&&myCost<0) {
00138             MsgHandler::getErrorInstance()->inform("Invalid cost in alternative for route '" + myCurrentAlternatives->getID() + "' (" + toString<SUMOReal>(myCost) + ").");
00139             myCurrentIsOk = false;
00140             return;
00141         }
00142         if (myCurrentIsOk&&myProbability<0) {
00143             MsgHandler::getErrorInstance()->inform("Invalid probability in alternative for route '" + myCurrentAlternatives->getID() + "' (" + toString<SUMOReal>(myProbability) + ").");
00144             myCurrentIsOk = false;
00145             return;
00146         }
00147     }
00148     if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
00149         myCharacters(SUMO_TAG_ROUTE, attrs.getStringReporting(SUMO_ATTR_EDGES, "route", 0, myCurrentIsOk));
00150     }
00151 }

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

Information whether the currently parsed alternatives set is valid.

Definition at line 166 of file RORDLoader_SUMOBase.h.

Referenced by myCharacters(), myEndElement(), myStartElement(), and startRoute().

The color of the current route/vehicle.

Definition at line 160 of file RORDLoader_SUMOBase.h.

Referenced by myCharacters(), startRoute(), and ~RORDLoader_SUMOBase().

SUMOReal RORDLoader_SUMOBase::myCost [protected]

The costs of the current alternative.

Definition at line 175 of file RORDLoader_SUMOBase.h.

Referenced by myCharacters(), and startRoute().

The currently parsed route alternatives.

Definition at line 172 of file RORDLoader_SUMOBase.h.

Referenced by myCharacters(), myEndElement(), startAlternative(), startRoute(), and ~RORDLoader_SUMOBase().

The currently read vehicle's depart.

Definition at line 202 of file RORDLoader_SUMOBase.h.

Referenced by getLastReadTimeStep(), and myStartElement().

Information whether the currently parsed item is valid.

Definition at line 163 of file RORDLoader_SUMOBase.h.

Referenced by closeVehicle(), myCharacters(), myEndElement(), myStartElement(), startAlternative(), and startRoute().

The currently parsed route.

Definition at line 196 of file RORDLoader_SUMOBase.h.

Referenced by myCharacters(), myEndElement(), and ~RORDLoader_SUMOBase().

std::string RORDLoader_SUMOBase::myCurrentRouteName [protected]

The name of the currently parsed route.

Definition at line 199 of file RORDLoader_SUMOBase.h.

Referenced by myCharacters(), and startRoute().

The currently parsed vehicle type.

Definition at line 205 of file RORDLoader_SUMOBase.h.

Referenced by myEndElement(), and myStartElement().

SUMOTime ROAbstractRouteDefLoader::myEnd [protected, inherited]

The time for which the first route shall be loaded.

Definition at line 110 of file ROAbstractRouteDefLoader.h.

Referenced by RORDGenerator_ODAmounts::buildForTimeStep(), closeVehicle(), and RORDLoader_TripDefs::myEndElement().

bool ROTypedXMLRoutesLoader::myEnded [protected, inherited]

Information whether the whole file has been parsed.

Definition at line 139 of file ROTypedXMLRoutesLoader.h.

Referenced by RORDGenerator_ODAmounts::buildForTimeStep(), ROTypedXMLRoutesLoader::endDocument(), and ROTypedXMLRoutesLoader::ended().

SUMOReal RORDLoader_SUMOBase::myGawronA [protected]

gawron beta - value

Definition at line 184 of file RORDLoader_SUMOBase.h.

Referenced by startAlternative().

SUMOReal RORDLoader_SUMOBase::myGawronBeta [protected]

gawron beta - value

Definition at line 181 of file RORDLoader_SUMOBase.h.

Referenced by startAlternative().

Information whether a further route has been read.

Definition at line 169 of file RORDLoader_SUMOBase.h.

Referenced by beginNextRoute(), myEndElement(), and nextRouteRead().

The maximum route alternatives number.

Definition at line 187 of file RORDLoader_SUMOBase.h.

Referenced by startAlternative().

RONet& ROAbstractRouteDefLoader::myNet [protected, inherited]

SAX2XMLReader* ROTypedXMLRoutesLoader::myParser [protected, inherited]

SUMOReal RORDLoader_SUMOBase::myProbability [protected]

The probability of the current alternative's usage.

Definition at line 178 of file RORDLoader_SUMOBase.h.

Referenced by myCharacters(), and startRoute().

XMLPScanToken ROTypedXMLRoutesLoader::myToken [protected, inherited]

Information about the current position within the file.

Definition at line 136 of file ROTypedXMLRoutesLoader.h.

Referenced by ROTypedXMLRoutesLoader::readRoutesAtLeastUntil(), and RORDGenerator_ODAmounts::RORDGenerator_ODAmounts().

Information whether a read route shall be tried to be repaired.

Definition at line 190 of file RORDLoader_SUMOBase.h.

Referenced by myCharacters().

The parsed vehicle parameter.

Definition at line 157 of file RORDLoader_SUMOBase.h.

Referenced by closeVehicle(), myCharacters(), myEndElement(), myStartElement(), startAlternative(), startRoute(), and ~RORDLoader_SUMOBase().

Information whether zones (districts) are used as origins / destinations.

Definition at line 193 of file RORDLoader_SUMOBase.h.

Referenced by myCharacters().


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

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