remotecontrol.hpp
来自「一个类似遥控器的源码程序。可以有多种功能」· HPP 代码 · 共 52 行
HPP
52 行
#ifndef _HEAD_FIRST_DESIGN_PATTERNS_COMMAND_REMOTE_CONTROL_HPP_
#define _HEAD_FIRST_DESIGN_PATTERNS_COMMAND_REMOTE_CONTROL_HPP_
#include "Remote.hpp"
namespace HeadFirstDesignPatterns {
namespace Command {
namespace Remote {//// This is the invoker//class RemoteControl { private: Command* onCommands[7]; private: Command* offCommands[7]; public: RemoteControl() { Command* noCommand = new NoCommand(); for (int i = 0; i < 7; i++) { onCommands[i] = noCommand; offCommands[i] = noCommand; } } public: virtual void setCommand(int slot, Command* onCommand, Command* offCommand) { onCommands[slot] = onCommand; offCommands[slot] = offCommand; } public: virtual void onButtonWasPushed(int slot) { onCommands[slot]->execute(); } public: virtual void offButtonWasPushed(int slot) { offCommands[slot]->execute(); } public: virtual std::string toString() { std::stringstream stringBuff; stringBuff << "\n------ Remote Control -------\n" << std::endl; for (int i = 0; i < 7; i++) { stringBuff << "[slot " << i << "] " << typeid(*onCommands[i]).name() << " " << typeid(*offCommands[i]).name() << std::endl; } return stringBuff.str(); }};} // namespace Remote
} // namespace Command
} // namespace HeadFirstDesignPatterns#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?