SUMOVehicleParserHelper Class Reference

#include <SUMOVehicleParserHelper.h>


Detailed Description

Helper methods for parsing vehicle attributes.

This class supports helper methods for parsing a vehicle's attributes.

Definition at line 51 of file SUMOVehicleParserHelper.h.


Static Public Member Functions

static SUMOVTypeParameterbeginVTypeParsing (const SUMOSAXAttributes &attrs) throw (ProcessError)
 Starts to parse a vehicle type.
static void closeVTypeParsing (SUMOVTypeParameter &vtype) throw ()
 Closes parsing of the vehicle type.
static SUMOEmissionClass parseEmissionClass (const SUMOSAXAttributes &attrs, const std::string &type, const std::string &id) throw ()
 Parses the vehicle emission class.
static SUMOVehicleParameterparseFlowAttributes (const SUMOSAXAttributes &attrs) throw (ProcessError)
 Parses a flow's attributes.
static SUMOVehicleShape parseGuiShape (const SUMOSAXAttributes &attrs, const std::string &type, const std::string &id) throw ()
 Parses the vehicle class.
static SUMOVehicleParameterparseVehicleAttributes (const SUMOSAXAttributes &attrs, bool skipID=false, bool skipDepart=false) throw (ProcessError)
 Parses a vehicle's attributes.
static SUMOVehicleClass parseVehicleClass (const SUMOSAXAttributes &attrs, const std::string &type, const std::string &id) throw ()
 Parses the vehicle class.
static void parseVTypeEmbedded (SUMOVTypeParameter &into, int element, const SUMOSAXAttributes &attrs, bool fromVType=false) throw (ProcessError)
 Parses an element embedded in vtype definition.
static void parseVTypeEmbedded_BKerner (SUMOVTypeParameter &into, const SUMOSAXAttributes &attrs) throw (ProcessError)
 Parses the Kerner definition embedded in vtype definition.
static void parseVTypeEmbedded_IDM (SUMOVTypeParameter &into, const SUMOSAXAttributes &attrs) throw (ProcessError)
 Parses the IDM definition embedded in vtype definition.
static void parseVTypeEmbedded_Krauss (SUMOVTypeParameter &into, const SUMOSAXAttributes &attrs, bool fromVType=false) throw (ProcessError)
 Parses the Krauss definition embedded in vtype definition.

Static Private Member Functions

static void parseCommonAttributes (const SUMOSAXAttributes &attrs, SUMOVehicleParameter *ret, std::string element) throw (ProcessError)
 Parses attributes common to vehicles and flows.

Member Function Documentation

SUMOVTypeParameter * SUMOVehicleParserHelper::beginVTypeParsing ( const SUMOSAXAttributes attrs  )  throw (ProcessError) [static]

Starts to parse a vehicle type.

Parameters:
[in] attr The SAX-attributes to get vehicle parameter from
Exceptions:
ProcessError If an attribute's value is invalid
See also:
SUMOVTypeParameter

Definition at line 349 of file SUMOVehicleParserHelper.cpp.

References SUMOVTypeParameter::color, SUMOVTypeParameter::defaultProbability, SUMOVTypeParameter::emissionClass, SUMOVTypeParameter::id, SUMOVTypeParameter::length, SUMOVTypeParameter::maxSpeed, SUMOVTypeParameter::offset, RGBColor::parseColorReporting(), SUMOVTypeParameter::setParameter, SUMOVTypeParameter::shape, SUMOVTypeParameter::speedDev, SUMOVTypeParameter::speedFactor, SUMO_ATTR_COLOR, SUMO_ATTR_EMISSIONCLASS, SUMO_ATTR_GUIOFFSET, SUMO_ATTR_GUISHAPE, SUMO_ATTR_GUIWIDTH, SUMO_ATTR_LENGTH, SUMO_ATTR_MAXSPEED, SUMO_ATTR_PROB, SUMO_ATTR_SPEEDDEV, SUMO_ATTR_SPEEDFACTOR, SUMO_ATTR_VCLASS, SUMO_TAG_CF_KRAUSS, SUMOVTypeParameter::vehicleClass, VTYPEPARS_COLOR_SET, VTYPEPARS_EMISSIONCLASS_SET, VTYPEPARS_LENGTH_SET, VTYPEPARS_MAXSPEED_SET, VTYPEPARS_OFFSET_SET, VTYPEPARS_PROBABILITY_SET, VTYPEPARS_SHAPE_SET, VTYPEPARS_SPEEDDEVIATION_SET, VTYPEPARS_SPEEDFACTOR_SET, VTYPEPARS_VEHICLECLASS_SET, VTYPEPARS_WIDTH_SET, and SUMOVTypeParameter::width.

Referenced by RORDLoader_TripDefs::myStartElement(), RORDLoader_SUMOBase::myStartElement(), and MSRouteHandler::myStartElement().

