本文整理汇总了C++中TraCIServer::readTypeCheckingUnsignedByte方法的典型用法代码示例。如果您正苦于以下问题:C++ TraCIServer::readTypeCheckingUnsignedByte方法的具体用法?C++ TraCIServer::readTypeCheckingUnsignedByte怎么用?C++ TraCIServer::readTypeCheckingUnsignedByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TraCIServer
的用法示例。
在下文中一共展示了TraCIServer::readTypeCheckingUnsignedByte方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toHex
//.........这里部分代码省略.........
}
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);
}
}
int alphaMax = -1;
if (itemNo > 2) {
if (!server.readTypeCheckingUnsignedByte(inputStorage, alphaMax)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The third parameter for highlighting must be maximal alpha.", outputStorage);
}
}
double duration = -1;
if (itemNo > 3) {
if (!server.readTypeCheckingDouble(inputStorage, duration)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fourth parameter for highlighting must be the highlight duration.", outputStorage);
}
}
int type = 0;
if (itemNo > 4) {
if (!server.readTypeCheckingUnsignedByte(inputStorage, type)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fifth parameter for highlighting must be the highlight type id as ubyte.", outputStorage);
}
}
libsumo::POI::highlight(id, col, size, alphaMax, duration, type);
}
break;
case libsumo::ADD: {
if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "A compound object is needed for setting a new PoI.", outputStorage);
}
//read itemNo
const int parameterCount = inputStorage.readInt();
std::string type;
if (!server.readTypeCheckingString(inputStorage, type)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The first PoI parameter must be the type encoded as a string.", outputStorage);
}
libsumo::TraCIColor col;
if (!server.readTypeCheckingColor(inputStorage, col)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The second PoI parameter must be the color.", outputStorage);
}
示例2: switch
bool
TraCIServerAPI_Simulation::commandPositionConversion(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage, int commandId) {
std::pair<MSLane*, SUMOReal> roadPos;
Position cartesianPos;
Position geoPos;
SUMOReal z = 0;
// actual position type that will be converted
int srcPosType = inputStorage.readUnsignedByte();
switch (srcPosType) {
case POSITION_2D:
case POSITION_3D:
case POSITION_LON_LAT:
case POSITION_LON_LAT_ALT: {
SUMOReal x = inputStorage.readDouble();
SUMOReal y = inputStorage.readDouble();
if (srcPosType != POSITION_2D && srcPosType != POSITION_LON_LAT) {
z = inputStorage.readDouble();
}
geoPos.set(x, y);
cartesianPos.set(x, y);
if (srcPosType == POSITION_LON_LAT || srcPosType == POSITION_LON_LAT_ALT) {
GeoConvHelper::getFinal().x2cartesian_const(cartesianPos);
} else {
GeoConvHelper::getFinal().cartesian2geo(geoPos);
}
}
break;
case POSITION_ROADMAP: {
std::string roadID = inputStorage.readString();
SUMOReal pos = inputStorage.readDouble();
int laneIdx = inputStorage.readUnsignedByte();
try {
// convert edge,offset,laneIdx to cartesian position
cartesianPos = geoPos = getLaneChecking(roadID, laneIdx, pos)->getShape().positionAtOffset(pos);
z = cartesianPos.z();
GeoConvHelper::getFinal().cartesian2geo(geoPos);
} catch (TraCIException& e) {
server.writeStatusCmd(commandId, RTYPE_ERR, e.what());
return false;
}
}
break;
default:
server.writeStatusCmd(commandId, RTYPE_ERR, "Source position type not supported");
return false;
}
int destPosType = 0;
if (!server.readTypeCheckingUnsignedByte(inputStorage, destPosType)) {
server.writeStatusCmd(commandId, RTYPE_ERR, "Destination position type must be of type ubyte.");
return false;
}
switch (destPosType) {
case POSITION_ROADMAP: {
// convert cartesion position to edge,offset,lane_index
roadPos = convertCartesianToRoadMap(cartesianPos);
// write result that is added to response msg
outputStorage.writeUnsignedByte(POSITION_ROADMAP);
outputStorage.writeString(roadPos.first->getEdge().getID());
outputStorage.writeDouble(roadPos.second);
const std::vector<MSLane*> lanes = roadPos.first->getEdge().getLanes();
outputStorage.writeUnsignedByte((int)distance(lanes.begin(), find(lanes.begin(), lanes.end(), roadPos.first)));
}
break;
case POSITION_2D:
case POSITION_3D:
case POSITION_LON_LAT:
case POSITION_LON_LAT_ALT:
outputStorage.writeUnsignedByte(destPosType);
if (destPosType == POSITION_LON_LAT || destPosType == POSITION_LON_LAT_ALT) {
outputStorage.writeDouble(geoPos.x());
outputStorage.writeDouble(geoPos.y());
} else {
outputStorage.writeDouble(cartesianPos.x());
outputStorage.writeDouble(cartesianPos.y());
}
if (destPosType != POSITION_2D && destPosType != POSITION_LON_LAT) {
outputStorage.writeDouble(z);
}
break;
default:
server.writeStatusCmd(commandId, RTYPE_ERR, "Destination position type not supported");
return false;
}
return true;
}
示例3: getPolygon
bool
TraCIServerAPI_Polygon::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
std::string warning = ""; // additional description for response
// variable
int variable = inputStorage.readUnsignedByte();
if (variable != VAR_TYPE && variable != VAR_COLOR && variable != VAR_SHAPE && variable != VAR_FILL
&& variable != ADD && variable != REMOVE) {
return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "Change Polygon State: unsupported variable specified", outputStorage);
}
// id
std::string id = inputStorage.readString();
Polygon* p = 0;
ShapeContainer& shapeCont = MSNet::getInstance()->getShapeContainer();
if (variable != ADD && variable != REMOVE) {
p = getPolygon(id);
if (p == 0) {
return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "Polygon '" + id + "' is not known", outputStorage);
}
}
// process
switch (variable) {
case VAR_TYPE: {
std::string type;
if (!server.readTypeCheckingString(inputStorage, type)) {
return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The type must be given as a string.", outputStorage);
}
p->setType(type);
}
break;
case VAR_COLOR: {
RGBColor col;
if (!server.readTypeCheckingColor(inputStorage, col)) {
return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The color must be given using an according type.", outputStorage);
}
p->setColor(col);
}
break;
case VAR_SHAPE: {
PositionVector shape;
if (!server.readTypeCheckingPolygon(inputStorage, shape)) {
return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The shape must be given using an accoring type.", outputStorage);
}
shapeCont.reshapePolygon(id, shape);
}
break;
case VAR_FILL: {
int value = 0;
if (!server.readTypeCheckingUnsignedByte(inputStorage, value)) {
return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "'fill' must be defined using an unsigned byte.", outputStorage);
}
p->setFill(value != 0);
}
break;
case ADD: {
if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "A compound object is needed for setting a new polygon.", outputStorage);
}
//readt itemNo
inputStorage.readInt();
std::string type;
if (!server.readTypeCheckingString(inputStorage, type)) {
return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The type must be given as a string.", outputStorage);
}
RGBColor col;
if (!server.readTypeCheckingColor(inputStorage, col)) {
return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The second polygon parameter must be the color.", outputStorage);
}
int value = 0;
if (!server.readTypeCheckingUnsignedByte(inputStorage, value)) {
return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The third polygon parameter must be 'fill' encoded as ubyte.", outputStorage);
}
bool fill = value != 0;
int layer = 0;
if (!server.readTypeCheckingInt(inputStorage, layer)) {
return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The fourth polygon parameter must be the layer encoded as int.", outputStorage);
}
PositionVector shape;
if (!server.readTypeCheckingPolygon(inputStorage, shape)) {
return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The fifth polygon parameter must be the shape.", outputStorage);
}
//
if (!shapeCont.addPolygon(id, type, col, (SUMOReal)layer,
Shape::DEFAULT_ANGLE, Shape::DEFAULT_IMG_FILE, shape, fill)) {
delete p;
return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "Could not add polygon.", outputStorage);
}
}
break;
case REMOVE: {
int layer = 0; // !!! layer not used yet (shouldn't the id be enough?)
if (!server.readTypeCheckingInt(inputStorage, layer)) {
return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The layer must be given using an int.", outputStorage);
}
if (!shapeCont.removePolygon(id)) {
return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "Could not remove polygon '" + id + "'", outputStorage);
}
}
break;
default:
//.........这里部分代码省略.........