/////////////////////////////////////////////////////////////// // Command.cpp - Command infrastructure // // ver 1.0 // // Language: Visual C++, VS 2008, SP1 // // Platform: Dell Precision T7400, Vista Ultimate, SP1 // // Application: CSE775 Project #1, Spring 2009 // // Author: Jim Fawcett, Syracuse University CST 4-187 // // (315) 443-3948, jfawcett@twcny.rr.com // /////////////////////////////////////////////////////////////// #include "Command.h" //----< call each ICommand::execute on commands vector >------- void Invoker::invoke(const std::wstring& msg) { std::vector::iterator iter; for(iter=commands.begin(); iter!=commands.end(); ++iter) (*iter)->execute(msg); } //----< add an ICommand derived instance to commands >--------- void Invoker::addCommand(ICommand* pCommand) { commands.push_back(pCommand); } //----< test stub >-------------------------------------------- #ifdef TEST_COMMAND #include class myCommand : public ICommand { public: void execute(const std::wstring& msg) { std::wcout << L"\n Invoking Command with message: \"" << msg.c_str() << L"\""; } }; void main() { std::cout << "\n Testing Command Facility"; std::cout << "\n ==========================\n"; myCommand mc; Invoker invoker; invoker.addCommand(&mc); invoker.invoke(L"hi from test client"); std::cout << "\n\n"; } #endif