00349                                                                                              {
00350     SUMOVTypeParameter *vtype = new SUMOVTypeParameter();
00351     if (!attrs.setIDFromAttributes("vtype", vtype->id)) {
00352         throw ProcessError();
00353     }
00354     bool ok = true;
00355     if (attrs.hasAttribute(SUMO_ATTR_LENGTH)) {
00356         vtype->length = attrs.getSUMORealReporting(SUMO_ATTR_LENGTH, "vtype", vtype->id.c_str(), ok);
00357         vtype->setParameter |= VTYPEPARS_LENGTH_SET;
00358     }
00359     if (attrs.hasAttribute(SUMO_ATTR_MAXSPEED)) {
00360         vtype->maxSpeed = attrs.getSUMORealReporting(SUMO_ATTR_MAXSPEED, "vtype", vtype->id.c_str(), ok);
00361         vtype->setParameter |= VTYPEPARS_MAXSPEED_SET;
00362     }
00363     if (attrs.hasAttribute(SUMO_ATTR_SPEEDFACTOR)) {
00364         vtype->speedFactor = attrs.getSUMORealReporting(SUMO_ATTR_SPEEDFACTOR, "vtype", vtype->id.c_str(), ok);
00365         vtype->setParameter |= VTYPEPARS_SPEEDFACTOR_SET;
00366     }
00367     if (attrs.hasAttribute(SUMO_ATTR_SPEEDDEV)) {
00368         vtype->speedDev = attrs.getSUMORealReporting(SUMO_ATTR_SPEEDDEV, "vtype", vtype->id.c_str(), ok);
00369         vtype->setParameter |= VTYPEPARS_SPEEDDEVIATION_SET;
00370     }
00371     if (attrs.hasAttribute(SUMO_ATTR_EMISSIONCLASS)) {
00372         vtype->emissionClass = parseEmissionClass(attrs, "vtype", vtype->id);
00373         vtype->setParameter |= VTYPEPARS_EMISSIONCLASS_SET;
00374     }
00375     if (attrs.hasAttribute(SUMO_ATTR_VCLASS)) {
00376         vtype->vehicleClass = parseVehicleClass(attrs, "vtype", vtype->id);
00377         vtype->setParameter |= VTYPEPARS_VEHICLECLASS_SET;
00378     }
00379     if (attrs.hasAttribute(SUMO_ATTR_GUIWIDTH)) {
00380         vtype->width = attrs.getSUMORealReporting(SUMO_ATTR_GUIWIDTH, "vtype", vtype->id.c_str(), ok);
00381         vtype->setParameter |= VTYPEPARS_WIDTH_SET;
00382     }
00383     if (attrs.hasAttribute(SUMO_ATTR_GUIOFFSET)) {
00384         vtype->offset = attrs.getSUMORealReporting(SUMO_ATTR_GUIOFFSET, "vtype", vtype->id.c_str(), ok);
00385         vtype->setParameter |= VTYPEPARS_OFFSET_SET;
00386     }
00387     if (attrs.hasAttribute(SUMO_ATTR_GUISHAPE)) {
00388         vtype->shape = parseGuiShape(attrs, "vtype", vtype->id);
00389         vtype->setParameter |= VTYPEPARS_SHAPE_SET;
00390     }
00391     if (attrs.hasAttribute(SUMO_ATTR_COLOR)) {
00392         vtype->color = RGBColor::parseColorReporting(attrs.getString(SUMO_ATTR_COLOR), "vtype", vtype->id.c_str(), true, ok);
00393         vtype->setParameter |= VTYPEPARS_COLOR_SET;
00394     } else {
00395         vtype->color = RGBColor(1,1,0);
00396     }
00397     if (attrs.hasAttribute(SUMO_ATTR_PROB)) {
00398         vtype->defaultProbability = attrs.getSUMORealReporting(SUMO_ATTR_PROB, "vtype", vtype->id.c_str(), ok);
00399         vtype->setParameter |= VTYPEPARS_PROBABILITY_SET;
00400     }
00401     try {
00402         parseVTypeEmbedded(*vtype, SUMO_TAG_CF_KRAUSS, attrs, true);
00403     } catch (ProcessError &) {
00404         throw;
00405     }
00406     if (!ok) {
00407         throw ProcessError();
00408     }
00409     return vtype;
00410 }

static void SUMOVehicleParserHelper::closeVTypeParsing ( SUMOVTypeParameter vtype  )  throw () [inline, static]

Closes parsing of the vehicle type.

Returns:
The resulting vehicle type parameter
See also:
SUMOVTypeParameter

Definition at line 142 of file SUMOVehicleParserHelper.h.

Referenced by RORDLoader_TripDefs::myEndElement(), RORDLoader_SUMOBase::myEndElement(), and MSRouteHandler::myEndElement().

00142 { }

void SUMOVehicleParserHelper::parseCommonAttributes ( const SUMOSAXAttributes attrs,
SUMOVehicleParameter ret,
std::string  element 
) throw (ProcessError) [static, private]

Parses attributes common to vehicles and flows.

Parses all attributes stored in "SUMOVehicleParameter".

See also:
SUMOVehicleParameter
Parameters:
[in] attr The SAX-attributes to get vehicle parameter from
[out] ret The parameter to parse into
[in] element The name of the element (vehicle or flow)
Exceptions:
ProcessError If an attribute's value is invalid

Definition at line 187 of file SUMOVehicleParserHelper.cpp.

References TplConvert< E >::_2int(), TplConvert< E >::_2SUMOReal(), ARRIVAL_LANE_CURRENT, ARRIVAL_LANE_GIVEN, ARRIVAL_POS_GIVEN, ARRIVAL_POS_MAX, ARRIVAL_POS_RANDOM, ARRIVAL_SPEED_CURRENT, ARRIVAL_SPEED_GIVEN, RGBColor::DEFAULT_COLOR, DEPART_LANE_DEPARTLANE, DEPART_LANE_FREE, DEPART_LANE_GIVEN, DEPART_LANE_RANDOM, DEPART_POS_FREE, DEPART_POS_GIVEN, DEPART_POS_RANDOM, DEPART_POS_RANDOM_FREE, DEPART_SPEED_GIVEN, DEPART_SPEED_MAX, DEPART_SPEED_RANDOM, RGBColor::parseColor(), SUMO_ATTR_ARRIVALLANE, SUMO_ATTR_ARRIVALPOS, SUMO_ATTR_ARRIVALSPEED, SUMO_ATTR_COLOR, SUMO_ATTR_DEPARTLANE, SUMO_ATTR_DEPARTPOS, SUMO_ATTR_DEPARTSPEED, SUMO_ATTR_FROM_TAZ, SUMO_ATTR_LINE, SUMO_ATTR_ROUTE, SUMO_ATTR_TO_TAZ, SUMO_ATTR_TYPE, VEHPARS_ARRIVALLANE_SET, VEHPARS_ARRIVALPOS_SET, VEHPARS_ARRIVALSPEED_SET, VEHPARS_COLOR_SET, VEHPARS_DEPARTLANE_SET, VEHPARS_DEPARTPOS_SET, VEHPARS_DEPARTSPEED_SET, VEHPARS_LINE_SET, VEHPARS_ROUTE_SET, VEHPARS_TAZ_SET, and VEHPARS_VTYPE_SET.

