GrPPI  0.3.1
Generic and Reusable Parallel Pattern Interface
simple_node.h
Go to the documentation of this file.
1 
21 #ifndef GRPPI_FF_DETAIL_SIMPLE_NODE_H
22 #define GRPPI_FF_DETAIL_SIMPLE_NODE_H
23 
24 #include "fastflow_allocator.h"
25 
26 #include <ff/allocator.hpp>
27 #include <ff/node.hpp>
28 
29 namespace grppi {
30 
31 namespace detail_ff {
32 
39 template <typename Input, typename Output, typename Transformer>
40 class node_impl : public ff::ff_node_t<Input,Output> {
41 public:
42 
43  node_impl(Transformer && transform_op) :
44  transform_op_{transform_op}
45  {}
46 
47  Output * svc(Input * p_item) {
48  return new (ff_arena) Output{transform_op_(*p_item)};
49  }
50 
51 private:
52  Transformer transform_op_;
53 };
54 
60 template <typename Output, typename Generator>
61 class node_impl<void,Output,Generator> : public ff::ff_node {
62 public:
63 
64  node_impl(Generator && generate_op) :
65  generate_op_{generate_op}
66  {}
67 
68  void * svc(void *) {
69  std::experimental::optional<Output> result{generate_op_()};
70  if (result) {
71  return new (ff_arena) Output{*result};
72  }
73  else {
74  return EOS;
75  }
76  }
77 
78 private:
79  Generator generate_op_;
80 };
81 
87 template <typename Input, typename Consumer>
88 class node_impl<Input,void,Consumer> : public ff::ff_node_t<Input,void> {
89 public:
90 
91  node_impl(Consumer && consume_op) :
92  consume_op_{consume_op}
93  {}
94 
95  void * svc(Input * p_item) {
96  consume_op_(*p_item);
97  operator delete(p_item, ff_arena);
98  return GO_ON;
99  }
100 
101 private:
102  Consumer consume_op_;
103 };
104 
105 
106 } // namespace detail_ff
107 
108 } // namespace grppi
109 
110 #endif
Definition: callable_traits.h:26
constexpr ff_arena_t ff_arena
Fastflow arena object. This object will be passed to placement new/delete to use FastFlow allocation ...
Definition: fastflow_allocator.h:41
Fastflow node for a pipeline transformation stage.
Definition: simple_node.h:40
node_impl(Generator &&generate_op)
Definition: simple_node.h:64
void * svc(Input *p_item)
Definition: simple_node.h:95
node_impl(Consumer &&consume_op)
Definition: simple_node.h:91
node_impl(Transformer &&transform_op)
Definition: simple_node.h:43
Output * svc(Input *p_item)
Definition: simple_node.h:47
void * svc(void *)
Definition: simple_node.h:68