Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/ActionQueue.hpp

    r11d433 r601ef8  
    1616#include "CodePatterns/Singleton.hpp"
    1717
     18#include "CodePatterns/Observer/Channels.hpp"
     19#include "CodePatterns/Observer/Observable.hpp"
    1820
    1921#ifdef HAVE_ACTION_THREAD
     
    3840class ActionRegistry;
    3941class ActionTrait;
     42
     43namespace Queuedetail {
     44  template <class T> const T* lastChanged()
     45  {
     46    ASSERT(0, "Queuedetail::lastChanged() - only specializations may be used.");
     47    return NULL;
     48  }
     49}
    4050
    4151/** This class combines the whole handling of Actions into a single class.
     
    4454 * automatically queued and placed into a History after execution.
    4555 */
    46 class ActionQueue : public Singleton<ActionQueue>
     56class ActionQueue : public Singleton<ActionQueue>, public Observable
    4757{
    4858  friend class Singleton<ActionQueue>;
     
    5161  typedef std::vector< Action * > ActionQueue_t;
    5262
     63  //!> channels for this observable
     64  enum NotificationType {
     65    ActionQueued,  // new action was queued
     66    NotificationType_MAX  // denotes the maximum of available notification types
     67  };
     68
     69  //>! access to last changed element (atom or molecule)
     70  template <class T> const T* lastChanged() const
     71  { return Queuedetail::lastChanged<T>(); }
     72
    5373  /** Queues the Action with \a name to be called.
    5474   *
     
    124144   */
    125145  void redoLast();
     146
     147  /** Checks whether there is one completed Action stored in ActionHistory in the past.
     148   *
     149   * @return true - at least one Action to undo present, false - else
     150   */
     151  bool canUndo() const;
     152
     153  /** Checks whether there is one completed Action stored in ActionHistory in the future.
     154   *
     155   * @return true - at least one Action to redo present, false - else
     156   */
     157  bool canRedo() const;
    126158
    127159  /** Return status of last executed action.
     
    170202  void clear();
    171203
    172   /** Clears all actions currently present in the actionqueues.
    173    *
    174    */
    175   void clearQueue();
    176 
    177 #ifdef HAVE_ACTION_THREAD
     204  /** Clears all actions present in the actionqueues from \a _fromAction.
     205   *
     206   * @param _fromAction 0 if all Actions to clear or else
     207   */
     208  void clearQueue(const size_t _fromAction = 0);
     209
     210#ifdef HAVE_ACTION_THREAD
     211
     212  /** Clears the temporary queue.
     213   *
     214   */
     215  void clearTempQueue();
     216
     217  /** Sets the run_thread_isIdle flag.
     218   *
     219   * @param _flag state to set to
     220   */
     221  void setRunThreadIdle(const bool _flag);
     222
    178223  /** Runs the ActionQueue.
    179224   *
     
    194239   */
    195240  void wait();
     241
     242  /** Moves all action from tempqueue into real queue.
     243   *
     244   */
     245  void insertTempQueue();
     246
    196247#endif
    197248
     
    204255  void insertAction(Action *_action, enum Action::QueryOptions state);
    205256
    206   /** Moves all action from tempqueue into real queue.
    207    *
    208    */
    209   void insertTempQueue();
    210 
    211257private:
    212258  /** Private cstor for ActionQueue.
     
    222268  ~ActionQueue();
    223269
     270private:
     271  friend const Action *Queuedetail::lastChanged<Action>();
     272  static const Action *_lastchangedaction;
     273
    224274  //!> ActionRegistry to spawn new actions
    225275  ActionRegistry *AR;
     
    231281  ActionQueue_t actionqueue;
    232282
     283  //!> indicates that the last action has failed
     284  bool lastActionOk;
     285
     286#ifdef HAVE_ACTION_THREAD
    233287  //!> point to current action in actionqueue
    234288  size_t CurrentAction;
     
    237291  ActionQueue_t tempqueue;
    238292
    239   //!> indicates that the last action has failed
    240   bool lastActionOk;
    241 
    242 #ifdef HAVE_ACTION_THREAD
    243293  //!> internal thread to call Actions
    244294  boost::thread run_thread;
     
    260310  ActionStatusList StatusList;
    261311};
     312namespace Queuedetail {
     313  template <>       inline  const Action* lastChanged<Action>() { return ActionQueue::_lastchangedaction; }
     314}
    262315
    263316};
Note: See TracChangeset for help on using the changeset viewer.