1 | /*
|
---|
2 | * molecule_template.hpp
|
---|
3 | *
|
---|
4 | * Created on: Oct 6, 2009
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef MOLECULE_TEMPLATE_HPP_
|
---|
9 | #define MOLECULE_TEMPLATE_HPP_
|
---|
10 |
|
---|
11 | /*********************************************** includes ***********************************/
|
---|
12 |
|
---|
13 | // include config.h
|
---|
14 | #ifdef HAVE_CONFIG_H
|
---|
15 | #include <config.h>
|
---|
16 | #endif
|
---|
17 |
|
---|
18 | #include "atom.hpp"
|
---|
19 | /********************************************** declarations *******************************/
|
---|
20 |
|
---|
21 |
|
---|
22 | // ========================= Summing over each Atoms =================================== //
|
---|
23 |
|
---|
24 | // zero arguments
|
---|
25 | template <typename res, typename typ> res molecule::SumPerAtom(res (typ::*f)() ) const
|
---|
26 | {
|
---|
27 | res result = 0;
|
---|
28 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
29 | result += ((*iter)->*f)();
|
---|
30 | }
|
---|
31 | return result;
|
---|
32 | };
|
---|
33 | template <typename res, typename typ> res molecule::SumPerAtom(res (typ::*f)() const ) const
|
---|
34 | {
|
---|
35 | res result = 0;
|
---|
36 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
37 | result += ((*iter)->*f)();
|
---|
38 | }
|
---|
39 | return result;
|
---|
40 | };
|
---|
41 | // one argument
|
---|
42 | template <typename res, typename typ, typename T> res molecule::SumPerAtom(res (typ::*f)(T), T t ) const
|
---|
43 | {
|
---|
44 | res result = 0;
|
---|
45 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
46 | result += ((*iter)->*f)(t);
|
---|
47 | }
|
---|
48 | return result;
|
---|
49 | };
|
---|
50 | template <typename res, typename typ, typename T> res molecule::SumPerAtom(res (typ::*f)(T) const, T t ) const
|
---|
51 | {
|
---|
52 | res result = 0;
|
---|
53 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
54 | result += ((*iter)->*f)(t);
|
---|
55 | }
|
---|
56 | return result;
|
---|
57 | };
|
---|
58 |
|
---|
59 |
|
---|
60 | // ================== Acting with each Atoms on same molecule ========================== //
|
---|
61 |
|
---|
62 | // zero arguments
|
---|
63 | template <typename res> void molecule::ActWithEachAtom( res (molecule::*f)(atom *)) const
|
---|
64 | {
|
---|
65 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
66 | (*f)((*iter));
|
---|
67 | }
|
---|
68 | };
|
---|
69 | template <typename res> void molecule::ActWithEachAtom( res (molecule::*f)(atom *) const) const
|
---|
70 | {
|
---|
71 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
72 | (*f)((*iter));
|
---|
73 | }
|
---|
74 | };
|
---|
75 |
|
---|
76 | // ================== Acting with each Atoms on copy molecule ========================== //
|
---|
77 |
|
---|
78 | // zero arguments
|
---|
79 | template <typename res> void molecule::ActOnCopyWithEachAtom( res (molecule::*f)(atom *) , molecule *copy) const
|
---|
80 | {
|
---|
81 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
82 | (copy->*f)((*iter));
|
---|
83 | }
|
---|
84 | };
|
---|
85 | template <typename res> void molecule::ActOnCopyWithEachAtom( res (molecule::*f)(atom *) const, molecule *copy) const
|
---|
86 | {
|
---|
87 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
88 | (copy->*f)((*iter));
|
---|
89 | }
|
---|
90 | };
|
---|
91 |
|
---|
92 | // ================== Acting with each Atoms on copy molecule if true ========================== //
|
---|
93 |
|
---|
94 | // zero arguments
|
---|
95 | template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () ) const
|
---|
96 | {
|
---|
97 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
98 | if (((*iter)->*condition)())
|
---|
99 | (copy->*f)((*iter));
|
---|
100 | }
|
---|
101 | };
|
---|
102 | template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () const ) const
|
---|
103 | {
|
---|
104 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
105 | if (((*iter)->*condition)())
|
---|
106 | (copy->*f)((*iter));
|
---|
107 | }
|
---|
108 | };
|
---|
109 | template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const , molecule *copy, bool (atom::*condition) () ) const
|
---|
110 | {
|
---|
111 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
112 | if (((*iter)->*condition)())
|
---|
113 | (copy->*f)((*iter));
|
---|
114 | }
|
---|
115 | };
|
---|
116 | template <typename res> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) () const ) const
|
---|
117 | {
|
---|
118 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
119 | if (((*iter)->*condition)())
|
---|
120 | (copy->*f)((*iter));
|
---|
121 | }
|
---|
122 | };
|
---|
123 | // one argument
|
---|
124 | template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T), T t ) const
|
---|
125 | {
|
---|
126 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
127 | if (((*iter)->*condition)(t))
|
---|
128 | (copy->*f)((*iter));
|
---|
129 | }
|
---|
130 | };
|
---|
131 | template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T) const, T t ) const
|
---|
132 | {
|
---|
133 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
134 | if (((*iter)->*condition)(t))
|
---|
135 | (copy->*f)((*iter));
|
---|
136 | }
|
---|
137 | };
|
---|
138 | template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T), T t ) const
|
---|
139 | {
|
---|
140 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
141 | if (((*iter)->*condition)(t))
|
---|
142 | (copy->*f)((*iter));
|
---|
143 | }
|
---|
144 | };
|
---|
145 | template <typename res, typename T> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T) const, T t ) const
|
---|
146 | {
|
---|
147 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
148 | if (((*iter)->*condition)(t))
|
---|
149 | (copy->*f)((*iter));
|
---|
150 | }
|
---|
151 | };
|
---|
152 | // two arguments
|
---|
153 | template <typename res, typename T, typename U> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U), T t, U u ) const
|
---|
154 | {
|
---|
155 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
156 | if (((*iter)->*condition)(t,u))
|
---|
157 | (copy->*f)((*iter));
|
---|
158 | }
|
---|
159 | };
|
---|
160 | template <typename res, typename T, typename U> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U) const, T t, U u ) const
|
---|
161 | {
|
---|
162 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
163 | if (((*iter)->*condition)(t,u))
|
---|
164 | (copy->*f)((*iter));
|
---|
165 | }
|
---|
166 | };
|
---|
167 | template <typename res, typename T, typename U> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U), T t, U u ) const
|
---|
168 | {
|
---|
169 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
170 | if (((*iter)->*condition)(t,u))
|
---|
171 | (copy->*f)((*iter));
|
---|
172 | }
|
---|
173 | };
|
---|
174 | template <typename res, typename T, typename U> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U) const, T t, U u ) const
|
---|
175 | {
|
---|
176 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
177 | if (((*iter)->*condition)(t,u))
|
---|
178 | (copy->*f)((*iter));
|
---|
179 | }
|
---|
180 | };
|
---|
181 | // three arguments
|
---|
182 | template <typename res, typename T, typename U, typename V> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U, V), T t, U u, V v ) const
|
---|
183 | {
|
---|
184 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
185 | if (((*iter)->*condition)(t,u,v))
|
---|
186 | (copy->*f)((*iter));
|
---|
187 | }
|
---|
188 | };
|
---|
189 | template <typename res, typename T, typename U, typename V> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U, V) const, T t, U u, V v ) const
|
---|
190 | {
|
---|
191 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
192 | if (((*iter)->*condition)(t,u,v))
|
---|
193 | (copy->*f)((*iter));
|
---|
194 | }
|
---|
195 | };
|
---|
196 | template <typename res, typename T, typename U, typename V> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U, V), T t, U u, V v ) const
|
---|
197 | {
|
---|
198 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
199 | if (((*iter)->*condition)(t,u,v))
|
---|
200 | (copy->*f)((*iter));
|
---|
201 | }
|
---|
202 | };
|
---|
203 | template <typename res, typename T, typename U, typename V> void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U, V) const, T t, U u, V v ) const
|
---|
204 | {
|
---|
205 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
206 | if (((*iter)->*condition)(t,u,v))
|
---|
207 | (copy->*f)((*iter));
|
---|
208 | }
|
---|
209 | };
|
---|
210 |
|
---|
211 | // ================== Acting on all Atoms ========================== //
|
---|
212 |
|
---|
213 | // zero arguments
|
---|
214 | template <typename res, typename typ> void molecule::ActOnAllAtoms( res (typ::*f)()) const
|
---|
215 | {
|
---|
216 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
217 | ((*iter)->*f)();
|
---|
218 | }
|
---|
219 | };
|
---|
220 | template <typename res, typename typ> void molecule::ActOnAllAtoms( res (typ::*f)() const) const
|
---|
221 | {
|
---|
222 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
223 | ((*iter)->*f)();
|
---|
224 | }
|
---|
225 | };
|
---|
226 | // one argument
|
---|
227 | template <typename res, typename typ, typename T> void molecule::ActOnAllAtoms( res (typ::*f)(T), T t ) const
|
---|
228 | {
|
---|
229 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
230 | ((*iter)->*f)(t);
|
---|
231 | }
|
---|
232 | };
|
---|
233 | template <typename res, typename typ, typename T> void molecule::ActOnAllAtoms( res (typ::*f)(T) const, T t ) const
|
---|
234 | {
|
---|
235 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
236 | ((*iter)->*f)(t);
|
---|
237 | }
|
---|
238 | };
|
---|
239 | // two argument
|
---|
240 | template <typename res, typename typ, typename T, typename U> void molecule::ActOnAllAtoms( res (typ::*f)(T, U), T t, U u ) const
|
---|
241 | {
|
---|
242 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
243 | ((*iter)->*f)(t, u);
|
---|
244 | }
|
---|
245 | };
|
---|
246 | template <typename res, typename typ, typename T, typename U> void molecule::ActOnAllAtoms( res (typ::*f)(T, U) const, T t, U u ) const
|
---|
247 | {
|
---|
248 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
249 | ((*iter)->*f)(t, u);
|
---|
250 | }
|
---|
251 | };
|
---|
252 | // three argument
|
---|
253 | template <typename res, typename typ, typename T, typename U, typename V> void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V), T t, U u, V v) const
|
---|
254 | {
|
---|
255 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
256 | ((*iter)->*f)(t, u, v);
|
---|
257 | }
|
---|
258 | };
|
---|
259 | template <typename res, typename typ, typename T, typename U, typename V> void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V) const, T t, U u, V v) const
|
---|
260 | {
|
---|
261 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
262 | ((*iter)->*f)(t, u, v);
|
---|
263 | }
|
---|
264 | };
|
---|
265 | // four arguments
|
---|
266 | template <typename res, typename typ, typename T, typename U, typename V, typename W> void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V, W), T t, U u, V v, W w) const
|
---|
267 | {
|
---|
268 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
269 | ((*iter)->*f)(t, u, v, w);
|
---|
270 | }
|
---|
271 | };
|
---|
272 | template <typename res, typename typ, typename T, typename U, typename V, typename W> void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V, W) const, T t, U u, V v, W w) const
|
---|
273 | {
|
---|
274 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
275 | ((*iter)->*f)(t, u, v, w);
|
---|
276 | }
|
---|
277 | };
|
---|
278 |
|
---|
279 | // ===================== Accessing arrays indexed by some integer for each atom ======================
|
---|
280 |
|
---|
281 | // for atom ints
|
---|
282 | template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *) ) const
|
---|
283 | {
|
---|
284 | int inc = 1;
|
---|
285 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
286 | (*Setor) (&array[((*iter)->*index)], &inc);
|
---|
287 | }
|
---|
288 | };
|
---|
289 | template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *), T value ) const
|
---|
290 | {
|
---|
291 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
292 | (*Setor) (&array[((*iter)->*index)], &value);
|
---|
293 | }
|
---|
294 | };
|
---|
295 | template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *), T *value ) const
|
---|
296 | {
|
---|
297 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
298 | (*Setor) (&array[((*iter)->*index)], value);
|
---|
299 | }
|
---|
300 | };
|
---|
301 | // for element ints
|
---|
302 | template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *) ) const
|
---|
303 | {
|
---|
304 | int inc = 1;
|
---|
305 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
306 | (*Setor) (&array[((*iter)->getType()->*index)], &inc);
|
---|
307 | }
|
---|
308 | };
|
---|
309 | template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *), T value ) const
|
---|
310 | {
|
---|
311 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
312 | (*Setor) (&array[((*iter)->getType()->*index)], &value);
|
---|
313 | }
|
---|
314 | };
|
---|
315 | template <typename T> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *), T *value ) const
|
---|
316 | {
|
---|
317 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
318 | (*Setor) (&array[((*iter)->getType()->*index)], value);
|
---|
319 | }
|
---|
320 | };
|
---|
321 |
|
---|
322 | template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ atom::*value ) const
|
---|
323 | {
|
---|
324 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
325 | array[((*iter)->*index)] = ((*iter)->*Setor) ((*iter)->*value);
|
---|
326 | }
|
---|
327 | };
|
---|
328 | template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ atom::*value ) const
|
---|
329 | {
|
---|
330 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
331 | array[((*iter)->*index)] = ((*iter)->*Setor) ((*iter)->*value);
|
---|
332 | }
|
---|
333 | };
|
---|
334 | template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ &vect ) const
|
---|
335 | {
|
---|
336 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
337 | array[((*iter)->*index)] = ((*iter)->*Setor) (vect);
|
---|
338 | }
|
---|
339 | };
|
---|
340 | template <typename T, typename typ> void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ &vect ) const
|
---|
341 | {
|
---|
342 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
343 | array[((*iter)->*index)] = ((*iter)->*Setor) (vect);
|
---|
344 | }
|
---|
345 | };
|
---|
346 | template <typename T, typename typ, typename typ2> void molecule::SetAtomValueToIndexedArray ( T *array, int typ::*index, T typ2::*value ) const
|
---|
347 | {
|
---|
348 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
349 | (*iter)->*value = array[((*iter)->*index)];
|
---|
350 | //Log() << Verbose(2) << *(*iter) << " gets " << ((*iter)->*value); << endl;
|
---|
351 | }
|
---|
352 | };
|
---|
353 |
|
---|
354 | template <typename T, typename typ> void molecule::SetAtomValueToValue ( T value, T typ::*ptr ) const
|
---|
355 | {
|
---|
356 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
|
---|
357 | (*iter)->*ptr = value;
|
---|
358 | //Log() << Verbose(2) << *(*iter) << " gets " << ((*iter)->*ptr) << endl;
|
---|
359 | }
|
---|
360 | };
|
---|
361 |
|
---|
362 |
|
---|
363 | #endif /* MOLECULE_TEMPLATE_HPP_ */
|
---|