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