00188                                                                           {
00189     //ret->refid = attrs.getStringSecure(SUMO_ATTR_REFID, "");
00190     bool ok = true;
00191     // parse route information
00192     if (attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
00193         ret->setParameter |= VEHPARS_ROUTE_SET; // !!! needed?
00194         ret->routeid = attrs.getStringReporting(SUMO_ATTR_ROUTE, "vehicle", 0, ok);
00195     }
00196     // parse type information
00197     if (attrs.hasAttribute(SUMO_ATTR_TYPE)) {
00198         ret->setParameter |= VEHPARS_VTYPE_SET; // !!! needed?
00199         ret->vtypeid = attrs.getStringReporting(SUMO_ATTR_TYPE, "vehicle", 0, ok);
00200     }
00201     // parse line information
00202     if (attrs.hasAttribute(SUMO_ATTR_LINE)) {
00203         ret->setParameter |= VEHPARS_LINE_SET; // !!! needed?
00204         ret->line = attrs.getStringReporting(SUMO_ATTR_LINE, "vehicle", 0, ok);
00205     }
00206     // parse zone information
00207     if (attrs.hasAttribute(SUMO_ATTR_FROM_TAZ) && attrs.hasAttribute(SUMO_ATTR_TO_TAZ)) {
00208         ret->setParameter |= VEHPARS_TAZ_SET;
00209         ret->fromTaz = attrs.getStringReporting(SUMO_ATTR_FROM_TAZ, "vehicle", 0, ok);
00210         ret->toTaz = attrs.getStringReporting(SUMO_ATTR_TO_TAZ, "vehicle", 0, ok);
00211     }
00212 
00213     // parse depart lane information
00214     if (attrs.hasAttribute(SUMO_ATTR_DEPARTLANE)) {
00215         ret->setParameter |= VEHPARS_DEPARTLANE_SET;
00216         const std::string helper = attrs.getStringReporting(SUMO_ATTR_DEPARTLANE, "vehicle", 0, ok);
00217         if (helper=="departlane") {
00218             ret->departLaneProcedure = DEPART_LANE_DEPARTLANE;
00219         } else if (helper=="random") {
00220             ret->departLaneProcedure = DEPART_LANE_RANDOM;
00221         } else if (helper=="free") {
00222             ret->departLaneProcedure = DEPART_LANE_FREE;
00223         } else {
00224             try {
00225                 ret->departLane = TplConvert<char>::_2int(helper.c_str());;
00226                 ret->departLaneProcedure = DEPART_LANE_GIVEN;
00227                 if (ret->departLane < 0) {
00228                     throw ProcessError("Invalid departlane definition for " + element + " '" + ret->id + "'");
00229                 }
00230             } catch (NumberFormatException &) {
00231                 throw ProcessError("Invalid departlane definition for " + element + " '" + ret->id + "'");
00232             } catch (EmptyData &) {
00233                 throw ProcessError("Invalid departlane definition for " + element + " '" + ret->id + "'");
00234             }
00235         }
00236     }
00237     // parse depart position information
00238     if (attrs.hasAttribute(SUMO_ATTR_DEPARTPOS)) {
00239         ret->setParameter |= VEHPARS_DEPARTPOS_SET;
00240         const std::string helper = attrs.getStringReporting(SUMO_ATTR_DEPARTPOS, "vehicle", 0, ok);
00241         if (helper=="random") {
00242             ret->departPosProcedure = DEPART_POS_RANDOM;
00243         } else if (helper=="random_free") {
00244             ret->departPosProcedure = DEPART_POS_RANDOM_FREE;
00245         } else if (helper=="free") {
00246             ret->departPosProcedure = DEPART_POS_FREE;
00247         } else {
00248             try {
00249                 ret->departPos = TplConvert<char>::_2SUMOReal(helper.c_str());
00250                 ret->departPosProcedure = DEPART_POS_GIVEN;
00251             } catch (NumberFormatException &) {
00252                 throw ProcessError("Invalid departpos definition for " + element + " '" + ret->id + "'");
00253             } catch (EmptyData &) {
00254                 throw ProcessError("Invalid departpos definition for " + element + " '" + ret->id + "'");
00255             }
00256         }
00257     }
00258     // parse depart position information
00259     if (attrs.hasAttribute(SUMO_ATTR_DEPARTSPEED)) {
00260         ret->setParameter |= VEHPARS_DEPARTSPEED_SET;
00261         std::string helper = attrs.getStringReporting(SUMO_ATTR_DEPARTSPEED, "vehicle", 0, ok);
00262         if (helper=="random") {
00263             ret->departSpeedProcedure = DEPART_SPEED_RANDOM;
00264         } else if (helper=="max") {
00265             ret->departSpeedProcedure = DEPART_SPEED_MAX;
00266         } else {
00267             try {
00268                 ret->departSpeed = TplConvert<char>::_2SUMOReal(helper.c_str());
00269                 ret->departSpeedProcedure = DEPART_SPEED_GIVEN;
00270             } catch (NumberFormatException &) {
00271                 throw ProcessError("Invalid departspeed definition for " + element + " '" + ret->id + "'");
00272             } catch (EmptyData &) {
00273                 throw ProcessError("Invalid departspeed definition for " + element + " '" + ret->id + "'");
00274             }
00275         }
00276     }
00277 
00278     // parse arrival lane information
00279     if (attrs.hasAttribute(SUMO_ATTR_ARRIVALLANE)) {
00280         ret->setParameter |= VEHPARS_ARRIVALLANE_SET;
00281         std::string helper = attrs.getStringReporting(SUMO_ATTR_ARRIVALLANE, "vehicle", 0, ok);
00282         if (helper=="current") {
00283             ret->arrivalLaneProcedure = ARRIVAL_LANE_CURRENT;
00284         } else {
00285             try {
00286                 ret->arrivalLane = TplConvert<char>::_2int(helper.c_str());;
00287                 ret->arrivalLaneProcedure = ARRIVAL_LANE_GIVEN;
00288             } catch (NumberFormatException &) {
00289                 throw ProcessError("Invalid arrivallane definition for " + element + " '" + ret->id + "'");
00290             } catch (EmptyData &) {
00291                 throw ProcessError("Invalid arrivallane definition for " + element + " '" + ret->id + "'");
00292             }
00293         }
00294     }
00295     // parse arrival position information
00296     if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
00297         ret->setParameter |= VEHPARS_ARRIVALPOS_SET;
00298         std::string helper = attrs.getStringReporting(SUMO_ATTR_ARRIVALPOS, "vehicle", 0, ok);
00299         if (helper=="random") {
00300             ret->arrivalPosProcedure = ARRIVAL_POS_RANDOM;
00301         } else if (helper=="max") {
00302             ret->arrivalPosProcedure = ARRIVAL_POS_MAX;
00303         } else {
00304             try {
00305                 ret->arrivalPos = TplConvert<char>::_2SUMOReal(helper.c_str());
00306                 ret->arrivalPosProcedure = ARRIVAL_POS_GIVEN;
00307             } catch (NumberFormatException &) {
00308                 throw ProcessError("Invalid arrivalpos definition for " + element + " '" + ret->id + "'");
00309             } catch (EmptyData &) {
00310                 throw ProcessError("Invalid arrivalpos definition for " + element + " '" + ret->id + "'");
00311             }
00312         }
00313     }
00314     // parse arrival position information
00315     if (attrs.hasAttribute(SUMO_ATTR_ARRIVALSPEED)) {
00316         ret->setParameter |= VEHPARS_ARRIVALSPEED_SET;
00317         std::string helper = attrs.getStringReporting(SUMO_ATTR_ARRIVALSPEED, "vehicle", 0, ok);
00318         if (helper=="current") {
00319             ret->arrivalSpeedProcedure = ARRIVAL_SPEED_CURRENT;
00320         } else {
00321             try {
00322                 ret->arrivalSpeed = TplConvert<char>::_2SUMOReal(helper.c_str());
00323                 ret->arrivalSpeedProcedure = ARRIVAL_SPEED_GIVEN;
00324             } catch (NumberFormatException &) {
00325                 throw ProcessError("Invalid arrivalspeed definition for " + element + " '" + ret->id + "'");
00326             } catch (EmptyData &) {
00327                 throw ProcessError("Invalid arrivalspeed definition for " + element + " '" + ret->id + "'");
00328             }
00329         }
00330     }
00331 
00332     // parse color
00333     if (attrs.hasAttribute(SUMO_ATTR_COLOR)) {
00334         ret->setParameter |= VEHPARS_COLOR_SET;
00335         try {
00336             ret->color = RGBColor::parseColor(attrs.getStringReporting(SUMO_ATTR_COLOR, "vehicle", 0, ok));
00337         } catch (NumberFormatException &) {
00338             throw ProcessError("Invalid color definition for " + element + " '" + ret->id + "'");
00339         } catch (EmptyData &) {
00340             throw ProcessError("Invalid color definition for " + element + " '" + ret->id + "'");
00341         }
00342     } else {
00343         ret->color = RGBColor::DEFAULT_COLOR;
00344     }
00345 }

SUMOEmissionClass SUMOVehicleParserHelper::parseEmissionClass ( const SUMOSAXAttributes attrs,
const std::string &  type,
const std::string &  id 
) throw () [static]

Parses the vehicle emission class.

When given, the vehicle emission class is parsed using getVehicleEmissionTypeID. Exceptions occuring within this process are catched and reported.

If no vehicle class is available in the attributes, the default class (SVE_UNKNOWN) is returned.

Parameters:
[in] attrs The attributes to read the class from
[in] type The data type (element) that is processed, for error message generation
[in] id The id of the parsed element, for error message generation
Returns:
The parsed vehicle emission class
See also:
SUMOEmissionClass
Todo:
Recheck how errors are handled and what happens if they occure

Definition at line 533 of file SUMOVehicleParserHelper.cpp.

References MsgHandler::getErrorInstance(), getVehicleEmissionTypeID(), MsgHandler::inform(), SUMO_ATTR_EMISSIONCLASS, and SVE_UNKNOWN.

