当前位置: 首页 > news >正文

佛山网站建设推广企业所得税优惠政策2021年计算

佛山网站建设推广,企业所得税优惠政策2021年计算,pvc建筑模板生产厂家,重庆巨能建设集团网站为了在命令模式的基础上实现撤销#xff08;Undo#xff09;和回退#xff08;Redo#xff09;功能#xff0c;我们可以在每个命令类中记录一些必要的状态#xff0c;允许我们撤销之前的操作#xff0c;并在需要时回退操作。常见的做法是使用一个命令堆栈来存储历史命令…为了在命令模式的基础上实现撤销Undo和回退Redo功能我们可以在每个命令类中记录一些必要的状态允许我们撤销之前的操作并在需要时回退操作。常见的做法是使用一个命令堆栈来存储历史命令并为每个命令提供撤销undo操作。 我们可以通过以下步骤来添加撤销和回退功能 Command接口为命令接口添加一个undo()方法。具体命令类ConcreteCommand为每个具体命令类实现undo()方法撤销相应的操作。Invoker类管理一个命令堆栈历史记录并实现undo()和redo()方法来执行撤销和回退操作。 代码实现 我们将对之前的代码进行修改来实现撤销和回退功能 #include iostream #include memory #include vector #include stack// 绘图命令接口 class Command { public:virtual ~Command() default;virtual void execute() 0;virtual void undo() 0; // 增加撤销操作接口 };// 接收者绘图工具如画布 class Receiver { public:void drawPoint(int x, int y) {std::cout Drawing point at ( x , y ).\n;}void undoDrawPoint(int x, int y) {std::cout Undo drawing point at ( x , y ).\n;}void drawLine(int x1, int y1, int x2, int y2) {std::cout Drawing line from ( x1 , y1 ) to ( x2 , y2 ).\n;}void undoDrawLine(int x1, int y1, int x2, int y2) {std::cout Undo drawing line from ( x1 , y1 ) to ( x2 , y2 ).\n;}void drawCircle(int x, int y, int radius) {std::cout Drawing circle at ( x , y ) with radius radius .\n;}void undoDrawCircle(int x, int y, int radius) {std::cout Undo drawing circle at ( x , y ) with radius radius .\n;}void drawEllipse(int x, int y, int majorAxis, int minorAxis) {std::cout Drawing ellipse at ( x , y ) with major axis majorAxis and minor axis minorAxis .\n;}void undoDrawEllipse(int x, int y, int majorAxis, int minorAxis) {std::cout Undo drawing ellipse at ( x , y ) with major axis majorAxis and minor axis minorAxis .\n;}void drawPolyline(const std::vectorstd::pairint, int points) {std::cout Drawing polyline with the following points:\n;for (const auto point : points) {std::cout ( point.first , point.second ) ;}std::cout \n;}void undoDrawPolyline(const std::vectorstd::pairint, int points) {std::cout Undo drawing polyline with the following points:\n;for (const auto point : points) {std::cout ( point.first , point.second ) ;}std::cout \n;} };// 绘制点的命令 class DrawPointCommand : public Command { private:Receiver* receiver;int x, y; public:DrawPointCommand(Receiver* r, int x, int y) : receiver(r), x(x), y(y) {}void execute() override {receiver-drawPoint(x, y);}void undo() override {receiver-undoDrawPoint(x, y);} };// 绘制直线的命令 class DrawLineCommand : public Command { private:Receiver* receiver;int x1, y1, x2, y2; public:DrawLineCommand(Receiver* r, int x1, int y1, int x2, int y2) : receiver(r), x1(x1), y1(y1), x2(x2), y2(y2) {}void execute() override {receiver-drawLine(x1, y1, x2, y2);}void undo() override {receiver-undoDrawLine(x1, y1, x2, y2);} };// 绘制圆形的命令 class DrawCircleCommand : public Command { private:Receiver* receiver;int x, y, radius; public:DrawCircleCommand(Receiver* r, int x, int y, int radius) : receiver(r), x(x), y(y), radius(radius) {}void execute() override {receiver-drawCircle(x, y, radius);}void undo() override {receiver-undoDrawCircle(x, y, radius);} };// 绘制椭圆的命令 class DrawEllipseCommand : public Command { private:Receiver* receiver;int x, y, majorAxis, minorAxis; public:DrawEllipseCommand(Receiver* r, int x, int y, int majorAxis, int minorAxis) : receiver(r), x(x), y(y), majorAxis(majorAxis), minorAxis(minorAxis) {}void execute() override {receiver-drawEllipse(x, y, majorAxis, minorAxis);}void undo() override {receiver-undoDrawEllipse(x, y, majorAxis, minorAxis);} };// 绘制多段线的命令 class DrawPolylineCommand : public Command { private:Receiver* receiver;std::vectorstd::pairint, int points; public:DrawPolylineCommand(Receiver* r, const std::vectorstd::pairint, int points) : receiver(r), points(points) {}void execute() override {receiver-drawPolyline(points);}void undo() override {receiver-undoDrawPolyline(points);} };// 调用者工具栏或按钮 class Invoker { private:std::stackstd::shared_ptrCommand commandHistory; // 历史命令栈std::stackstd::shared_ptrCommand redoStack; // 重做命令栈public:void executeCommand(std::shared_ptrCommand cmd) {cmd-execute();commandHistory.push(cmd); // 将命令压入历史栈while (!redoStack.empty()) { // 清空重做栈redoStack.pop();}}void undo() {if (!commandHistory.empty()) {std::shared_ptrCommand cmd commandHistory.top();commandHistory.pop();cmd-undo();redoStack.push(cmd); // 将撤销的命令压入重做栈} else {std::cout No command to undo.\n;}}void redo() {if (!redoStack.empty()) {std::shared_ptrCommand cmd redoStack.top();redoStack.pop();cmd-execute();commandHistory.push(cmd); // 将重做的命令压入历史栈} else {std::cout No command to redo.\n;}} };// 客户端代码 int main() {Receiver receiver; // 绘图工具画布// 创建具体的命令std::shared_ptrCommand drawPoint std::make_sharedDrawPointCommand(receiver, 10, 20);std::shared_ptrCommand drawLine std::make_sharedDrawLineCommand(receiver, 10, 20, 30, 40);std::shared_ptrCommand drawCircle std::make_sharedDrawCircleCommand(receiver, 50, 50, 15);std::shared_ptrCommand drawEllipse std::make_sharedDrawEllipseCommand(receiver, 70, 70, 20, 10);std::vectorstd::pairint, int polylinePoints {{10, 10}, {20, 20}, {30, 30}, {40, 40}};std::shared_ptrCommand drawPolyline std::make_sharedDrawPolylineCommand(receiver, polylinePoints);// 创建调用者Invoker invoker;// 模拟用户操作通过调用命令绘制图形invoker.executeCommand(drawPoint);invoker.executeCommand(drawLine);invoker.executeCommand(drawCircle);invoker.executeCommand(drawEllipse);invoker.executeCommand(drawPolyline);// 撤销操作std::cout \nUndoing the last command:\n;invoker.undo();// 回退重做操作std::cout \nRedoing the last undone command:\n;invoker.redo();return 0; }关键修改 Command接口添加了undo()方法使每个命令都能撤销其操作。Receiver类为每个绘制方法添加了撤销方法undoDraw...用于撤销具体的图形操作。Invoker类管理两个栈——commandHistory历史命令栈和redoStack重做命令栈。在执行命令时将其压入commandHistory在撤销时将命令从commandHistory中取出并执行undo()同时将命令压入redoStack。回退时从redoStack取出命令并重新执行。 输出 Drawing point at (10, 20). Drawing line from (10, 20) to (30, 40). Drawing circle at (50, 50) with radius 15. Drawing ellipse at (70, 70) with major axis 20 and minor axis 10. Drawing polyline with the following points: (10, 10) (20, 20) (30, 30) (40, 40)Undoing the last command: Undo drawing polyline with the following points: (10, 10) (20, 20) (30, 30) (40, 40)Redoing the last undone command: Drawing polyline with the following points: (10, 10) (20, 20) (30, 30) (40, 40)功能扩展 撤销操作允许撤销最后的绘图命令。回退操作允许重做之前撤销的命令。 这样我们就实现了撤销和回退功能用户可以随时撤销之前的操作并恢复它们。
http://www.zqtcl.cn/news/394475/

