OGS 6.2.0-244-g47b8a9a9d
SerialExecutor.h
Go to the documentation of this file.
1 
13 #pragma once
14 
15 #include <cassert>
16 #include <cstddef>
17 #include <utility>
18 #include <vector>
19 
20 namespace NumLib
21 {
23 {
47  template <typename F, typename C, typename... Args_>
48  static void
49  executeDereferenced(F const& f, C const& c, Args_&&... args)
50  {
51  for (std::size_t i = 0; i < c.size(); i++)
52  {
53  f(i, *c[i], std::forward<Args_>(args)...);
54  }
55  }
56 
70  template <typename Container, typename Object, typename Method,
71  typename... Args>
72  static void executeMemberDereferenced(Object& object, Method method,
73  Container const& container,
74  Args&&... args)
75  {
76  for (std::size_t i = 0; i < container.size(); i++)
77  {
78  (object.*method)(i, *container[i], std::forward<Args>(args)...);
79  }
80  }
81 
97  template <typename Container, typename Object, typename Method,
98  typename... Args>
100  Object& object, Method method, Container const& container,
101  std::vector<std::size_t> const& active_container_ids, Args&&... args)
102  {
103  if (active_container_ids.empty())
104  {
105  executeMemberDereferenced(object, method, container,
106  std::forward<Args>(args)...);
107  return;
108  }
109 
110  for (std::size_t i = 0; i < active_container_ids.size(); i++)
111  {
112  (object.*method)(i, *container[active_container_ids[i]],
113  std::forward<Args>(args)...);
114  }
115  }
116 
128  template <typename Container, typename Method, typename... Args>
129  static void executeMemberOnDereferenced(Method method,
130  Container const& container,
131  Args&&... args)
132  {
133  for (std::size_t i = 0; i < container.size(); i++)
134  {
135  ((*container[i]).*method)(i, std::forward<Args>(args)...);
136  }
137  }
138 
153  template <typename Container, typename Method, typename... Args>
155  Method method, Container const& container,
156  std::vector<std::size_t> const& active_container_ids, Args&&... args)
157  {
158  if (active_container_ids.empty())
159  {
160  executeMemberOnDereferenced(method, container,
161  std::forward<Args>(args)...);
162  return;
163  }
164 
165  for (std::size_t i = 0; i < active_container_ids.size(); i++)
166  {
167  ((*container[active_container_ids[i]]).*method)(
168  i, std::forward<Args>(args)...);
169  }
170  }
171 
189  template <typename F, typename C, typename Data, typename... Args_>
190  static void transformDereferenced(F const& f, C const& c, Data& data,
191  Args_&&... args)
192  {
193  assert(c.size() == data.size());
194 
195  for (std::size_t i = 0; i < c.size(); i++)
196  {
197  f(i, *c[i], data[i], std::forward<Args_>(args)...);
198  }
199  }
200 };
201 
202 } // namespace NumLib
static void executeSelectedMemberOnDereferenced(Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
static void transformDereferenced(F const &f, C const &c, Data &data, Args_ &&... args)
static void executeMemberOnDereferenced(Method method, Container const &container, Args &&... args)
static void executeDereferenced(F const &f, C const &c, Args_ &&... args)
static void executeMemberDereferenced(Object &object, Method method, Container const &container, Args &&... args)
static void executeSelectedMemberDereferenced(Object &object, Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)