00535                                      {
00536     SUMOEmissionClass vclass = SVE_UNKNOWN;
00537     try {
00538         bool ok = true;
00539         std::string vclassS = attrs.getOptStringReporting(SUMO_ATTR_EMISSIONCLASS, type.c_str(), id.c_str(), ok, "");
00540         if (vclassS=="") {
00541             return vclass;
00542         }
00543         return getVehicleEmissionTypeID(vclassS);
00544     } catch (...) {
00545         MsgHandler::getErrorInstance()->inform("The emission class for " + type + " '" + id + "' is not known.");
00546     }
00547     return vclass;
00548 }

SUMOVehicleParameter * SUMOVehicleParserHelper::parseFlowAttributes ( const SUMOSAXAttributes attrs  )  throw (ProcessError) [static]

Parses a flow's attributes.

Parses all attributes stored in "SUMOVehicleParameter".

See also:
SUMOVehicleParameter
Parameters:
[in] attr The SAX-attributes to get vehicle parameter from
Returns:
The parsed attribute structure if no error occured, 0 otherwise
Exceptions:
ProcessError If an attribute's value is invalid

Definition at line 45 of file SUMOVehicleParserHelper.cpp.

References SUMOVehicleParameter::depart, OptionsCont::getOptions(), SUMOVehicleParameter::id, SUMOVehicleParameter::repetitionNumber, SUMOVehicleParameter::repetitionOffset, SUMOVehicleParameter::setParameter, string2time(), SUMO_ATTR_BEGIN, SUMO_ATTR_END, SUMO_ATTR_NO, SUMO_ATTR_PERIOD, SUMO_ATTR_VEHSPERHOUR, SUMOReal, SUMOTime_MAX, and VEHPARS_PERIODFREQ_SET.

Referenced by MSRouteHandler::myStartElement().

00045                                                                                                {
00046     std::string id;
00047     if (!attrs.setIDFromAttributes("flow", id)) {
00048         throw ProcessError();
00049     }
00050     if (attrs.hasAttribute(SUMO_ATTR_PERIOD) && attrs.hasAttribute(SUMO_ATTR_VEHSPERHOUR)) {
00051         throw ProcessError("At most one of '" + attrs.getName(SUMO_ATTR_PERIOD) +
00052                            "' and '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
00053                            "' has to be given in the definition of flow '" + id + "'.");
00054     }
00055     if (attrs.hasAttribute(SUMO_ATTR_PERIOD) || attrs.hasAttribute(SUMO_ATTR_VEHSPERHOUR)) {
00056         if (attrs.hasAttribute(SUMO_ATTR_END) && attrs.hasAttribute(SUMO_ATTR_NO)) {
00057             throw ProcessError("If '" + attrs.getName(SUMO_ATTR_PERIOD) +
00058                                "' or '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
00059                                "' are given at most one of '" + attrs.getName(SUMO_ATTR_END) +
00060                                "' and '" + attrs.getName(SUMO_ATTR_NO) +
00061                                "' are allowed in flow '" + id + "'.");
00062         }
00063     } else {
00064         if (!attrs.hasAttribute(SUMO_ATTR_NO)) {
00065             throw ProcessError("At least one of '" + attrs.getName(SUMO_ATTR_PERIOD) +
00066                                "', '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
00067                                "', and '" + attrs.getName(SUMO_ATTR_NO) +
00068                                "' is needed in flow '" + id + "'.");
00069         }
00070     }
00071     bool ok = true;
00072     SUMOVehicleParameter *ret = new SUMOVehicleParameter();
00073     ret->id = id;
00074     parseCommonAttributes(attrs, ret, "flow");
00075 
00076     // parse repetition information
00077     if (attrs.hasAttribute(SUMO_ATTR_PERIOD)) {
00078         ret->setParameter |= VEHPARS_PERIODFREQ_SET;
00079         ret->repetitionOffset = attrs.getSUMOTimeReporting(SUMO_ATTR_PERIOD, "flow", id.c_str(), ok);
00080     }
00081     if (attrs.hasAttribute(SUMO_ATTR_VEHSPERHOUR)) {
00082         ret->setParameter |= VEHPARS_PERIODFREQ_SET;
00083         const SUMOReal vph = attrs.getSUMORealReporting(SUMO_ATTR_VEHSPERHOUR, "flow", id.c_str(), ok);
00084         if (ok && vph <= 0) {
00085             delete ret;
00086             throw ProcessError("Invalid repetition rate in the definition of flow '" + id + "'.");
00087         }
00088         if (ok && vph != 0) {
00089             ret->repetitionOffset = 3600./vph*1000.;
00090         }
00091     }
00092 
00093     ret->depart = string2time(OptionsCont::getOptions().getString("begin"));
00094     if (attrs.hasAttribute(SUMO_ATTR_BEGIN)) {
00095         ret->depart = attrs.getSUMOTimeReporting(SUMO_ATTR_BEGIN, "flow", id.c_str(), ok);
00096     }
00097     if (ok && ret->depart < 0) {
00098         delete ret;
00099         throw ProcessError("Negative begin time in the definition of flow '" + id + "'.");
00100     }
00101     SUMOTime end = string2time(OptionsCont::getOptions().getString("end"));
00102     if (end<0) {
00103         end=SUMOTime_MAX;
00104     }
00105     if (attrs.hasAttribute(SUMO_ATTR_END)) {
00106         end = attrs.getSUMOTimeReporting(SUMO_ATTR_END, "flow", id.c_str(), ok);
00107     }
00108     if (ok && end <= ret->depart) {
00109         delete ret;
00110         throw ProcessError("Flow '" + id + "' ends before or at its begin time.");
00111     }
00112     if (attrs.hasAttribute(SUMO_ATTR_NO)) {
00113         ret->repetitionNumber = attrs.getIntReporting(SUMO_ATTR_NO, "flow", id.c_str(), ok);
00114         ret->setParameter |= VEHPARS_PERIODFREQ_SET;
00115         if (ok && ret->repetitionNumber < 0) {
00116             delete ret;
00117             throw ProcessError("Negative repetition number in the definition of flow '" + id + "'.");
00118         }
00119         if (ok && ret->repetitionOffset < 0) {
00120             ret->repetitionOffset = (end - ret->depart) / (SUMOReal)ret->repetitionNumber;
00121         }
00122     } else {
00123         if (ok && ret->repetitionOffset <= 0) {
00124             delete ret;
00125             throw ProcessError("Invalid repetition rate in the definition of flow '" + id + "'.");
00126         }
00127         if (end == SUMOTime_MAX) {
00128             ret->repetitionNumber = INT_MAX;
00129         } else {
00130             ret->repetitionNumber = (int)((end - ret->depart) / ret->repetitionOffset + 0.5);
00131         }
00132     }
00133     if (!ok) {
00134         delete ret;
00135         throw ProcessError();
00136     }
00137     return ret;
00138 }

