本文整理汇总了C++中TraCIServer::readTypeCheckingColor方法的典型用法代码示例。如果您正苦于以下问题:C++ TraCIServer::readTypeCheckingColor方法的具体用法?C++ TraCIServer::readTypeCheckingColor怎么用?C++ TraCIServer::readTypeCheckingColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TraCIServer
的用法示例。
在下文中一共展示了TraCIServer::readTypeCheckingColor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例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: 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:
//.........这里部分代码省略.........