相关文章:

  • 沈阳怎么做网站西亚网站建设科技
  • 做外贸免费的网站有哪些专业简历制作
  • 园林景观设计网站推荐国内wordpress主题
  • 一流的免费网站建设摄影网站源码
  • 深圳高端网站设计公司怎样开发手机网站建设
  • 做网站需要用c语言吗新闻热点
  • 做网站需要交维护费么网站建设详细合同范本
  • 网站运营需要做什么静态网站作品
  • 如何做旅游休闲网站苍南做网站
  • wordpress jp theme关键词排名优化公司成都
  • Soho外贸常用网站wordpress下不了插件吗
  • 企业网站建设小技巧有哪些WordPress网站小程序
  • 公司招聘网站续费申请seo编辑是干什么的
  • 58同城泉州网站建设人工投票平台app
  • dede 网站地图 插件网站引导页flash
  • 聊城做网站的公司渠道网站总体结构
  • 北京比较大的网站建设公司wap网站引导页特效
  • 做关于植物的网站即墨网站设计
  • 怎么提升网站收录商品网页制作
  • 做网站建设的平台wordpress5.0发布
  • 站长工具a级查网站域名
  • 免费做网站电话手机开发者模式打开有什么影响
  • 上海免费网站建站模板毕节做网站优化
  • 影响网站建设的关键点手机网站制作app
  • 商务网站建设的流程深圳模板网站建设案例
  • 做中英文网站多少钱方维制网站
  • 做一个信息发布网站要多少钱开发小程序多少钱一个
  • 山东网站设计网站关键词设置技巧
  • 做网站服务怎么赚钱产品展示型的网站功能有哪些
  • 丹东网站制作宁波网站建设公司制作网站