]> git.stg.codes - stg.git/blob - projects/stargazer/actions.inl.h
Correction method GetPropertyValue
[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     : mutex()
19 {
20 pthread_mutex_init(&mutex, NULL);
21 }
22
23 // Delete all actions before deleting list
24 inline
25 ACTIONS_LIST::~ACTIONS_LIST()
26 {
27
28     {
29     STG_LOCKER lock(&mutex, __FILE__, __LINE__);
30
31     parent::iterator it(parent::begin());
32     while (it != parent::end()) 
33         {
34         delete *it++;
35         }
36     }
37
38 pthread_mutex_destroy(&mutex);
39 }
40
41 inline
42 ACTIONS_LIST::parent::iterator ACTIONS_LIST::begin()
43
44 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
45 return parent::begin();
46 }
47
48 inline
49 ACTIONS_LIST::parent::iterator ACTIONS_LIST::end()
50
51 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
52 return parent::end();
53 }
54
55 inline
56 ACTIONS_LIST::parent::const_iterator ACTIONS_LIST::begin() const
57
58 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
59 return parent::begin();
60 }
61
62 inline
63 ACTIONS_LIST::parent::const_iterator ACTIONS_LIST::end() const
64
65 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
66 return parent::end();
67 }
68
69 inline
70 bool ACTIONS_LIST::empty() const
71 {
72 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
73 return parent::empty();
74 }
75
76 inline
77 size_t ACTIONS_LIST::size() const
78 {
79 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
80 return parent::size();
81 }
82
83 inline
84 void ACTIONS_LIST::swap(ACTIONS_LIST & list)
85 {
86 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
87 parent::swap(list);
88 }
89
90 template <class ACTIVE_CLASS, typename DATA_TYPE>
91 inline
92 void ACTIONS_LIST::Enqueue(ACTIVE_CLASS & ac,
93                            typename ACTOR<ACTIVE_CLASS, DATA_TYPE>::TYPE a,
94                            DATA_TYPE d)
95 {
96 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
97 push_back(new ACTION<ACTIVE_CLASS, DATA_TYPE>(ac, a, d));
98 }
99
100 inline
101 void ACTIONS_LIST::InvokeAll()
102 {
103 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
104 std::for_each(
105         parent::begin(),
106         parent::end(),
107         std::mem_fun(&BASE_ACTION::Invoke)
108 );
109 }
110
111 #endif