| 1 | /* | 
|---|
| 2 | * ControllerCommand.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: 01.06.2012 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef CONTROLLERCOMMAND_HPP_ | 
|---|
| 9 | #define CONTROLLERCOMMAND_HPP_ | 
|---|
| 10 |  | 
|---|
| 11 | // include config.h | 
|---|
| 12 | #ifdef HAVE_CONFIG_H | 
|---|
| 13 | #include <config.h> | 
|---|
| 14 | #endif | 
|---|
| 15 |  | 
|---|
| 16 | #include <boost/function.hpp> | 
|---|
| 17 | #include <deque> | 
|---|
| 18 | #include <string> | 
|---|
| 19 |  | 
|---|
| 20 | /** ControllerCommand associates a single name with a certain deque of | 
|---|
| 21 | *  (conntroller) commands. | 
|---|
| 22 | * | 
|---|
| 23 | * The ControllerCommand can be used as follows: | 
|---|
| 24 | * \code | 
|---|
| 25 | * ControllerCommand command; | 
|---|
| 26 | * for (ControllerCommand::const_iterator iter = command.begin(); | 
|---|
| 27 | *    iter != command.end(); ++iter) { | 
|---|
| 28 | *    ... | 
|---|
| 29 | *    // execute current command | 
|---|
| 30 | *    (*iter)(); | 
|---|
| 31 | *    ... | 
|---|
| 32 | * } | 
|---|
| 33 | * \endcode | 
|---|
| 34 | * | 
|---|
| 35 | */ | 
|---|
| 36 | struct ControllerCommand | 
|---|
| 37 | { | 
|---|
| 38 | public: | 
|---|
| 39 | //!> commands are simply bound functions | 
|---|
| 40 | typedef boost::function<void ()> commands_t; | 
|---|
| 41 | //!> typedef for deque with commands_t to execute | 
|---|
| 42 | typedef std::deque<commands_t> queue_t; | 
|---|
| 43 | //!> convenience constant iterator to queue_t | 
|---|
| 44 | typedef std::deque<commands_t>::const_iterator const_iterator; | 
|---|
| 45 |  | 
|---|
| 46 | /** Constructor of class ControllerCommand. | 
|---|
| 47 | * | 
|---|
| 48 | * \param _name name of this command | 
|---|
| 49 | * \param _commands command queue to associated with this command | 
|---|
| 50 | */ | 
|---|
| 51 | ControllerCommand(const std::string &_name, const queue_t &_commands) : | 
|---|
| 52 | name(_name), | 
|---|
| 53 | commands(_commands) | 
|---|
| 54 | {} | 
|---|
| 55 | /** Destructor of class ControllerCommand. | 
|---|
| 56 | * | 
|---|
| 57 | */ | 
|---|
| 58 | ControllerCommand() | 
|---|
| 59 | {} | 
|---|
| 60 |  | 
|---|
| 61 | /** Getter for begin of deque. | 
|---|
| 62 | * | 
|---|
| 63 | * \return iterator pointing at first command | 
|---|
| 64 | */ | 
|---|
| 65 | const_iterator begin() const | 
|---|
| 66 | { return commands.begin(); } | 
|---|
| 67 |  | 
|---|
| 68 | /** Getter for one after end of command deque. | 
|---|
| 69 | * | 
|---|
| 70 | * \return iterator at one position after last command | 
|---|
| 71 | */ | 
|---|
| 72 | const_iterator end() const | 
|---|
| 73 | { return commands.end(); } | 
|---|
| 74 |  | 
|---|
| 75 | /** Getter for internal name of this ControllerCommand. | 
|---|
| 76 | * | 
|---|
| 77 | * \note this is required for Repository pattern. | 
|---|
| 78 | * | 
|---|
| 79 | * \return name of this ControllerCommand | 
|---|
| 80 | */ | 
|---|
| 81 | const std::string &getName() const | 
|---|
| 82 | { return name; } | 
|---|
| 83 |  | 
|---|
| 84 | private: | 
|---|
| 85 | //!> name of this ControllerCommand | 
|---|
| 86 | const std::string name; | 
|---|
| 87 | //!> commands to execute | 
|---|
| 88 | const queue_t commands; | 
|---|
| 89 | }; | 
|---|
| 90 |  | 
|---|
| 91 | #endif /* CONTROLLERCOMMAND_HPP_ */ | 
|---|