本文整理汇总了C++中SUMOSAXAttributes::setIDFromAttributes方法的典型用法代码示例。如果您正苦于以下问题:C++ SUMOSAXAttributes::setIDFromAttributes方法的具体用法?C++ SUMOSAXAttributes::setIDFromAttributes怎么用?C++ SUMOSAXAttributes::setIDFromAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SUMOSAXAttributes
的用法示例。
在下文中一共展示了SUMOSAXAttributes::setIDFromAttributes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: throw
void
NIXMLTypesHandler::myStartElement(SumoXMLTag element,
const SUMOSAXAttributes &attrs) throw(ProcessError) {
if (element!=SUMO_TAG_TYPE) {
return;
}
// get the id, report a warning if not given or empty...
std::string id;
if (!attrs.setIDFromAttributes("type", id), false) {
WRITE_WARNING("No type id given... Skipping.");
return;
}
// check deprecated (unused) attributes
if (!myHaveReportedAboutFunctionDeprecation&&attrs.hasAttribute(SUMO_ATTR_FUNCTION)) {
MsgHandler::getWarningInstance()->inform("While parsing type '" + id + "': 'function' is deprecated.\n All occurences are ignored.");
myHaveReportedAboutFunctionDeprecation = true;
}
bool ok = true;
int priority = attrs.getOptIntReporting(SUMO_ATTR_PRIORITY, "type", id.c_str(), ok, myTypeCont.getDefaultPriority());
int noLanes = attrs.getOptIntReporting(SUMO_ATTR_NOLANES, "type", id.c_str(), ok, myTypeCont.getDefaultNoLanes());
SUMOReal speed = attrs.getOptSUMORealReporting(SUMO_ATTR_SPEED, "type", id.c_str(), ok, (SUMOReal) myTypeCont.getDefaultSpeed());
bool discard = attrs.getOptBoolReporting(SUMO_ATTR_DISCARD, 0, 0, ok, false);
if (!ok) {
return;
}
// build the type
if (!myTypeCont.insert(id, noLanes, speed, priority)) {
MsgHandler::getErrorInstance()->inform("Duplicate type occured. ID='" + id + "'");
} else {
if (discard) {
myTypeCont.markAsToDiscard(id);
}
}
}
示例2: pos
void
NIImporter_SUMO::addJunction(const SUMOSAXAttributes &attrs) {
// get the id, report an error if not given or empty...
std::string id;
if (!attrs.setIDFromAttributes("junction", id)) {
return;
}
if (id[0]==':') {
return;
}
bool ok = true;
SUMOReal x = attrs.getOptSUMORealReporting(SUMO_ATTR_X, "junction", id.c_str(), ok, -1);
SUMOReal y = attrs.getOptSUMORealReporting(SUMO_ATTR_Y, "junction", id.c_str(), ok, -1);
// !!! this is too simplified! A proper error check should be done
if (x==-1||y==-1) {
MsgHandler::getErrorInstance()->inform("Junction '" + id + "' has an invalid position.");
return;
}
Position2D pos(x, y);
if (!GeoConvHelper::x2cartesian(pos)) {
MsgHandler::getErrorInstance()->inform("Unable to project coordinates for junction " + id + ".");
return;
}
NBNode *node = new NBNode(id, pos);
if (!myNodeCont.insert(node)) {
MsgHandler::getErrorInstance()->inform("Problems on adding junction '" + id + "'.");
delete node;
return;
}
}
示例3: st
void
MSRouteHandler::openRouteDistribution(const SUMOSAXAttributes &attrs) {
if (attrs.setIDFromAttributes("routeDistribution", myCurrentRouteDistributionID)) {
myCurrentRouteDistribution = new RandomDistributor<const MSRoute*>();
if (attrs.hasAttribute(SUMO_ATTR_ROUTES)) {
bool ok = true;
StringTokenizer st(attrs.getStringReporting(SUMO_ATTR_ROUTES, "routeDistribution", myCurrentRouteDistributionID.c_str(), ok));
while (st.hasNext()) {
std::string routeID = st.next();
const MSRoute *route = MSRoute::dictionary(routeID);
if (route==0) {
throw ProcessError("Unknown route '" + routeID + "' in distribution '" + myCurrentRouteDistributionID + "'.");
}
myCurrentRouteDistribution->add(1., route, false);
}
}
}
}
示例4:
void
NIImporter_SUMO::addEdge(const SUMOSAXAttributes &attrs) {
// get the id, report an error if not given or empty...
std::string id;
if (!attrs.setIDFromAttributes("edge", id)) {
return;
}
bool ok = true;
myCurrentEdge = new EdgeAttrs;
myCurrentEdge->id = id;
// get the type
myCurrentEdge->type = attrs.getOptStringReporting(SUMO_ATTR_TYPE, "edge", id.c_str(), ok, "");
// get the origin and the destination node
myCurrentEdge->fromNode = attrs.getOptStringReporting(SUMO_ATTR_FROM, "edge", id.c_str(), ok, "");
myCurrentEdge->toNode = attrs.getOptStringReporting(SUMO_ATTR_TO, "edge", id.c_str(), ok, "");
myCurrentEdge->priority = attrs.getOptIntReporting(SUMO_ATTR_PRIORITY, "edge", id.c_str(), ok, -1);
myCurrentEdge->maxSpeed = 0;
myCurrentEdge->builtEdge = 0;
}
示例5: throw
void
NIXMLEdgesHandler::myStartElement(SumoXMLTag element,
const SUMOSAXAttributes &attrs) throw(ProcessError) {
if (element==SUMO_TAG_EDGE) {
myIsUpdate = false;
bool ok = true;
// initialise the edge
myCurrentEdge = 0;
mySplits.clear();
// get the id, report an error if not given or empty...
if (!attrs.setIDFromAttributes("edge", myCurrentID)) {
return;
}
myCurrentEdge = myEdgeCont.retrieve(myCurrentID);
// check deprecated (unused) attributes
if (!myHaveReportedAboutFunctionDeprecation&&attrs.hasAttribute(SUMO_ATTR_FUNCTION)) {
MsgHandler::getWarningInstance()->inform("While parsing edge '" + myCurrentID + "': 'function' is deprecated.\n All occurences are ignored.");
myHaveReportedAboutFunctionDeprecation = true;
}
// use default values, first
myCurrentSpeed = myTypeCont.getDefaultSpeed();
myCurrentPriority = myTypeCont.getDefaultPriority();
myCurrentLaneNo = myTypeCont.getDefaultNoLanes();
// use values from the edge to overwrite if existing, then
if (myCurrentEdge!=0) {
myIsUpdate = true;
if (!myHaveReportedAboutOverwriting) {
MsgHandler::getMessageInstance()->inform("Duplicate edge id occured ('" + myCurrentID + "'); assuming overwriting is wished.");
myHaveReportedAboutOverwriting = true;
}
myCurrentSpeed = myCurrentEdge->getSpeed();
myCurrentPriority = myCurrentEdge->getPriority();
myCurrentLaneNo = myCurrentEdge->getNoLanes();
myCurrentType = myCurrentEdge->getTypeID();
}
// check whether a type's values shall be used
myCurrentType = "";
if (attrs.hasAttribute(SUMO_ATTR_TYPE)) {
myCurrentType = attrs.getStringReporting(SUMO_ATTR_TYPE, "edge", myCurrentID.c_str(), ok);
if (!ok) {
return;
}
if (!myTypeCont.knows(myCurrentType)) {
MsgHandler::getErrorInstance()->inform("Type '" + myCurrentType + "' used by edge '" + myCurrentID + "' was not defined.");
return;
}
myCurrentSpeed = myTypeCont.getSpeed(myCurrentType);
myCurrentPriority = myTypeCont.getPriority(myCurrentType);
myCurrentLaneNo = myTypeCont.getNoLanes(myCurrentType);
}
// speed, priority and the number of lanes have now default values;
// try to read the real values from the file
if (attrs.hasAttribute(SUMO_ATTR_SPEED)) {
myCurrentSpeed = attrs.getSUMORealReporting(SUMO_ATTR_SPEED, "edge", myCurrentID.c_str(), ok);
}
if (myOptions.getBool("speed-in-kmh")) {
myCurrentSpeed = myCurrentSpeed / (SUMOReal) 3.6;
}
// try to get the number of lanes
if (attrs.hasAttribute(SUMO_ATTR_NOLANES)) {
myCurrentLaneNo = attrs.getIntReporting(SUMO_ATTR_NOLANES, "edge", myCurrentID.c_str(), ok);
}
// try to get the priority
if (attrs.hasAttribute(SUMO_ATTR_PRIORITY)) {
myCurrentPriority = attrs.getIntReporting(SUMO_ATTR_PRIORITY, "edge", myCurrentID.c_str(), ok);
}
// try to get the shape
myShape = tryGetShape(attrs);
// and how to spread the lanes
if (attrs.getOptStringReporting(SUMO_ATTR_SPREADFUNC, "edge", myCurrentID.c_str(), ok, "")=="center") {
myLanesSpread = NBEdge::LANESPREAD_CENTER;
} else {
myLanesSpread = NBEdge::LANESPREAD_RIGHT;
}
// try to set the nodes
if (!setNodes(attrs)) {
// return if this failed
return;
}
// get the length or compute it
if (attrs.hasAttribute(SUMO_ATTR_LENGTH)) {
myLength = attrs.getSUMORealReporting(SUMO_ATTR_LENGTH, "edge", myCurrentID.c_str(), ok);
} else {
myLength = 0;
}
/// insert the parsed edge into the edges map
if (!ok) {
return;
}
// check whether a previously defined edge shall be overwritten
if (myCurrentEdge!=0) {
myCurrentEdge->reinit(myFromNode, myToNode, myCurrentType, myCurrentSpeed,
myCurrentLaneNo, myCurrentPriority, myShape,
myLanesSpread);
} else {
// the edge must be allocated in dependence to whether a shape is given
if (myShape.size()==0) {
myCurrentEdge = new NBEdge(myCurrentID, myFromNode, myToNode, myCurrentType, myCurrentSpeed,
myCurrentLaneNo, myCurrentPriority, myLanesSpread);
//.........这里部分代码省略.........
示例6: ProcessError
void
MSCalibrator::MSCalibrator_FileTriggeredChild::myStartElement(SumoXMLTag element,
const SUMOSAXAttributes &attrs) throw(ProcessError) {
if (element==SUMO_TAG_ROUTEDISTELEM) {
bool ok = true;
SUMOReal freq = attrs.getSUMORealReporting(SUMO_ATTR_PROB, "calibrator/routedistelem", myParent.getID().c_str(), ok);
std::string routeStr = attrs.getStringReporting(SUMO_ATTR_ID, "calibrator/routedistelem", myParent.getID().c_str(), ok);
if (ok) {
const MSRoute* route = MSRoute::dictionary(routeStr);
if (route == 0) {
throw ProcessError("MSTriggeredSource " + myParent.getID() + ": Route '" + routeStr + "' does not exist.");
}
if (freq<0) {
throw ProcessError("MSTriggeredSource " + myParent.getID() + ": Attribute \"probability\" is negative (must not).");
}
// Attributes ok, add to routeDist
myRouteDist.add(freq, route);
}
return;
}
// vehicle-type distributions
if (element==SUMO_TAG_VTYPEDISTELEM) {
// get the id, report an error if not given or empty...
std::string id;
if (!attrs.setIDFromAttributes("vtypedistelem", id)) {
return;
}
bool ok = true;
SUMOReal prob = attrs.getSUMORealReporting(SUMO_ATTR_PROB, "vtypedistelem", id.c_str(), ok);
if (ok) {
if (prob<=0) {
MsgHandler::getErrorInstance()->inform("False probability while parsing calibrator '" + myParent.getID() + "' (" + toString(prob) + ").");
return;
}
MSVehicleType *vtype = MSNet::getInstance()->getVehicleControl().getVType(id);
if (vtype==0) {
MsgHandler::getErrorInstance()->inform("Unknown vtype-object '" + id + "'.");
return;
}
myVTypeDist.add(prob, vtype);
}
}
if (element==SUMO_TAG_FLOW) {
bool ok = true;
SUMOReal no = attrs.getSUMORealReporting(SUMO_ATTR_NO, "flow", myParent.getID().c_str(), ok);
if (no<0) {
MsgHandler::getErrorInstance()->inform("Negative flow in calibrator '" + myParent.getID() + "'.");
return;
}
SUMOTime end = attrs.getOptSUMOTimeReporting(SUMO_ATTR_END, "flow", myParent.getID().c_str(), ok, -1);
if (!ok) {
return;
}
myFlow = (SUMOReal) no;
if (end==-1||end>=MSNet::getInstance()->getCurrentTimeStep()) {
if (myFlow>0) {
buildAndScheduleFlowVehicle();
MSNet::getInstance()->getEmissionEvents().addEvent(
new WrappingCommand<MSCalibrator::MSCalibrator_FileTriggeredChild>(this, &MSCalibrator::MSCalibrator_FileTriggeredChild::execute),
(SUMOTime)(1. / (myFlow / 3600.))+MSNet::getInstance()->getCurrentTimeStep(),
MSEventControl::ADAPT_AFTER_EXECUTION);
myHaveInitialisedFlow = true;
}
}
}
// check whethe the correct tag is read
if (element==SUMO_TAG_EMIT) {
bool ok = true;
SUMOTime depart = attrs.getSUMOTimeReporting(SUMO_ATTR_TIME, "emit", 0, ok);
SUMOReal departSpeed = attrs.getOptSUMORealReporting(SUMO_ATTR_SPEED, "emit", myParent.getID().c_str(), ok, -1);
if (!ok) {
return;
}
if (depart<myBeginTime) {
// do not process the vehicle if the emission time is before the simulation begin
return;
}
SUMOVehicleParameter* pars = new SUMOVehicleParameter();
pars->repetitionNumber = -1;
pars->repetitionOffset = -1;
pars->depart = depart;
pars->departSpeed = departSpeed;
// check and assign id
pars->id = attrs.getStringSecure(SUMO_ATTR_ID, "");
if (myVehicleControl.getVehicle(pars->id)!=0) {
WRITE_WARNING("MSTriggeredSource " + myParent.getID()+ ": Vehicle " + pars->id + " already exists.\n Generating a default id.");
pars->id = "";
}
if (pars->id=="") {
pars->id = myParent.getID() + "_" + toString(pars->depart) + "_" + toString(myRunningID++);
if (myVehicleControl.getVehicle(pars->id)!=0) {
WRITE_WARNING("MSTriggeredSource " + myParent.getID()+ ": Vehicle " + pars->id + " already exists.\n Continuing with next element.");
return;
}
}
// check and assign vehicle type
pars->vtypeid = attrs.getStringReporting(SUMO_ATTR_TYPE, "calibrator/routedistelem", myParent.getID().c_str(), ok, "");
//.........这里部分代码省略.........