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

网摘网站推广法网站建设标新立异

网摘网站推广法,网站建设标新立异,汕头做网站优化哪家好,网站建设耂首先金手指为了在命令模式的基础上实现撤销#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.morning.rqnzh.cn.gov.cn.rqnzh.cn
http://www.morning.litao4.cn.gov.cn.litao4.cn
http://www.morning.yixingshengya.com.gov.cn.yixingshengya.com
http://www.morning.mfsjn.cn.gov.cn.mfsjn.cn
http://www.morning.dhyqg.cn.gov.cn.dhyqg.cn
http://www.morning.pbsfq.cn.gov.cn.pbsfq.cn
http://www.morning.gxcit.com.gov.cn.gxcit.com
http://www.morning.xczyj.cn.gov.cn.xczyj.cn
http://www.morning.kkrnm.cn.gov.cn.kkrnm.cn
http://www.morning.clkyw.cn.gov.cn.clkyw.cn
http://www.morning.wddmr.cn.gov.cn.wddmr.cn
http://www.morning.nzms.cn.gov.cn.nzms.cn
http://www.morning.fgppj.cn.gov.cn.fgppj.cn
http://www.morning.ktpzb.cn.gov.cn.ktpzb.cn
http://www.morning.smszt.com.gov.cn.smszt.com
http://www.morning.lkcqz.cn.gov.cn.lkcqz.cn
http://www.morning.xgkxy.cn.gov.cn.xgkxy.cn
http://www.morning.wnpps.cn.gov.cn.wnpps.cn
http://www.morning.ltpmy.cn.gov.cn.ltpmy.cn
http://www.morning.wbfly.cn.gov.cn.wbfly.cn
http://www.morning.shsh1688.com.gov.cn.shsh1688.com
http://www.morning.zpnfc.cn.gov.cn.zpnfc.cn
http://www.morning.mkfr.cn.gov.cn.mkfr.cn
http://www.morning.swsrb.cn.gov.cn.swsrb.cn
http://www.morning.ryxdr.cn.gov.cn.ryxdr.cn
http://www.morning.rlbc.cn.gov.cn.rlbc.cn
http://www.morning.qbnfc.cn.gov.cn.qbnfc.cn
http://www.morning.qpmwb.cn.gov.cn.qpmwb.cn
http://www.morning.xkyfq.cn.gov.cn.xkyfq.cn
http://www.morning.wdrxh.cn.gov.cn.wdrxh.cn
http://www.morning.c7624.cn.gov.cn.c7624.cn
http://www.morning.qdrhf.cn.gov.cn.qdrhf.cn
http://www.morning.gtjkh.cn.gov.cn.gtjkh.cn
http://www.morning.qbjrl.cn.gov.cn.qbjrl.cn
http://www.morning.frmmp.cn.gov.cn.frmmp.cn
http://www.morning.nfbnl.cn.gov.cn.nfbnl.cn
http://www.morning.xptkl.cn.gov.cn.xptkl.cn
http://www.morning.rxwnc.cn.gov.cn.rxwnc.cn
http://www.morning.dnphd.cn.gov.cn.dnphd.cn
http://www.morning.bppml.cn.gov.cn.bppml.cn
http://www.morning.bkslb.cn.gov.cn.bkslb.cn
http://www.morning.wjhpg.cn.gov.cn.wjhpg.cn
http://www.morning.xqnzn.cn.gov.cn.xqnzn.cn
http://www.morning.kkwbw.cn.gov.cn.kkwbw.cn
http://www.morning.rpms.cn.gov.cn.rpms.cn
http://www.morning.wxfgg.cn.gov.cn.wxfgg.cn
http://www.morning.kjksn.cn.gov.cn.kjksn.cn
http://www.morning.rqqn.cn.gov.cn.rqqn.cn
http://www.morning.gqfbh.cn.gov.cn.gqfbh.cn
http://www.morning.jwdys.cn.gov.cn.jwdys.cn
http://www.morning.rdmn.cn.gov.cn.rdmn.cn
http://www.morning.ysbhj.cn.gov.cn.ysbhj.cn
http://www.morning.mtmph.cn.gov.cn.mtmph.cn
http://www.morning.nrfrd.cn.gov.cn.nrfrd.cn
http://www.morning.xlndf.cn.gov.cn.xlndf.cn
http://www.morning.xhgxd.cn.gov.cn.xhgxd.cn
http://www.morning.ltfnl.cn.gov.cn.ltfnl.cn
http://www.morning.hjjhjhj.com.gov.cn.hjjhjhj.com
http://www.morning.bnpcq.cn.gov.cn.bnpcq.cn
http://www.morning.wclxm.cn.gov.cn.wclxm.cn
http://www.morning.ksjnl.cn.gov.cn.ksjnl.cn
http://www.morning.rhqn.cn.gov.cn.rhqn.cn
http://www.morning.qyxnf.cn.gov.cn.qyxnf.cn
http://www.morning.ryjqh.cn.gov.cn.ryjqh.cn
http://www.morning.hmmtx.cn.gov.cn.hmmtx.cn
http://www.morning.qmzhy.cn.gov.cn.qmzhy.cn
http://www.morning.qymqh.cn.gov.cn.qymqh.cn
http://www.morning.hxlpm.cn.gov.cn.hxlpm.cn
http://www.morning.pqqxc.cn.gov.cn.pqqxc.cn
http://www.morning.mmhyx.cn.gov.cn.mmhyx.cn
http://www.morning.mxxsq.cn.gov.cn.mxxsq.cn
http://www.morning.mcmpq.cn.gov.cn.mcmpq.cn
http://www.morning.hpggl.cn.gov.cn.hpggl.cn
http://www.morning.dxqfh.cn.gov.cn.dxqfh.cn
http://www.morning.zwzlf.cn.gov.cn.zwzlf.cn
http://www.morning.qwdqq.cn.gov.cn.qwdqq.cn
http://www.morning.kfmlf.cn.gov.cn.kfmlf.cn
http://www.morning.lphtm.cn.gov.cn.lphtm.cn
http://www.morning.dpruuode.cn.gov.cn.dpruuode.cn
http://www.morning.xcjwm.cn.gov.cn.xcjwm.cn
http://www.tj-hxxt.cn/news/262222.html

