]> git.stg.codes - stg.git/blob - projects/stargazer/actions.inl.h
7a0bac35158ecee058712a490628753ae0ed0c48
[stg.git] / projects / stargazer / actions.inl.h
1 #ifndef __ACTIONS_INL_H__
2 #define __ACTIONS_INL_H__
3
4 #include <algorithm>
5
6 #include "stg/locker.h"
7
8 // Polymorphick action invocation
9 template <class ACTIVE_CLASS, typename DATA_TYPE>
10 inline
11 void ACTION<ACTIVE_CLASS, DATA_TYPE>::Invoke()
12 {
13 (activeClass.*actor)(data);
14 }
15
16 inline
17 ACTIONS_LIST::ACTIONS_LIST()
18 {
19 }
20
21 // Delete all actions before deleting list
22 inline
23 ACTIONS_LIST::~ACTIONS_LIST()
24 {
25 std::lock_guard lock(m_mutex);
26
27 parent::iterator it(parent::begin());
28 while (it != parent::end())
29     delete *it++;
30 }
31
32 inline
33 ACTIONS_LIST::parent::iterator ACTIONS_LIST::begin()
34 {
35 std::lock_guard lock(m_mutex);
36 return parent::begin();
37 }
38
39 inline
40 ACTIONS_LIST::parent::iterator ACTIONS_LIST::end()
41 {
42 std::lock_guard lock(m_mutex);
43 return parent::end();
44 }
45
46 inline
47 ACTIONS_LIST::parent::const_iterator ACTIONS_LIST::begin() const
48 {
49 std::lock_guard lock(m_mutex);
50 return parent::begin();
51 }
52
53 inline
54 ACTIONS_LIST::parent::const_iterator ACTIONS_LIST::end() const
55 {
56 std::lock_guard lock(m_mutex);
57 return parent::end();
58 }
59
60 inline
61 bool ACTIONS_LIST::empty() const
62 {
63 std::lock_guard lock(m_mutex);
64 return parent::empty();
65 }
66
67 inline
68 size_t ACTIONS_LIST::size() const
69 {
70 std::lock_guard lock(m_mutex);
71 return parent::size();
72 }
73
74 inline
75 void ACTIONS_LIST::swap(ACTIONS_LIST & list)
76 {
77 std::lock_guard lock(m_mutex);
78 parent::swap(list);
79 }
80
81 template <class ACTIVE_CLASS, typename DATA_TYPE>
82 inline
83 void ACTIONS_LIST::Enqueue(ACTIVE_CLASS & ac,
84                            typename ACTOR<ACTIVE_CLASS, DATA_TYPE>::TYPE a,
85                            DATA_TYPE d)
86 {
87 std::lock_guard lock(m_mutex);
88 push_back(new ACTION<ACTIVE_CLASS, DATA_TYPE>(ac, a, d));
89 }
90
91 inline
92 void ACTIONS_LIST::InvokeAll()
93 {
94 std::lock_guard lock(m_mutex);
95 std::for_each(
96         parent::begin(),
97         parent::end(),
98         [](auto action){ action->Invoke(); });
99 }
100
101 #endif