6 // ACTIONS_LIST actionsList;
11 // actionsList.Enqueue(myClass, &CLASS::myMethod1, myData1);
12 // actionsList.Enqueue(myClass, &CLASS::myMethod2, myData2);
14 // actionsList.InvokeAll();
20 // Generalized actor type - a method of some class with one argument
21 template <class ACTIVE_CLASS, typename DATA_TYPE>
24 typedef void (ACTIVE_CLASS::*TYPE)(DATA_TYPE);
27 // Abstract base action class for polymorphic action invocation
31 virtual ~BASE_ACTION() {}
32 virtual void Invoke() = 0;
35 // Concrete generalized action type - an actor with it's data and owner
36 template <class ACTIVE_CLASS, typename DATA_TYPE>
37 class ACTION : public BASE_ACTION,
38 public std::unary_function<ACTIVE_CLASS &, void>
41 ACTION(ACTIVE_CLASS & ac,
42 typename ACTOR<ACTIVE_CLASS, DATA_TYPE>::TYPE a,
44 : activeClass(ac), actor(a), data(d) {}
45 void Invoke() override;
47 ACTION(const ACTION<ACTIVE_CLASS, DATA_TYPE> & rvalue);
48 ACTION<ACTIVE_CLASS, DATA_TYPE> & operator=(const ACTION<ACTIVE_CLASS, DATA_TYPE> & rvalue);
50 ACTIVE_CLASS & activeClass;
51 typename ACTOR<ACTIVE_CLASS, DATA_TYPE>::TYPE actor;
55 // A list of an actions
56 // All methods are thread-safe
57 class ACTIONS_LIST : private std::vector<BASE_ACTION *>
60 // Just a typedef for parent class
61 typedef std::vector<BASE_ACTION *> parent;
65 // Delete actions and destroy mutex
66 virtual ~ACTIONS_LIST();
68 parent::iterator begin();
69 parent::iterator end();
70 parent::const_iterator begin() const;
71 parent::const_iterator end() const;
75 void swap(ACTIONS_LIST & list);
77 // Add an action to list
78 template <class ACTIVE_CLASS, typename DATA_TYPE>
79 void Enqueue(ACTIVE_CLASS & ac,
80 typename ACTOR<ACTIVE_CLASS, DATA_TYPE>::TYPE a,
82 // Invoke all actions in the list
85 mutable std::mutex m_mutex;
88 #include "actions.inl.h"