group_particles
Loading...
Searching...
No Matches
callback_utils_select.hpp
Go to the documentation of this file.
1
6#ifndef CALLBACK_UTILS_SELECT_HPP
7#define CALLBACK_UTILS_SELECT_HPP
8
9#include <cassert>
10#include <utility>
11#include <functional>
12
13#include "callback.hpp"
14
15namespace CallbackUtils {
16
19namespace select
20{
21
30 template<typename AFields>
32 virtual public Callback<AFields>
33 {// {{{
35 static constexpr size_t buf_size = 64UL;
36 size_t N_selects = 0UL;
37 std::pair<void *, std::function<bool(void *, const GrpProperties &)>> selectors[buf_size];
38 protected :
39 void register_select (void *obj, std::function<bool(void *, const GrpProperties &)> fct)
40 {
41 selectors[N_selects++] = std::make_pair(obj, fct);
42 assert(N_selects < buf_size);
43 }
44 public :
45 bool grp_select (const GrpProperties &grp) const override final
46 {
47 for (size_t ii=0; ii != N_selects; ++ii)
48 if (!selectors[ii].second(selectors[ii].first, grp))
49 return false;
50 return true;
51 }
52 };// }}}
53
62 template<typename AFields, typename Child>
64 virtual public Callback<AFields>,
65 virtual private MultiSelectBase<AFields>
66 {// {{{
68 static bool this_grp_select_static (void *obj, const GrpProperties &grp)
69 {
70 Child *p = (Child *)obj;
71 return p->this_grp_select(grp);
72 }
73 protected :
77 virtual bool this_grp_select (const GrpProperties &grp) const = 0;
78 public :
80 {
81 MultiSelectBase<AFields>::register_select(this, this_grp_select_static);
82 }
83 };// }}}
84
89 template<typename AFields, typename Field>
90 class Window :
91 virtual public Callback<AFields>,
92 private MultiSelect<AFields, Window<AFields, Field>>
93 {// {{{
96 static_assert(Field::dim == 1);
97 static_assert(Field::type == FieldTypes::GrpFld);
98 static_assert(std::is_floating_point_v<typename Field::value_type>);
99
100 typename Field::value_type min_val, max_val;
101
102 bool this_grp_select (const GrpProperties &grp) const override final
103 {
104 auto x = grp.template get<Field>();
105 return x > min_val && x < max_val;
106 }
107 public :
111 Window (typename Field::value_type min_val_, typename Field::value_type max_val_) :
112 min_val { min_val_ }, max_val { max_val_ }
113 { }
114 };// }}}
115
120 template<typename AFields, typename Field>
121 struct LowCutoff :
122 virtual public Callback<AFields>,
123 private Window<AFields, Field>
124 {// {{{
127 LowCutoff (typename Field::value_type min_val) :
128 Window<AFields, Field> { min_val, std::numeric_limits<typename Field::value_type>::max() } { }
129 };// }}}
130
135 template<typename AFields, typename Field>
136 struct HighCutoff :
137 virtual public Callback<AFields>,
138 private Window<AFields, Field>
139 {// {{{
142 HighCutoff (typename Field::value_type max_val) :
143 Window<AFields, Field> { std::numeric_limits<typename Field::value_type>::min(), max_val } { }
144 };// }}}
145
146} // namespace select
147
148} // namespace CallbackUtils
149
150
151#endif // CALLBACK_UTILS_SELECT_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 apply multiple selection functions in Callback::grp_select.
Definition callback_utils_select.hpp:33
interface class to include a selection function in Callback::grp_select.
Definition callback_utils_select.hpp:66
virtual bool this_grp_select(const GrpProperties &grp) const =0
select only groups that have some 1-dimensional property fall into an interval.
Definition callback_utils_select.hpp:93
Window(typename Field::value_type min_val_, typename Field::value_type max_val_)
Definition callback_utils_select.hpp:111
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
select only groups that have some 1-dimensional property below a certain value.
Definition callback_utils_select.hpp:139
HighCutoff(typename Field::value_type max_val)
Definition callback_utils_select.hpp:142
select only groups that have some 1-dimensional property above a certain value.
Definition callback_utils_select.hpp:124
LowCutoff(typename Field::value_type min_val)
Definition callback_utils_select.hpp:127