group_particles
Loading...
Searching...
No Matches
callback_utils_grp_action.hpp
Go to the documentation of this file.
1
7#ifndef CALLBACK_UTILS_GRP_ACTION_HPP
8#define CALLBACK_UTILS_GRP_ACTION_HPP
9
10#include <cassert>
11#include <functional>
12#include <vector>
13#include <type_traits>
14#include <cstdio>
15
16#include "callback.hpp"
17
18namespace CallbackUtils {
19
22namespace grp_action {
23
29 template<typename AFields>
31 virtual public Callback<AFields>
32 {// {{{
34
35 static constexpr size_t buf_size = 64UL;
36 size_t N_actions = 0UL;
37 std::pair<void *, std::function<void(void *, const GrpProperties &)>> grp_actions[buf_size];
38 protected :
39 void register_fct (void *obj, std::function<void(void *, const GrpProperties &)> fct)
40 {
41 grp_actions[N_actions++] = std::make_pair(obj, fct);
42 assert(N_actions < buf_size);
43 }
44 public :
45 void grp_action (const GrpProperties &grp) override final
46 {
47 for (size_t ii=0; ii != N_actions; ++ii)
48 grp_actions[ii].second(grp_actions[ii].first, grp);
49 }
50 };// }}}
51
60 template<typename AFields, typename Child>
62 virtual public Callback<AFields>,
63 virtual private MultiGrpActionBase<AFields>
64 {// {{{
66 static void this_grp_action_static (void *obj, const GrpProperties &grp)
67 {
68 Child *p = (Child *)obj;
69 p->this_grp_action(grp);
70 }
71 protected :
75 virtual void this_grp_action (const GrpProperties &grp) = 0;
76 public :
78 {
79 MultiGrpActionBase<AFields>::register_fct(this, this_grp_action_static);
80 }
81 };// }}}
82
87 template<typename AFields, typename Tdata>
89 virtual public Callback<AFields>,
90 private MultiGrpAction<AFields, StoreGrpHomogeneous<AFields, Tdata>>
91 {// {{{
94 std::vector<Tdata> &data;
95 void this_grp_action (const GrpProperties &grp) override final
96 {
97 data.push_back(grp_reduce(grp));
98 }
99 protected :
105 virtual Tdata grp_reduce (const GrpProperties &grp) const = 0;
106 public :
110 StoreGrpHomogeneous (std::vector<Tdata> &data_) :
111 data(data_)
112 { }
113 };// }}}
114
122 template<typename AFields, typename Field, typename storeasT = typename Field::value_type>
124 virtual public Callback<AFields>,
125 private StoreGrpHomogeneous<AFields, storeasT>
126 {// {{{
127 static_assert(Field::dim == 1, "Currently not implemented, could probably be done");
128 static_assert(std::is_arithmetic_v<storeasT>);
129 storeasT grp_reduce (const typename Callback<AFields>::GrpProperties &grp) const override final
130 {
131 return grp.template get<Field>();
132 }
133 public :
136 StoreGrpProperty (std::vector<storeasT> &data) :
137 StoreGrpHomogeneous<AFields, storeasT>(data)
138 { }
139 };// }}}
140
141} // namespace grp_action
142
143} // namespace CallbackUtils
144
145#endif // CALLBACK_UTILS_GRP_ACTION_HPP
Contains the abstract base class that the user should subclass from in order to define the desired fu...
Specialization of the Callback::BaseProperties type to groups.
Definition callback.hpp:85
base class to have multiple actions performed in Callback::grp_action
Definition callback_utils_grp_action.hpp:32
interface class to add an action to be performed during Callback::grp_action
Definition callback_utils_grp_action.hpp:64
virtual void this_grp_action(const GrpProperties &grp)=0
implements the common case of storing a data item of identical type for each group.
Definition callback_utils_grp_action.hpp:91
StoreGrpHomogeneous(std::vector< Tdata > &data_)
Definition callback_utils_grp_action.hpp:110
virtual Tdata grp_reduce(const GrpProperties &grp) const =0
implements the common case of storing a single group property for each group.
Definition callback_utils_grp_action.hpp:126
StoreGrpProperty(std::vector< storeasT > &data)
Definition callback_utils_grp_action.hpp:136
contains classes that implement parts of the Callback base.
Definition callback_utils.hpp:35
The abstract base class the user should inherit from.
Definition callback.hpp:32