本文整理汇总了C++中TraCIServer::readTypeCheckingInt方法的典型用法代码示例。如果您正苦于以下问题:C++ TraCIServer::readTypeCheckingInt方法的具体用法?C++ TraCIServer::readTypeCheckingInt怎么用?C++ TraCIServer::readTypeCheckingInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TraCIServer
的用法示例。
在下文中一共展示了TraCIServer::readTypeCheckingInt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toHex
//.........这里部分代码省略.........
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);
}
int layer = 0;
if (!server.readTypeCheckingInt(inputStorage, layer)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The third PoI parameter must be the layer encoded as int.", outputStorage);
}
libsumo::TraCIPosition pos;
if (!server.readTypeCheckingPosition2D(inputStorage, pos)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The fourth PoI parameter must be the position.", outputStorage);
}
if (parameterCount == 4) {
if (!libsumo::POI::add(id, pos.x, pos.y, col, type, layer)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "Could not add PoI.", outputStorage);
}
} else if (parameterCount == 8) {
std::string imgFile;
if (!server.readTypeCheckingString(inputStorage, imgFile)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The fifth PoI parameter must be the imgFile encoded as a string.", outputStorage);
}
double width;
if (!server.readTypeCheckingDouble(inputStorage, width)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The sixth PoI parameter must be the width encoded as a double.", outputStorage);
}
double height;
if (!server.readTypeCheckingDouble(inputStorage, height)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The seventh PoI parameter must be the height encoded as a double.", outputStorage);
}
double angle;
if (!server.readTypeCheckingDouble(inputStorage, angle)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The eighth PoI parameter must be the angle encoded as a double.", outputStorage);
}
//
if (!libsumo::POI::add(id, pos.x, pos.y, col, type, layer, imgFile, width, height, angle)) {
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "Could not add PoI.", outputStorage);
}
} else {
示例2: toHex
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_Edge::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
tcpip::Storage& outputStorage) {
// variable & id
int variable = inputStorage.readUnsignedByte();
std::string id = inputStorage.readString();
// check variable
if (variable != ID_LIST && variable != VAR_EDGE_TRAVELTIME && variable != VAR_EDGE_EFFORT && variable != VAR_CURRENT_TRAVELTIME
&& variable != VAR_CO2EMISSION && variable != VAR_COEMISSION && variable != VAR_HCEMISSION && variable != VAR_PMXEMISSION
&& variable != VAR_NOXEMISSION && variable != VAR_FUELCONSUMPTION && variable != VAR_NOISEEMISSION && variable != VAR_WAITING_TIME
&& variable != LAST_STEP_VEHICLE_NUMBER && variable != LAST_STEP_MEAN_SPEED && variable != LAST_STEP_OCCUPANCY
&& variable != LAST_STEP_VEHICLE_HALTING_NUMBER && variable != LAST_STEP_LENGTH
&& variable != LAST_STEP_PERSON_ID_LIST
&& variable != LAST_STEP_VEHICLE_ID_LIST && variable != ID_COUNT && variable != VAR_PARAMETER) {
return server.writeErrorStatusCmd(CMD_GET_EDGE_VARIABLE, "Get Edge Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
}
// begin response building
tcpip::Storage tempMsg;
// response-code, variableID, objectID
tempMsg.writeUnsignedByte(RESPONSE_GET_EDGE_VARIABLE);
tempMsg.writeUnsignedByte(variable);
tempMsg.writeString(id);
// process request
if (variable == ID_LIST) {
std::vector<std::string> ids;
MSEdge::insertIDs(ids);
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeStringList(ids);
} else if (variable == ID_COUNT) {
std::vector<std::string> ids;
MSEdge::insertIDs(ids);
tempMsg.writeUnsignedByte(TYPE_INTEGER);
tempMsg.writeInt((int) ids.size());
} else {
MSEdge* e = MSEdge::dictionary(id);
if (e == 0) {
return server.writeErrorStatusCmd(CMD_GET_EDGE_VARIABLE, "Edge '" + id + "' is not known", outputStorage);
}
switch (variable) {
case VAR_EDGE_TRAVELTIME: {
// time
int time = 0;
if (!server.readTypeCheckingInt(inputStorage, time)) {
return server.writeErrorStatusCmd(CMD_GET_EDGE_VARIABLE, "The message must contain the time definition.", outputStorage);
}
tempMsg.writeUnsignedByte(TYPE_DOUBLE);
SUMOReal value;
if (!MSNet::getInstance()->getWeightsStorage().retrieveExistingTravelTime(e, time, value)) {
tempMsg.writeDouble(-1);
} else {
tempMsg.writeDouble(value);
}
}
break;
case VAR_EDGE_EFFORT: {
// time
int time = 0;
if (!server.readTypeCheckingInt(inputStorage, time)) {
return server.writeErrorStatusCmd(CMD_GET_EDGE_VARIABLE, "The message must contain the time definition.", outputStorage);
}
tempMsg.writeUnsignedByte(TYPE_DOUBLE);
SUMOReal value;
if (!MSNet::getInstance()->getWeightsStorage().retrieveExistingEffort(e, time, value)) {
tempMsg.writeDouble(-1);
} else {
tempMsg.writeDouble(value);
}
}
break;
case VAR_CURRENT_TRAVELTIME:
tempMsg.writeUnsignedByte(TYPE_DOUBLE);
tempMsg.writeDouble(e->getCurrentTravelTime());
break;
case VAR_WAITING_TIME: {
SUMOReal wtime = 0;
const std::vector<MSLane*>& lanes = e->getLanes();
for (std::vector<MSLane*>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
wtime += (*i)->getWaitingSeconds();
}
tempMsg.writeUnsignedByte(TYPE_DOUBLE);
tempMsg.writeDouble(wtime);
}
break;
case LAST_STEP_PERSON_ID_LIST: {
std::vector<std::string> personIDs;
std::vector<MSTransportable*> persons = e->getSortedPersons(MSNet::getInstance()->getCurrentTimeStep());
for (std::vector<MSTransportable*>::iterator it = persons.begin(); it != persons.end(); ++it) {
personIDs.push_back((*it)->getID());
}
tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
tempMsg.writeStringList(personIDs);
}
break;
case LAST_STEP_VEHICLE_ID_LIST: {
std::vector<std::string> vehIDs;
const std::vector<MSLane*>& lanes = e->getLanes();
for (std::vector<MSLane*>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
//.........这里部分代码省略.........
示例3: getPoI
bool
TraCIServerAPI_POI::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_POSITION
&& variable != ADD && variable != REMOVE) {
return server.writeErrorStatusCmd(CMD_SET_POI_VARIABLE, "Change PoI State: unsupported variable specified", outputStorage);
}
// id
std::string id = inputStorage.readString();
PointOfInterest* p = 0;
ShapeContainer& shapeCont = MSNet::getInstance()->getShapeContainer();
if (variable != ADD && variable != REMOVE) {
p = getPoI(id);
if (p == 0) {
return server.writeErrorStatusCmd(CMD_SET_POI_VARIABLE, "POI '" + id + "' is not known", outputStorage);
}
}
// process
switch (variable) {
case VAR_TYPE: {
std::string type;
if (!server.readTypeCheckingString(inputStorage, type)) {
return server.writeErrorStatusCmd(CMD_SET_POI_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_POI_VARIABLE, "The color must be given using an according type.", outputStorage);
}
p->setColor(col);
}
break;
case VAR_POSITION: {
Position pos;
if (!server.readTypeCheckingPosition2D(inputStorage, pos)) {
return server.writeErrorStatusCmd(CMD_SET_POI_VARIABLE, "The position must be given using an accoring type.", outputStorage);
}
shapeCont.movePOI(id, pos);
}
break;
case ADD: {
if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
return server.writeErrorStatusCmd(CMD_SET_POI_VARIABLE, "A compound object is needed for setting a new PoI.", outputStorage);
}
//read itemNo
inputStorage.readInt();
std::string type;
if (!server.readTypeCheckingString(inputStorage, type)) {
return server.writeErrorStatusCmd(CMD_SET_POI_VARIABLE, "The first PoI parameter must be the type encoded as a string.", outputStorage);
}
RGBColor col;
if (!server.readTypeCheckingColor(inputStorage, col)) {
return server.writeErrorStatusCmd(CMD_SET_POI_VARIABLE, "The second PoI parameter must be the color.", outputStorage);
}
int layer = 0;
if (!server.readTypeCheckingInt(inputStorage, layer)) {
return server.writeErrorStatusCmd(CMD_SET_POI_VARIABLE, "The third PoI parameter must be the layer encoded as int.", outputStorage);
}
Position pos;
if (!server.readTypeCheckingPosition2D(inputStorage, pos)) {
return server.writeErrorStatusCmd(CMD_SET_POI_VARIABLE, "The fourth PoI parameter must be the position.", outputStorage);
}
//
if (!shapeCont.addPOI(id, type, col, (SUMOReal)layer,
Shape::DEFAULT_ANGLE, Shape::DEFAULT_IMG_FILE, pos,
Shape::DEFAULT_IMG_WIDTH, Shape::DEFAULT_IMG_HEIGHT)) {
delete p;
return server.writeErrorStatusCmd(CMD_SET_POI_VARIABLE, "Could not add PoI.", 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_POI_VARIABLE, "The layer must be given using an int.", outputStorage);
}
if (!shapeCont.removePOI(id)) {
return server.writeErrorStatusCmd(CMD_SET_POI_VARIABLE, "Could not remove PoI '" + id + "'", outputStorage);
}
}
break;
default:
break;
}
server.writeStatusCmd(CMD_SET_POI_VARIABLE, RTYPE_OK, warning, outputStorage);
return true;
}
示例4: switch
//.........这里部分代码省略.........
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);
}
if (!server.readTypeCheckingDouble(inputStorage, speed)) {
return server.writeErrorStatusCmd(CMD_GET_SIM_VARIABLE, "Retrieval of a route requires a double as sixth parameter.", outputStorage);
示例5: 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:
//.........这里部分代码省略.........