| [628577] | 1 | /*
|
|---|
| 2 | * ActionQueue.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Aug 16, 2013
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef ACTIONQUEUE_HPP_
|
|---|
| 9 | #define ACTIONQUEUE_HPP_
|
|---|
| 10 |
|
|---|
| 11 | // include config.h
|
|---|
| 12 | #ifdef HAVE_CONFIG_H
|
|---|
| 13 | #include <config.h>
|
|---|
| 14 | #endif
|
|---|
| 15 |
|
|---|
| 16 | #include "CodePatterns/Singleton.hpp"
|
|---|
| 17 |
|
|---|
| [690741] | 18 | #include <vector>
|
|---|
| [1d3563] | 19 |
|
|---|
| [f54cda] | 20 | #include "Actions/Action.hpp"
|
|---|
| [b5b01e] | 21 | #include "Actions/ActionState.hpp"
|
|---|
| [628577] | 22 |
|
|---|
| 23 | namespace MoleCuilder {
|
|---|
| 24 |
|
|---|
| [6367dd] | 25 | class ActionHistory;
|
|---|
| [ed3944] | 26 | class ActionRegistry;
|
|---|
| 27 | class ActionTrait;
|
|---|
| [628577] | 28 |
|
|---|
| 29 | /** This class combines the whole handling of Actions into a single class.
|
|---|
| 30 | *
|
|---|
| [1d3563] | 31 | * It spawns new Actions by its internal ActionRegistry. Spawned Actions are
|
|---|
| 32 | * automatically queued and placed into a History after execution.
|
|---|
| [628577] | 33 | */
|
|---|
| 34 | class ActionQueue : public Singleton<ActionQueue>
|
|---|
| 35 | {
|
|---|
| 36 | friend class Singleton<ActionQueue>;
|
|---|
| 37 | public:
|
|---|
| [690741] | 38 | typedef std::vector<std::string> ActionTokens_t;
|
|---|
| [af5384] | 39 | typedef std::vector< Action * > ActionQueue_t;
|
|---|
| [1d3563] | 40 |
|
|---|
| [05c989] | 41 | /** Queues the Action with \a name to be called.
|
|---|
| 42 | *
|
|---|
| [7fc447] | 43 | * \param name token of Action to actionqueue
|
|---|
| [f54cda] | 44 | * \param state whether Actions needs to be filled via a Dialog or not
|
|---|
| [05c989] | 45 | */
|
|---|
| [f54cda] | 46 | void queueAction(const std::string &name, enum Action::QueryOptions state = Action::Interactive);
|
|---|
| 47 |
|
|---|
| 48 | /** Queues the Action with \a name to be called.
|
|---|
| 49 | *
|
|---|
| 50 | * \param _action action to add
|
|---|
| 51 | * \param state whether Actions needs to be filled via a Dialog or not
|
|---|
| 52 | */
|
|---|
| 53 | void queueAction(Action *_action, enum Action::QueryOptions state = Action::Interactive);
|
|---|
| [05c989] | 54 |
|
|---|
| [1d3563] | 55 | /** Returns the spawned action by token \a name.
|
|---|
| 56 | *
|
|---|
| [7fc447] | 57 | * Action is checked into internal actionqueue.
|
|---|
| [1d3563] | 58 | *
|
|---|
| 59 | * \return pointer to newly spawned action
|
|---|
| 60 | */
|
|---|
| [a6ceab] | 61 | Action* getActionByName(const std::string &name);
|
|---|
| [1d3563] | 62 |
|
|---|
| 63 | /** Checks whether the Action is known by the given \a name.
|
|---|
| 64 | *
|
|---|
| 65 | * \param name token of action to check
|
|---|
| 66 | * \return true - token is known, false - else
|
|---|
| 67 | */
|
|---|
| [a6ceab] | 68 | bool isActionKnownByName(const std::string &name) const;
|
|---|
| [1d3563] | 69 |
|
|---|
| [126867] | 70 | /** Register an Action with the ActionRegistry.
|
|---|
| 71 | *
|
|---|
| 72 | * \param _action action to add
|
|---|
| 73 | */
|
|---|
| 74 | void registerAction(Action *_action);
|
|---|
| 75 |
|
|---|
| [690741] | 76 | /** Returns the vector with the tokens of all currently known Actions.
|
|---|
| 77 | *
|
|---|
| 78 | * \return list of all tokens
|
|---|
| 79 | */
|
|---|
| 80 | const ActionTokens_t getListOfActions() const;
|
|---|
| 81 |
|
|---|
| 82 | /** Returns the trait to an Action.
|
|---|
| 83 | *
|
|---|
| 84 | * \param name name of Action
|
|---|
| 85 | * \return const ref to its default Trait.
|
|---|
| 86 | */
|
|---|
| [a6ceab] | 87 | const ActionTrait& getActionsTrait(const std::string &name) const;
|
|---|
| [690741] | 88 |
|
|---|
| [7fc447] | 89 | /** Print the current contents of the actionqueue as CLI instantiated list of Actions.
|
|---|
| [46b181] | 90 | *
|
|---|
| 91 | * This is useful for storing the current session.
|
|---|
| 92 | *
|
|---|
| 93 | * \param output output stream to print to
|
|---|
| 94 | */
|
|---|
| 95 | void outputAsCLI(std::ostream &output) const;
|
|---|
| 96 |
|
|---|
| [7fc447] | 97 | /** Print the current contents of the actionqueue as Python instantiated list of Actions.
|
|---|
| [477012] | 98 | *
|
|---|
| 99 | * This is useful for storing the current session.
|
|---|
| 100 | *
|
|---|
| 101 | * \param output output stream to print to
|
|---|
| 102 | */
|
|---|
| 103 | void outputAsPython(std::ostream &output) const;
|
|---|
| 104 |
|
|---|
| [af5384] | 105 | /** Undoes last called Acfriend void ::cleanUp();tion.
|
|---|
| [6367dd] | 106 | *
|
|---|
| 107 | */
|
|---|
| 108 | void undoLast();
|
|---|
| 109 |
|
|---|
| 110 | /** Redoes last undone Action.
|
|---|
| 111 | *
|
|---|
| 112 | */
|
|---|
| 113 | void redoLast();
|
|---|
| 114 |
|
|---|
| [af5384] | 115 | /** Getter for the last executed action.
|
|---|
| 116 | *
|
|---|
| 117 | * \note this is necessary for Reactions to actually have a chance of getting
|
|---|
| 118 | * the calculated value as Action's are always cloned.
|
|---|
| 119 | *
|
|---|
| 120 | * \return const ref to last action
|
|---|
| 121 | */
|
|---|
| 122 | const Action &getLastAction() const {
|
|---|
| [7fc447] | 123 | return *(actionqueue.back());
|
|---|
| [af5384] | 124 | }
|
|---|
| 125 |
|
|---|
| [6367dd] | 126 | private:
|
|---|
| 127 | //!> grant Action access to internal history functions.
|
|---|
| 128 | friend class Action;
|
|---|
| 129 |
|
|---|
| 130 | /** Wrapper function to add state to ActionHistory.
|
|---|
| 131 | *
|
|---|
| 132 | * \param _Action Action whose state to add
|
|---|
| 133 | * \param _state state to add
|
|---|
| 134 | */
|
|---|
| 135 | void addElement(Action* _Action, ActionState::ptr _state);
|
|---|
| 136 |
|
|---|
| 137 | /** Wrapper function to clear ActionHistory.
|
|---|
| 138 | *
|
|---|
| 139 | */
|
|---|
| 140 | void clear();
|
|---|
| 141 |
|
|---|
| [628577] | 142 | private:
|
|---|
| [1d3563] | 143 | /** Private cstor for ActionQueue.
|
|---|
| 144 | *
|
|---|
| 145 | * Must be private as is singleton.
|
|---|
| 146 | *
|
|---|
| 147 | */
|
|---|
| [628577] | 148 | ActionQueue();
|
|---|
| [1d3563] | 149 |
|
|---|
| 150 | /** Dstor for ActionQueue.
|
|---|
| 151 | *
|
|---|
| 152 | */
|
|---|
| [628577] | 153 | ~ActionQueue();
|
|---|
| 154 |
|
|---|
| 155 | //!> ActionRegistry to spawn new actions
|
|---|
| [ed3944] | 156 | ActionRegistry *AR;
|
|---|
| [1d3563] | 157 |
|
|---|
| [6367dd] | 158 | //!> ActionHistory is for undoing and redoing actions, requires ActionRegistry fully initialized
|
|---|
| 159 | ActionHistory *history;
|
|---|
| 160 |
|
|---|
| [7fc447] | 161 | //!> internal actionqueue of actions
|
|---|
| 162 | ActionQueue_t actionqueue;
|
|---|
| [af5384] | 163 |
|
|---|
| [7fc447] | 164 | //!> point to current action in actionqueue
|
|---|
| [af5384] | 165 | size_t CurrentAction;
|
|---|
| [628577] | 166 | };
|
|---|
| 167 |
|
|---|
| 168 | };
|
|---|
| 169 |
|
|---|
| 170 | #endif /* ACTIONQUEUE_HPP_ */
|
|---|