SUMOVehicleShape SUMOVehicleParserHelper::parseGuiShape ( const SUMOSAXAttributes attrs,
const std::string &  type,
const std::string &  id 
) throw () [static]

Parses the vehicle class.

When given, the vehicle class is parsed using getVehicleShapeID. Exceptions occuring within this process are catched and reported.

If no vehicle class is available in the attributes, the default class (SVS_UNKNOWN) is returned.

Parameters:
[in] attrs The attributes to read the class from
[in] type The data type (element) that is processed, for error message generation
[in] id The id of the parsed element, for error message generation
Returns:
The parsed vehicle shape
See also:
SUMOVehicleShape
Todo:
Recheck how errors are handled and what happens if they occure

Definition at line 552 of file SUMOVehicleParserHelper.cpp.

References MsgHandler::getErrorInstance(), getVehicleShapeID(), MsgHandler::inform(), SUMO_ATTR_GUISHAPE, and SVS_UNKNOWN.

00554                                                                     {
00555     SUMOVehicleShape vclass = SVS_UNKNOWN;
00556     try {
00557         bool ok = true;
00558         std::string vclassS = attrs.getOptStringReporting(SUMO_ATTR_GUISHAPE, type.c_str(), id.c_str(), ok, "");
00559         if (vclassS=="") {
00560             return vclass;
00561         }
00562         return getVehicleShapeID(vclassS);
00563     } catch (...) {
00564         MsgHandler::getErrorInstance()->inform("The shape for " + type + " '" + id + "' is not known.");
00565     }
00566     return vclass;
00567 }

SUMOVehicleParameter * SUMOVehicleParserHelper::parseVehicleAttributes ( const SUMOSAXAttributes attrs,
bool  skipID = false,
bool  skipDepart = false 
) throw (ProcessError) [static]

Parses a vehicle's attributes.

Parses all attributes stored in "SUMOVehicleParameter".

See also:
SUMOVehicleParameter
Parameters:
[in] attr The SAX-attributes to get vehicle parameter from
[in] skipID Whether parsing the id shall be skipped
[in] skipDepart Whether parsing the departure time shall be skipped
Returns:
The parsed attribute structure if no error occured, 0 otherwise
Exceptions:
ProcessError If an attribute's value is invalid

Definition at line 142 of file SUMOVehicleParserHelper.cpp.

References SUMOVehicleParameter::depart, DEPART_GIVEN, DEPART_TRIGGERED, SUMOVehicleParameter::departProcedure, SUMOVehicleParameter::id, SUMOVehicleParameter::repetitionNumber, SUMOVehicleParameter::repetitionOffset, SUMOVehicleParameter::setParameter, SUMO_ATTR_DEPART, SUMO_ATTR_PERIOD, SUMO_ATTR_REPNUMBER, VEHPARS_PERIODFREQ_SET, VEHPARS_PERIODNUM_SET, and WRITE_WARNING.

Referenced by RORDLoader_TripDefs::myStartElement(), RORDLoader_SUMOBase::myStartElement(), MSRouteHandler::myStartElement(), and RORDGenerator_ODAmounts::parseFlowAmountDef().

