⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 remotecontrolwithundo.hpp

📁 深入浅出设计模式(书配套c++源代码)。包含20个设计模式的c++实现。
💻 HPP
字号:
#ifndef	_HFDP_CPP_COMMAND_REMOTE_CONTROL_WITH_UNDO_HPP_#define _HFDP_CPP_COMMAND_REMOTE_CONTROL_WITH_UNDO_HPP_#include "Undo.hpp"namespace HeadFirstDesignPatterns {namespace Command {namespace Undo {//// This is the invoker//class RemoteControlWithUndo {	private: static const int SLOTS = 7;	private: Command* _onCommands[SLOTS];	private: Command* _offCommands[SLOTS];	private: Command* _noCommand;	private: mutable Command* _undoCommand;	public: RemoteControlWithUndo() {		_noCommand = new NoCommand();		for( int i = 0; i < SLOTS; i++ ) {			_onCommands[i] = _noCommand;			_offCommands[i] = _noCommand;		}		_undoCommand = _noCommand;	}	public: ~RemoteControlWithUndo() {		delete _noCommand;	}	public: void setCommand( int slot, Command* onCommand, Command* offCommand ) { assert( slot <= SLOTS ); assert( onCommand ); assert( offCommand );		_onCommands[slot]  = onCommand;		_offCommands[slot] = offCommand;	}	public: void onButtonWasPushed( int slot ) const { assert( slot <= SLOTS );		_onCommands[slot]->execute();		_undoCommand = _onCommands[slot];	}	public: void offButtonWasPushed( int slot ) const { assert( slot <= SLOTS );		_offCommands[slot]->execute();		_undoCommand = _offCommands[slot];	}	public: void undoButtonWasPushed() const {		_undoCommand->undo();	}	public: std::string toString() const {		std::stringstream value;		value << std::endl << "------ Remote Control -------" << std::endl;		for( int i = 0; i < SLOTS; i++ ) {			value << "[slot " << i << "] ";			value << typeid( *_onCommands[i] ).name();			value << "    ";			value << typeid( *_offCommands[i] ).name();			value << std::endl;		}		value << "[undo] " << typeid( *_undoCommand ).name() << std::endl;		return value.str();	}};} // namespace Undo} // namespace Command} // namespace HeadFirstDesignPatterns#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -