OGS
SerialExecutor.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <cassert>
7#include <cstddef>
8#include <utility>
9#include <vector>
10
11namespace NumLib
12{
14{
38 template <typename F, typename C, typename... Args_>
39 static void executeDereferenced(F const& f, C const& c, Args_&&... args)
40 {
41 for (std::size_t i = 0; i < c.size(); i++)
42 {
43 f(i, *c[i], std::forward<Args_>(args)...);
44 }
45 }
46
60 template <typename Container, typename Object, typename Method,
61 typename... Args>
62 static void executeMemberDereferenced(Object& object, Method method,
63 Container const& container,
64 Args&&... args)
65 {
66 for (std::size_t i = 0; i < container.size(); i++)
67 {
68 (object.*method)(i, *container[i], std::forward<Args>(args)...);
69 }
70 }
71
87 template <typename Container, typename Object, typename Method,
88 typename... Args>
90 Object& object, Method method, Container const& container,
91 std::vector<std::size_t> const& active_container_ids, Args&&... args)
92 {
93 if (active_container_ids.empty())
94 {
95 executeMemberDereferenced(object, method, container,
96 std::forward<Args>(args)...);
97 return;
98 }
99
100 for (auto const id : active_container_ids)
101 {
102 (object.*method)(id, *container[id], std::forward<Args>(args)...);
103 }
104 }
105
117 template <typename Container, typename Method, typename... Args>
118 static void executeMemberOnDereferenced(Method method,
119 Container const& container,
120 Args&&... args)
121 {
122 for (std::size_t i = 0; i < container.size(); i++)
123 {
124 ((*container[i]).*method)(i, std::forward<Args>(args)...);
125 }
126 }
127
142 template <typename Container, typename Method, typename... Args>
144 Method method, Container const& container,
145 std::vector<std::size_t> const& active_container_ids, Args&&... args)
146 {
147 if (active_container_ids.empty())
148 {
149 executeMemberOnDereferenced(method, container,
150 std::forward<Args>(args)...);
151 return;
152 }
153
154 for (auto const id : active_container_ids)
155 {
156 ((*container[id]).*method)(id, std::forward<Args>(args)...);
157 }
158 }
159
177 template <typename F, typename C, typename Data, typename... Args_>
178 static void transformDereferenced(F const& f, C const& c, Data& data,
179 Args_&&... args)
180 {
181 assert(c.size() == data.size());
182
183 for (std::size_t i = 0; i < c.size(); i++)
184 {
185 data[i] = f(i, *c[i], std::forward<Args_>(args)...);
186 }
187 }
188};
189
190} // 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 executeSelectedMemberDereferenced(Object &object, Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
static void executeMemberOnDereferenced(Method method, Container const &container, Args &&... args)
static void executeMemberDereferenced(Object &object, Method method, Container const &container, Args &&... args)
static void executeDereferenced(F const &f, C const &c, Args_ &&... args)