00143                                                           {
00144     std::string id;
00145     if (!skipID && !attrs.setIDFromAttributes("vehicle", id)) {
00146         throw ProcessError();
00147     }
00148     if (attrs.hasAttribute(SUMO_ATTR_PERIOD) ^ attrs.hasAttribute(SUMO_ATTR_REPNUMBER)) {
00149         throw ProcessError("The attributes '" + attrs.getName(SUMO_ATTR_PERIOD) + "' and '" + attrs.getName(SUMO_ATTR_REPNUMBER) + "' have to be given both in the definition of '" + id + "'.");
00150     }
00151     bool ok = true;
00152     SUMOVehicleParameter *ret = new SUMOVehicleParameter();
00153     ret->id = id;
00154     parseCommonAttributes(attrs, ret, "vehicle");
00155     if (!skipDepart) {
00156         const std::string helper = attrs.getStringReporting(SUMO_ATTR_DEPART, "vehicle", 0, ok);
00157         if (helper=="triggered") {
00158             ret->departProcedure = DEPART_TRIGGERED;
00159         } else {
00160             ret->departProcedure = DEPART_GIVEN;
00161             ret->depart = attrs.getSUMOTimeReporting(SUMO_ATTR_DEPART, "vehicle", id.c_str(), ok);
00162             if (ok && ret->depart < 0) {
00163                 throw ProcessError("Negative departure time in the definition of '" + id + "'.");
00164             }
00165         }
00166     }
00167     // parse repetition information
00168     if (attrs.hasAttribute(SUMO_ATTR_PERIOD)) {
00169         WRITE_WARNING("period and repno are deprecated in vehicle '" + id + "', use flows instead.");
00170         ret->setParameter |= VEHPARS_PERIODFREQ_SET;
00171         ret->repetitionOffset = attrs.getSUMORealReporting(SUMO_ATTR_PERIOD, "vehicle", id.c_str(), ok);
00172     }
00173     if (attrs.hasAttribute(SUMO_ATTR_REPNUMBER)) {
00174         ret->setParameter |= VEHPARS_PERIODNUM_SET;
00175         ret->repetitionNumber = attrs.getIntReporting(SUMO_ATTR_REPNUMBER, "vehicle", id.c_str(), ok);
00176     }
00177 
00178     if (!ok) {
00179         delete ret;
00180         throw ProcessError();
00181     }
00182     return ret;
00183 }

SUMOVehicleClass SUMOVehicleParserHelper::parseVehicleClass ( const SUMOSAXAttributes attrs,
const std::string &  type,
const std::string &  id 
) throw () [static]

Parses the vehicle class.

When given, the vehicle class is parsed using getVehicleClassID. Exceptions occuring within this process are catched and reported.

If no vehicle class is available in the attributes, the default class (SVC_UNKNOWN) is returned.

Parameters:
[in] attrs The attributes to read the class from
[in] type The data type (element) that is processed, for error message generation
[in] id The id of the parsed element, for error message generation
Returns:
The parsed vehicle class
See also:
SUMOVehicleClass
Todo:
Recheck how errors are handled and what happens if they occure

Definition at line 514 of file SUMOVehicleParserHelper.cpp.

References MsgHandler::getErrorInstance(), getVehicleClassID(), MsgHandler::inform(), SUMO_ATTR_VCLASS, and SVC_UNKNOWN.

00516                                      {
00517     SUMOVehicleClass vclass = SVC_UNKNOWN;
00518     try {
00519         bool ok = true;
00520         std::string vclassS = attrs.getOptStringReporting(SUMO_ATTR_VCLASS, type.c_str(), id.c_str(), ok, "");
00521         if (vclassS=="") {
00522             return vclass;
00523         }
00524         return getVehicleClassID(vclassS);
00525     } catch (...) {
00526         MsgHandler::getErrorInstance()->inform("The class for " + type + " '" + id + "' is not known.");
00527     }
00528     return vclass;
00529 }

void SUMOVehicleParserHelper::parseVTypeEmbedded ( SUMOVTypeParameter into,
int  element,
const SUMOSAXAttributes attrs,
bool  fromVType = false 
) throw (ProcessError) [static]

Parses an element embedded in vtype definition.

Parameters:
in,filled] into The structure to fill with parsed values
[in] element The id of the currently parsed XML-element
[in] attr The SAX-attributes to get vehicle parameter from
[in] fromVType Whether the attributes are a part of the vtype-definition
Exceptions:
ProcessError If an attribute's value is invalid
See also:
SUMOVTypeParameter

Definition at line 414 of file SUMOVehicleParserHelper.cpp.

References SUMO_TAG_CF_BKERNER, SUMO_TAG_CF_IDM, SUMO_TAG_CF_KRAUSS, SUMO_TAG_CF_KRAUSS_ORIG1, and SUMO_TAG_CF_PWAGNER2009.

Referenced by RORDLoader_TripDefs::myStartElement(), RORDLoader_SUMOBase::myStartElement(), and MSRouteHandler::myStartElement().

00416                                             {
00417     switch (element) {
00418     case SUMO_TAG_CF_KRAUSS:
00419         parseVTypeEmbedded_Krauss(into, attrs, fromVType);
00420         break;
00421     case SUMO_TAG_CF_IDM:
00422         parseVTypeEmbedded_IDM(into, attrs);
00423         break;
00424     case SUMO_TAG_CF_KRAUSS_ORIG1:
00425         parseVTypeEmbedded_Krauss(into, attrs);
00426         break;
00427     case SUMO_TAG_CF_PWAGNER2009:
00428         parseVTypeEmbedded_Krauss(into, attrs);
00429         break;
00430     case SUMO_TAG_CF_BKERNER:
00431         parseVTypeEmbedded_BKerner(into, attrs);
00432         break;
00433     }
00434     if (!fromVType) {
00435         into.cfModel = element;
00436     }
00437 }

void SUMOVehicleParserHelper::parseVTypeEmbedded_BKerner ( SUMOVTypeParameter into,
const SUMOSAXAttributes attrs 
) throw (ProcessError) [static]

Parses the Kerner definition embedded in vtype definition.

Parameters:
in,filled] into The structure to fill with parsed values
[in] attr The SAX-attributes to get model parameter from
Exceptions:
ProcessError If an attribute's value is invalid
See also:
SUMOVTypeParameter

Definition at line 489 of file SUMOVehicleParserHelper.cpp.

References SUMO_ATTR_ACCEL, SUMO_ATTR_CF_KERNER_PHI, SUMO_ATTR_DECEL, SUMO_ATTR_K, and SUMO_ATTR_TAU.

