本文整理汇总了C++中TraCIServer::readTypeCheckingDouble方法的典型用法代码示例。如果您正苦于以下问题:C++ TraCIServer::readTypeCheckingDouble方法的具体用法?C++ TraCIServer::readTypeCheckingDouble怎么用?C++ TraCIServer::readTypeCheckingDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TraCIServer
的用法示例。
在下文中一共展示了TraCIServer::readTypeCheckingDouble方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
bool
TraCIServerAPI_Lane::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != VAR_MAXSPEED && variable != VAR_LENGTH && variable != LANE_ALLOWED && variable != LANE_DISALLOWED) {
return server.writeErrorStatusCmd(CMD_SET_LANE_VARIABLE, "Change Lane State: unsupported variable specified", outputStorage);
}
// id
std::string id = inputStorage.readString();
MSLane* l = MSLane::dictionary(id);
if (l == 0) {
return server.writeErrorStatusCmd(CMD_SET_LANE_VARIABLE, "Lane '" + id + "' is not known", outputStorage);
}
// process
switch (variable) {
case VAR_MAXSPEED: {
double value = 0;
if (!server.readTypeCheckingDouble(inputStorage, value)) {
return server.writeErrorStatusCmd(CMD_SET_LANE_VARIABLE, "The speed must be given as a double.", outputStorage);
}
l->setMaxSpeed(value);
}
break;
case VAR_LENGTH: {
double value = 0;
if (!server.readTypeCheckingDouble(inputStorage, value)) {
return server.writeErrorStatusCmd(CMD_SET_LANE_VARIABLE, "The length must be given as a double.", outputStorage);
}
l->setLength(value);
}
break;
case LANE_ALLOWED: {
std::vector<std::string> classes;
if (!server.readTypeCheckingStringList(inputStorage, classes)) {
return server.writeErrorStatusCmd(CMD_SET_LANE_VARIABLE, "Allowed classes must be given as a list of strings.", outputStorage);
}
l->setPermissions(parseVehicleClasses(classes));
l->getEdge().rebuildAllowedLanes();
}
break;
case LANE_DISALLOWED: {
std::vector<std::string> classes;
if (!server.readTypeCheckingStringList(inputStorage, classes)) {
return server.writeErrorStatusCmd(CMD_SET_LANE_VARIABLE, "Not allowed classes must be given as a list of strings.", outputStorage);
}
l->setPermissions(~parseVehicleClasses(classes)); // negation yields allowed
l->getEdge().rebuildAllowedLanes();
}
break;
default:
break;
}
server.writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_OK, warning, outputStorage);
return true;
}
示例2: toHex
bool
TraCIServerAPI_POI::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable & id
int variable = inputStorage.readUnsignedByte();
std::string id = inputStorage.readString();
// check variable
if (variable != libsumo::VAR_TYPE &&
variable != libsumo::VAR_COLOR &&
variable != libsumo::VAR_POSITION &&
variable != libsumo::VAR_WIDTH &&
variable != libsumo::VAR_HEIGHT &&
variable != libsumo::VAR_ANGLE &&
variable != libsumo::VAR_IMAGEFILE &&
variable != libsumo::VAR_HIGHLIGHT &&
variable != libsumo::ADD &&
variable != libsumo::REMOVE &&
variable != libsumo::VAR_PARAMETER) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "Change PoI State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
}
// process
try {
switch (variable) {
case libsumo::VAR_TYPE: {
std::string type;
if (!server.readTypeCheckingString(inputStorage, type)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The type must be given as a string.", outputStorage);
}
libsumo::POI::setType(id, type);
}
break;
case libsumo::VAR_COLOR: {
libsumo::TraCIColor col;
if (!server.readTypeCheckingColor(inputStorage, col)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The color must be given using an according type.", outputStorage);
}
libsumo::POI::setColor(id, col);
}
break;
case libsumo::VAR_POSITION: {
libsumo::TraCIPosition pos;
if (!server.readTypeCheckingPosition2D(inputStorage, pos)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The position must be given using an according type.", outputStorage);
}
libsumo::POI::setPosition(id, pos.x, pos.y);
}
break;
case libsumo::VAR_WIDTH: {
double width;
if (!server.readTypeCheckingDouble(inputStorage, width)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The width must be given using an according type.", outputStorage);
}
libsumo::POI::setWidth(id, width);
}
break;
case libsumo::VAR_HEIGHT: {
double height;
if (!server.readTypeCheckingDouble(inputStorage, height)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The height must be given using an according type.", outputStorage);
}
libsumo::POI::setHeight(id, height);
}
break;
case libsumo::VAR_ANGLE: {
double angle;
if (!server.readTypeCheckingDouble(inputStorage, angle)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The angle must be given using an according type.", outputStorage);
}
libsumo::POI::setAngle(id, angle);
}
break;
case libsumo::VAR_IMAGEFILE: {
std::string imageFile;
if (!server.readTypeCheckingString(inputStorage, imageFile)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The type must be given as a string.", outputStorage);
}
libsumo::POI::setImageFile(id, imageFile);
}
break;
case libsumo::VAR_HIGHLIGHT: {
// Highlight the POI by adding a polygon (NOTE: duplicated code exists for vehicle domain)
if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "A compound object is needed for highlighting an object.", outputStorage);
}
int itemNo = inputStorage.readUnsignedByte();
if (itemNo > 5) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "Highlighting an object needs zero to five parameters.", outputStorage);
}
libsumo::TraCIColor col = libsumo::TraCIColor(255, 0, 0);
if (itemNo > 0) {
if (!server.readTypeCheckingColor(inputStorage, col)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The first parameter for highlighting must be the highlight color.", outputStorage);
}
}
double size = -1;
if (itemNo > 1) {
if (!server.readTypeCheckingDouble(inputStorage, size)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The second parameter for highlighting must be the highlight size.", outputStorage);
}
//.........这里部分代码省略.........
示例3: toHex
bool
TraCIServerAPI_Edge::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != VAR_EDGE_TRAVELTIME && variable != VAR_EDGE_EFFORT && variable != VAR_MAXSPEED && variable != VAR_PARAMETER) {
return server.writeErrorStatusCmd(CMD_SET_EDGE_VARIABLE, "Change Edge State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
}
// id
std::string id = inputStorage.readString();
MSEdge* e = MSEdge::dictionary(id);
if (e == 0) {
return server.writeErrorStatusCmd(CMD_SET_EDGE_VARIABLE, "Edge '" + id + "' is not known", outputStorage);
}
// process
switch (variable) {
case LANE_ALLOWED: {
// read and set allowed vehicle classes
std::vector<std::string> classes;
if (!server.readTypeCheckingStringList(inputStorage, classes)) {
return server.writeErrorStatusCmd(CMD_SET_EDGE_VARIABLE, "Allowed vehicle classes must be given as a list of strings.", outputStorage);
}
SVCPermissions permissions = parseVehicleClasses(classes);
const std::vector<MSLane*>& lanes = e->getLanes();
for (std::vector<MSLane*>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
(*i)->setPermissions(permissions);
}
e->rebuildAllowedLanes();
}
break;
case LANE_DISALLOWED: {
// read and set disallowed vehicle classes
std::vector<std::string> classes;
if (!server.readTypeCheckingStringList(inputStorage, classes)) {
return server.writeErrorStatusCmd(CMD_SET_EDGE_VARIABLE, "Not allowed vehicle classes must be given as a list of strings.", outputStorage);
}
SVCPermissions permissions = ~parseVehicleClasses(classes); // negation yields allowed
const std::vector<MSLane*>& lanes = e->getLanes();
for (std::vector<MSLane*>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
(*i)->setPermissions(permissions);
}
e->rebuildAllowedLanes();
}
break;
case VAR_EDGE_TRAVELTIME: {
// read and set travel time
if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time requires a compound object.", outputStorage);
}
int parameterCount = inputStorage.readInt();
if (parameterCount == 3) {
// bound by time
int begTime = 0, endTime = 0;
double value = 0;
if (!server.readTypeCheckingInt(inputStorage, begTime)) {
return server.writeErrorStatusCmd(CMD_GET_EDGE_VARIABLE, "The first variable must be the begin time given as int.", outputStorage);
}
if (!server.readTypeCheckingInt(inputStorage, endTime)) {
return server.writeErrorStatusCmd(CMD_GET_EDGE_VARIABLE, "The second variable must be the end time given as int.", outputStorage);
}
if (!server.readTypeCheckingDouble(inputStorage, value)) {
return server.writeErrorStatusCmd(CMD_SET_EDGE_VARIABLE, "The third variable must be the value given as double", outputStorage);
}
MSNet::getInstance()->getWeightsStorage().addTravelTime(e, begTime, endTime, value);
} else if (parameterCount == 1) {
// unbound
double value = 0;
if (!server.readTypeCheckingDouble(inputStorage, value)) {
return server.writeErrorStatusCmd(CMD_SET_EDGE_VARIABLE, "The variable must be the value given as double", outputStorage);
}
MSNet::getInstance()->getWeightsStorage().addTravelTime(e, SUMOReal(0), SUMOReal(SUMOTime_MAX), value);
} else {
return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting travel time requires either begin time, end time, and value, or only value as parameter.", outputStorage);
}
}
break;
case VAR_EDGE_EFFORT: {
// read and set effort
if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
return server.writeErrorStatusCmd(CMD_SET_VEHICLE_VARIABLE, "Setting effort requires a compound object.", outputStorage);
}
int parameterCount = inputStorage.readInt();
if (parameterCount == 3) {
// bound by time
int begTime = 0, endTime = 0;
double value = 0;
if (!server.readTypeCheckingInt(inputStorage, begTime)) {
return server.writeErrorStatusCmd(CMD_GET_EDGE_VARIABLE, "The first variable must be the begin time given as int.", outputStorage);
}
if (!server.readTypeCheckingInt(inputStorage, endTime)) {
return server.writeErrorStatusCmd(CMD_GET_EDGE_VARIABLE, "The second variable must be the end time given as int.", outputStorage);
}
if (!server.readTypeCheckingDouble(inputStorage, value)) {
return server.writeErrorStatusCmd(CMD_SET_EDGE_VARIABLE, "The third variable must be the value given as double", outputStorage);
}
MSNet::getInstance()->getWeightsStorage().addEffort(e, begTime, endTime, value);
} else if (parameterCount == 1) {
// unbound
double value = 0;
//.........这里部分代码省略.........
示例4: switch
//.........这里部分代码省略.........
return false;
}
break;
case DISTANCE_REQUEST:
if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of distance requires a compound object.", outputStorage);
}
if (inputStorage.readInt() != 3) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of distance requires two positions and a distance type as parameter.", outputStorage);
}
if (!commandDistanceRequest(server, inputStorage, server.getWrapperStorage(), CMD_GET_SIM_VARIABLE)) {
return false;
}
break;
case FIND_ROUTE: {
if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a compound object.", outputStorage);
}
if (inputStorage.readInt() != 5) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires five parameter.", outputStorage);
}
std::string from, to, vtype;
double depart;
int routingMode;
if (!server.readTypeCheckingString(inputStorage, from)) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as first parameter.", outputStorage);
}
if (!server.readTypeCheckingString(inputStorage, to)) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as second parameter.", outputStorage);
}
if (!server.readTypeCheckingString(inputStorage, vtype)) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as third parameter.", outputStorage);
}
if (!server.readTypeCheckingDouble(inputStorage, depart)) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as fourth parameter.", outputStorage);
}
if (!server.readTypeCheckingInt(inputStorage, routingMode)) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires an integer as fifth parameter.", outputStorage);
}
writeStage(server.getWrapperStorage(), libsumo::Simulation::findRoute(from, to, vtype, TIME2STEPS(depart), routingMode));
break;
}
case FIND_INTERMODAL_ROUTE: {
if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of an intermodal route requires a compound object.", outputStorage);
}
if (inputStorage.readInt() != 13) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of an intermodal route requires thirteen parameters.", outputStorage);
}
std::string from, to, modes, ptype, vtype, destStop;
double depart, speed, walkFactor, departPos, arrivalPos, departPosLat;
int routingMode;
if (!server.readTypeCheckingString(inputStorage, from)) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as first parameter.", outputStorage);
}
if (!server.readTypeCheckingString(inputStorage, to)) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as second parameter.", outputStorage);
}
if (!server.readTypeCheckingString(inputStorage, modes)) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a string as third parameter.", outputStorage);
}
if (!server.readTypeCheckingDouble(inputStorage, depart)) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as fourth parameter.", outputStorage);
}
if (!server.readTypeCheckingInt(inputStorage, routingMode)) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires an integer as fifth parameter.", outputStorage);
示例5: getNamedView
bool
TraCIServerAPI_GUI::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != VAR_VIEW_ZOOM && variable != VAR_VIEW_OFFSET && variable != VAR_VIEW_SCHEMA && variable != VAR_VIEW_BOUNDARY
&& variable != VAR_SCREENSHOT && variable != VAR_TRACK_VEHICLE
) {
return server.writeErrorStatusCmd(CMD_SET_GUI_VARIABLE, "Change GUI State: unsupported variable specified", outputStorage);
}
// id
std::string id = inputStorage.readString();
GUISUMOAbstractView* v = getNamedView(id);
if (v == 0) {
return server.writeErrorStatusCmd(CMD_SET_GUI_VARIABLE, "View '" + id + "' is not known", outputStorage);
}
// process
switch (variable) {
case VAR_VIEW_ZOOM: {
Position off, p;
double zoom = 1;
if (!server.readTypeCheckingDouble(inputStorage, zoom)) {
return server.writeErrorStatusCmd(CMD_SET_GUI_VARIABLE, "The zoom must be given as a double.", outputStorage);
}
off.set(v->getChanger().getXPos(), v->getChanger().getYPos(), zoom);
v->setViewport(off, p);
}
break;
case VAR_VIEW_OFFSET: {
Position off, p;
if (!server.readTypeCheckingPosition2D(inputStorage, off)) {
return server.writeErrorStatusCmd(CMD_SET_GUI_VARIABLE, "The view port must be given as a position.", outputStorage);
}
off.set(off.x(), off.y(), v->getChanger().getZoom());
v->setViewport(off, p);
}
break;
case VAR_VIEW_SCHEMA: {
std::string schema;
if (!server.readTypeCheckingString(inputStorage, schema)) {
return server.writeErrorStatusCmd(CMD_SET_GUI_VARIABLE, "The scheme must be specified by a string.", outputStorage);
}
if (!v->setColorScheme(schema)) {
return server.writeErrorStatusCmd(CMD_SET_GUI_VARIABLE, "The scheme is not known.", outputStorage);
}
}
break;
case VAR_VIEW_BOUNDARY: {
Boundary b;
if (!server.readTypeCheckingBoundary(inputStorage, b)) {
return server.writeErrorStatusCmd(CMD_SET_GUI_VARIABLE, "The boundary must be specified by a bounding box.", outputStorage);
}
v->centerTo(b);
break;
}
case VAR_SCREENSHOT: {
std::string filename;
if (!server.readTypeCheckingString(inputStorage, filename)) {
return server.writeErrorStatusCmd(CMD_SET_GUI_VARIABLE, "Making a snapshot requires a file name.", outputStorage);
}
std::string error = v->makeSnapshot(filename);
if (error != "") {
return server.writeErrorStatusCmd(CMD_SET_GUI_VARIABLE, error, outputStorage);
}
}
break;
case VAR_TRACK_VEHICLE: {
std::string id;
if (!server.readTypeCheckingString(inputStorage, id)) {
return server.writeErrorStatusCmd(CMD_SET_GUI_VARIABLE, "Tracking requires a string vehicle ID.", outputStorage);
}
if (id == "") {
v->stopTrack();
} else {
SUMOVehicle* veh = MSNet::getInstance()->getVehicleControl().getVehicle(id);
if (veh == 0) {
return server.writeErrorStatusCmd(CMD_SET_GUI_VARIABLE, "Could not find vehicle '" + id + "'.", outputStorage);
}
if (!static_cast<GUIVehicle*>(veh)->hasActiveAddVisualisation(v, GUIVehicle::VO_TRACKED)) {
v->startTrack(static_cast<GUIVehicle*>(veh)->getGlID());
static_cast<GUIVehicle*>(veh)->addActiveAddVisualisation(v, GUIVehicle::VO_TRACKED);
}
}
}
default:
break;
}
server.writeStatusCmd(CMD_SET_GUI_VARIABLE, RTYPE_OK, warning, outputStorage);
return true;
}