File src/batch.h changed (mode: 100644) (index aebf5d5..93bc372) |
... |
... |
namespace om636 |
46 |
46 |
template<typename V, typename W> |
template<typename V, typename W> |
47 |
47 |
void traverse_destructive( V, W ); |
void traverse_destructive( V, W ); |
48 |
48 |
|
|
49 |
|
static void process_and_kill( const batch_type & ); |
|
|
49 |
|
static void process_and_kill( batch_type ); |
50 |
50 |
|
|
51 |
51 |
template<typename V> |
template<typename V> |
52 |
|
static void process_and_kill( const batch_type &, V ); |
|
|
52 |
|
static void process_and_kill( batch_type, V ); |
53 |
53 |
|
|
54 |
54 |
template<typename V, typename W> |
template<typename V, typename W> |
55 |
|
static void process_and_kill( const batch_type &, V, W ); |
|
|
55 |
|
static void process_and_kill( batch_type, V, W ); |
56 |
56 |
|
|
57 |
|
static batch_type process( const batch_type & ); |
|
|
57 |
|
static batch_type process( batch_type ); |
58 |
58 |
|
|
59 |
59 |
template<typename V> |
template<typename V> |
60 |
|
static batch_type process( const batch_type &, V ); |
|
|
60 |
|
static batch_type process( batch_type, V ); |
61 |
61 |
|
|
62 |
62 |
template<typename V, typename W> |
template<typename V, typename W> |
63 |
|
static batch_type process( const batch_type &, V, W ); |
|
|
63 |
|
static batch_type process( batch_type, V, W ); |
64 |
64 |
|
|
65 |
65 |
static void kill_all(batch_type &); |
static void kill_all(batch_type &); |
66 |
66 |
|
|
|
... |
... |
namespace om636 |
68 |
68 |
const batch_type & elements() const; |
const batch_type & elements() const; |
69 |
69 |
|
|
70 |
70 |
private: |
private: |
|
71 |
|
|
|
72 |
|
void merge_new_elements(); |
|
73 |
|
|
71 |
74 |
batch_type m_elements; |
batch_type m_elements; |
|
75 |
|
batch_type m_elements_add; |
72 |
76 |
}; |
}; |
73 |
77 |
} //control |
} //control |
74 |
78 |
} // om636 |
} // om636 |
File src/batch.hxx changed (mode: 100644) (index 9929d20..0d4b7bd) |
... |
... |
namespace om636 |
7 |
7 |
auto Batch<T>::hook( callback_type c ) -> listener_type |
auto Batch<T>::hook( callback_type c ) -> listener_type |
8 |
8 |
{ |
{ |
9 |
9 |
pointer_type agent( new agent_type( c ) ); |
pointer_type agent( new agent_type( c ) ); |
10 |
|
elements().insert( agent ); |
|
|
10 |
|
m_elements_add.insert( agent ); |
11 |
11 |
return listener_type( agent ); |
return listener_type( agent ); |
12 |
12 |
} |
} |
13 |
13 |
|
|
|
... |
... |
namespace om636 |
16 |
16 |
void Batch<T>::unhook() |
void Batch<T>::unhook() |
17 |
17 |
{ |
{ |
18 |
18 |
kill_all( elements() ); |
kill_all( elements() ); |
|
19 |
|
kill_all( m_elements_add ); |
19 |
20 |
} |
} |
20 |
21 |
|
|
21 |
22 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
22 |
23 |
template<typename T> |
template<typename T> |
23 |
24 |
void Batch<T>::traverse() |
void Batch<T>::traverse() |
24 |
25 |
{ |
{ |
25 |
|
batch_type copy; |
|
26 |
|
copy.swap( elements() ); |
|
27 |
|
elements() = process( copy ); |
|
|
26 |
|
merge_new_elements(); |
|
27 |
|
|
|
28 |
|
const batch_type & sub( process( elements() ) ); |
|
29 |
|
elements().erase( sub.begin(), sub.end() ); |
28 |
30 |
} |
} |
29 |
31 |
|
|
30 |
32 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
|
... |
... |
namespace om636 |
32 |
34 |
template<class V> |
template<class V> |
33 |
35 |
void Batch<T>::traverse(V arg) |
void Batch<T>::traverse(V arg) |
34 |
36 |
{ |
{ |
35 |
|
batch_type copy; |
|
36 |
|
copy.swap( elements() ); |
|
37 |
|
elements() = process( copy, arg ); |
|
|
37 |
|
merge_new_elements(); |
|
38 |
|
|
|
39 |
|
const batch_type & sub( process( elements(), arg ) ); |
|
40 |
|
elements().erase( sub.begin(), sub.end() ); |
38 |
41 |
} |
} |
39 |
42 |
|
|
40 |
43 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
|
... |
... |
namespace om636 |
42 |
45 |
template<typename V, typename W> |
template<typename V, typename W> |
43 |
46 |
void Batch<T>::traverse(V first_arg, W second_arg ) |
void Batch<T>::traverse(V first_arg, W second_arg ) |
44 |
47 |
{ |
{ |
45 |
|
batch_type copy; |
|
46 |
|
copy.swap( elements() ); |
|
47 |
|
elements() = process( copy, first_arg, second_arg ); |
|
|
48 |
|
merge_new_elements(); |
|
49 |
|
|
|
50 |
|
const batch_type & sub( process( elements(), first_arg, second_arg ) ); |
|
51 |
|
elements().erase( sub.begin(), sub.end() ); |
48 |
52 |
} |
} |
49 |
53 |
|
|
50 |
54 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
51 |
55 |
template<typename T> |
template<typename T> |
52 |
56 |
void Batch<T>::traverse_destructive() |
void Batch<T>::traverse_destructive() |
53 |
57 |
{ |
{ |
54 |
|
batch_type copy; |
|
55 |
|
copy.swap( elements() ); |
|
56 |
|
process_and_kill( copy ); |
|
|
58 |
|
process_and_kill( elements() ); |
57 |
59 |
} |
} |
58 |
60 |
|
|
59 |
61 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
|
... |
... |
namespace om636 |
61 |
63 |
template<class V> |
template<class V> |
62 |
64 |
void Batch<T>::traverse_destructive(V arg) |
void Batch<T>::traverse_destructive(V arg) |
63 |
65 |
{ |
{ |
64 |
|
batch_type copy; |
|
65 |
|
copy.swap( elements() ); |
|
66 |
|
process_and_kill( copy, arg ); |
|
|
66 |
|
process_and_kill( elements(), arg ); |
67 |
67 |
} |
} |
68 |
68 |
|
|
69 |
69 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
|
... |
... |
namespace om636 |
71 |
71 |
template<typename V, typename W> |
template<typename V, typename W> |
72 |
72 |
void Batch<T>::traverse_destructive(V first_arg, W second_arg ) |
void Batch<T>::traverse_destructive(V first_arg, W second_arg ) |
73 |
73 |
{ |
{ |
74 |
|
batch_type copy; |
|
75 |
|
copy.swap( elements() ); |
|
76 |
|
process_and_kill( copy, first_arg, second_arg ); |
|
|
74 |
|
process_and_kill( elements(), first_arg, second_arg ); |
77 |
75 |
} |
} |
78 |
76 |
|
|
79 |
77 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
80 |
78 |
template<typename T> |
template<typename T> |
81 |
|
auto Batch<T>::process( const batch_type & batch ) -> batch_type |
|
|
79 |
|
auto Batch<T>::process( batch_type batch ) -> batch_type |
82 |
80 |
{ |
{ |
83 |
81 |
batch_type result; |
batch_type result; |
84 |
82 |
for_each( batch.begin(), batch.end(), [&](pointer_type p) { |
for_each( batch.begin(), batch.end(), [&](pointer_type p) { |
85 |
83 |
if (!p->is_dead()) |
if (!p->is_dead()) |
86 |
|
{ |
|
87 |
84 |
p->invoke(); |
p->invoke(); |
|
85 |
|
else |
88 |
86 |
result.insert(p); |
result.insert(p); |
89 |
|
} |
|
90 |
87 |
} ); |
} ); |
91 |
88 |
return result; |
return result; |
92 |
89 |
} |
} |
|
... |
... |
namespace om636 |
94 |
91 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
95 |
92 |
template<typename T> |
template<typename T> |
96 |
93 |
template<typename V> |
template<typename V> |
97 |
|
auto Batch<T>::process( const batch_type & batch, V v ) -> batch_type |
|
|
94 |
|
auto Batch<T>::process( batch_type batch, V v ) -> batch_type |
98 |
95 |
{ |
{ |
99 |
96 |
batch_type result; |
batch_type result; |
100 |
97 |
for_each( batch.begin(), batch.end(), [&](pointer_type p) { |
for_each( batch.begin(), batch.end(), [&](pointer_type p) { |
101 |
98 |
if (!p->is_dead()) |
if (!p->is_dead()) |
102 |
|
{ |
|
103 |
99 |
p->invoke(v); |
p->invoke(v); |
|
100 |
|
else |
104 |
101 |
result.insert(p); |
result.insert(p); |
105 |
|
} |
|
106 |
102 |
} ); |
} ); |
107 |
103 |
return result; |
return result; |
108 |
104 |
} |
} |
|
... |
... |
namespace om636 |
110 |
106 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
111 |
107 |
template<typename T> |
template<typename T> |
112 |
108 |
template<typename V, typename W> |
template<typename V, typename W> |
113 |
|
auto Batch<T>::process( const batch_type & batch, V v, W w ) -> batch_type |
|
|
109 |
|
auto Batch<T>::process( batch_type batch, V v, W w ) -> batch_type |
114 |
110 |
{ |
{ |
115 |
111 |
batch_type result; |
batch_type result; |
116 |
112 |
for_each( batch.begin(), batch.end(), [&](pointer_type p) { |
for_each( batch.begin(), batch.end(), [&](pointer_type p) { |
117 |
113 |
if (!p->is_dead()) |
if (!p->is_dead()) |
118 |
|
{ |
|
119 |
114 |
p->invoke(v, w); |
p->invoke(v, w); |
|
115 |
|
else |
120 |
116 |
result.insert(p); |
result.insert(p); |
121 |
|
} |
|
122 |
117 |
} ); |
} ); |
123 |
118 |
return result; |
return result; |
124 |
119 |
} |
} |
125 |
120 |
|
|
126 |
121 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
127 |
122 |
template<typename T> |
template<typename T> |
128 |
|
void Batch<T>::process_and_kill( const batch_type & batch ) |
|
|
123 |
|
void Batch<T>::process_and_kill( batch_type batch ) |
129 |
124 |
{ |
{ |
130 |
125 |
for_each( batch.begin(), batch.end(), [](pointer_type p) { |
for_each( batch.begin(), batch.end(), [](pointer_type p) { |
131 |
126 |
if (!p->is_dead()) |
if (!p->is_dead()) |
|
... |
... |
namespace om636 |
136 |
131 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
137 |
132 |
template<typename T> |
template<typename T> |
138 |
133 |
template<typename V> |
template<typename V> |
139 |
|
void Batch<T>::process_and_kill( const batch_type & batch, V v ) |
|
|
134 |
|
void Batch<T>::process_and_kill( batch_type batch, V v ) |
140 |
135 |
{ |
{ |
141 |
136 |
for_each( batch.begin(), batch.end(), [&](pointer_type p) { |
for_each( batch.begin(), batch.end(), [&](pointer_type p) { |
142 |
137 |
if (!p->is_dead()) |
if (!p->is_dead()) |
|
... |
... |
namespace om636 |
147 |
142 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
148 |
143 |
template<typename T> |
template<typename T> |
149 |
144 |
template<typename V, typename W> |
template<typename V, typename W> |
150 |
|
void Batch<T>::process_and_kill( const batch_type & batch, V v, W w ) |
|
|
145 |
|
void Batch<T>::process_and_kill( batch_type batch, V v, W w ) |
151 |
146 |
{ |
{ |
152 |
147 |
for_each( batch.begin(), batch.end(), [&](pointer_type p) { |
for_each( batch.begin(), batch.end(), [&](pointer_type p) { |
153 |
148 |
if (!p->is_dead()) |
if (!p->is_dead()) |
|
... |
... |
namespace om636 |
178 |
173 |
} ); |
} ); |
179 |
174 |
batch.clear(); |
batch.clear(); |
180 |
175 |
} |
} |
|
176 |
|
|
|
177 |
|
///////////////////////////////////////////////////////////////////////////////////// |
|
178 |
|
template<typename T> |
|
179 |
|
void Batch<T>::merge_new_elements() |
|
180 |
|
{ |
|
181 |
|
elements().insert(m_elements_add.begin(), m_elements_add.end() ); |
|
182 |
|
m_elements_add.clear(); |
|
183 |
|
} |
181 |
184 |
|
|
182 |
185 |
} // control |
} // control |
183 |
186 |
} // om636 |
} // om636 |