00490                                                             {
00491     bool ok = true;
00492     if (attrs.hasAttribute(SUMO_ATTR_ACCEL)) {
00493         into.cfParameter["accel"] = attrs.getSUMORealReporting(SUMO_ATTR_ACCEL, "BKerner", into.id.c_str(), ok);
00494     }
00495     if (attrs.hasAttribute(SUMO_ATTR_DECEL)) {
00496         into.cfParameter["decel"] = attrs.getSUMORealReporting(SUMO_ATTR_DECEL, "BKerner", into.id.c_str(), ok);
00497     }
00498     if (attrs.hasAttribute(SUMO_ATTR_TAU)) {
00499         into.cfParameter["tau"] = attrs.getSUMORealReporting(SUMO_ATTR_TAU, "BKerner", into.id.c_str(), ok);
00500     }
00501     if (attrs.hasAttribute(SUMO_ATTR_K)) {
00502         into.cfParameter["k"] = attrs.getSUMORealReporting(SUMO_ATTR_K, "BKerner", into.id.c_str(), ok);
00503     }
00504     if (attrs.hasAttribute(SUMO_ATTR_CF_KERNER_PHI)) {
00505         into.cfParameter["phi"] = attrs.getSUMORealReporting(SUMO_ATTR_CF_KERNER_PHI, "BKerner", into.id.c_str(), ok);
00506     }
00507     if (!ok) {
00508         throw ProcessError();
00509     }
00510 }

void SUMOVehicleParserHelper::parseVTypeEmbedded_IDM ( SUMOVTypeParameter into,
const SUMOSAXAttributes attrs 
) throw (ProcessError) [static]

Parses the IDM definition embedded in vtype definition.

Parameters:
in,filled] into The structure to fill with parsed values
[in] attr The SAX-attributes to get model parameter from
Exceptions:
ProcessError If an attribute's value is invalid
See also:
SUMOVTypeParameter

Definition at line 464 of file SUMOVehicleParserHelper.cpp.

References SUMO_ATTR_ACCEL, SUMO_ATTR_CF_IDM_MINGAP, SUMO_ATTR_CF_IDM_TIMEHEADWAY, SUMO_ATTR_DECEL, and SUMO_ATTR_TAU.

00465                                                             {
00466     bool ok = true;
00467     if (attrs.hasAttribute(SUMO_ATTR_ACCEL)) {
00468         into.cfParameter["accel"] = attrs.getSUMORealReporting(SUMO_ATTR_ACCEL, "IDM", into.id.c_str(), ok);
00469     }
00470     if (attrs.hasAttribute(SUMO_ATTR_DECEL)) {
00471         into.cfParameter["decel"] = attrs.getSUMORealReporting(SUMO_ATTR_DECEL, "IDM", into.id.c_str(), ok);
00472     }
00473     if (attrs.hasAttribute(SUMO_ATTR_TAU)) {
00474         into.cfParameter["tau"] = attrs.getSUMORealReporting(SUMO_ATTR_TAU, "IDM", into.id.c_str(), ok);
00475     }
00476     if (attrs.hasAttribute(SUMO_ATTR_CF_IDM_TIMEHEADWAY)) {
00477         into.cfParameter["timeHeadWay"] = attrs.getSUMORealReporting(SUMO_ATTR_CF_IDM_TIMEHEADWAY, "IDM", into.id.c_str(), ok);
00478     }
00479     if (attrs.hasAttribute(SUMO_ATTR_CF_IDM_MINGAP)) {
00480         into.cfParameter["minGap"] = attrs.getSUMORealReporting(SUMO_ATTR_CF_IDM_MINGAP, "IDM", into.id.c_str(), ok);
00481     }
00482     if (!ok) {
00483         throw ProcessError();
00484     }
00485 }

void SUMOVehicleParserHelper::parseVTypeEmbedded_Krauss ( SUMOVTypeParameter into,
const SUMOSAXAttributes attrs,
bool  fromVType = false 
) throw (ProcessError) [static]

Parses the Krauss definition embedded in vtype definition.

Parameters:
in,filled] into The structure to fill with parsed values
[in] attr The SAX-attributes to get model parameter from
[in] fromVType Whether the attributes are a part of the vtype-definition
Exceptions:
ProcessError If an attribute's value is invalid
See also:
SUMOVTypeParameter

Definition at line 441 of file SUMOVehicleParserHelper.cpp.

References SUMO_ATTR_ACCEL, SUMO_ATTR_DECEL, SUMO_ATTR_SIGMA, and SUMO_ATTR_TAU.

00443                                             {
00444     bool ok = true;
00445     if (attrs.hasAttribute(SUMO_ATTR_ACCEL)) {
00446         into.cfParameter["accel"] = attrs.getSUMORealReporting(SUMO_ATTR_ACCEL, "krauss", into.id.c_str(), ok);
00447     }
00448     if (attrs.hasAttribute(SUMO_ATTR_DECEL)) {
00449         into.cfParameter["decel"] = attrs.getSUMORealReporting(SUMO_ATTR_DECEL, "krauss", into.id.c_str(), ok);
00450     }
00451     if (attrs.hasAttribute(SUMO_ATTR_SIGMA)) {
00452         into.cfParameter["sigma"] = attrs.getSUMORealReporting(SUMO_ATTR_SIGMA, "krauss", into.id.c_str(), ok);
00453     }
00454     if (attrs.hasAttribute(SUMO_ATTR_TAU)) {
00455         into.cfParameter["tau"] = attrs.getSUMORealReporting(SUMO_ATTR_TAU, "krauss", into.id.c_str(), ok);
00456     }
00457     if (!ok) {
00458         throw ProcessError();
00459     }
00460 }


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

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