GrPPI  1.0
Generic and Reusable Parallel Pattern Interface
iteration_nodes.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Universidad Carlos III de Madrid
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef GRPPI_FF_DETAIL_ITERATION_NODES_H
17 #define GRPPI_FF_DETAIL_ITERATION_NODES_H
18 
19 #include <vector>
20 
21 #include <ff/node.hpp>
22 
23 namespace grppi {
24 
25 namespace detail_ff {
26 
27 template<typename Item, typename Iteration>
28 class iteration_worker : public ff::ff_node_t<Item> {
29 public:
30  iteration_worker(Iteration && iteration) :
31  iteration_{std::move(iteration)}
32  {}
33 
34  Item * svc(Item * p_item) {
35  do {
36  *p_item = iteration_.transform(*p_item);
37  }
38  while (!iteration_.predicate(*p_item));
39  return p_item;
40  }
41 
42 private:
43  Iteration iteration_;
44 };
45 
46 } // namespace detail_ff
47 
48 } // namespace grppi
49 
50 #endif
Definition: iteration_nodes.h:28
iteration_worker(Iteration &&iteration)
Definition: iteration_nodes.h:30
Item * svc(Item *p_item)
Definition: iteration_nodes.h:34
Definition: callable_traits.h:21