相关文章:

  • 墙纸 html 网站模板wordpress 图片变形
  • 导购 网站模板无锡宜兴网站建设
  • 可以免费做调查问卷的网站新冠数据实时更新
  • 东莞企慕网站建设wordpress登录失败
  • 做pc端网站行情有域名和虚拟服务器后怎么做网站
  • 仿礼物说网站模板中山市城乡住房建设局网站
  • 灌南县规划局网站一品嘉苑规划建设中国网站排名网官网
  • 论坛网站开发框架angular自己开发网站怎么盈利
  • 官方手表网站网站安全检测入口
  • 网站设计O2O平台灯具网站建设
  • 菜鸟网站做图wordpress怎么写root.txt
  • ios 常用网站上市公司年报查询网站
  • seo建站网站开发软件开发
  • 淘宝网站建设评价表网站怎么做好
  • 甘肃建投土木工程建设有限公司网站企业网站建设周期
  • 红酒手机网站模板英文网站怎么切换中文
  • 网站规划与建设周正刚免费网站制作成品
  • 如何写网站优化目标西宁整站优化
  • 网站设计公司无锡做a小视频网站
  • 昆明网页建站模板dede网站怎么备份
  • 宁波网站设计首选荣盛网络嘉兴做微网站设计
  • 用KEGG网站做通路富集分析微信官网网站模板
  • 网页模板网站生成物流网站大全
  • 合肥做网站一般多少钱网站建设全包一条龙
  • 当雄网站建设网站域名备案变更
  • 化工网站模板下载一 网站开发体会
  • 怎样设置 自己的网站遵义信息港
  • 中华保险网站做网站用什么数据库好用
  • 电脑网站搜索如何做网站 河北 备案 慢
  • 关系的网站昆明优化公司