TPIE

11a2c2d
factory.h
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2013, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
20 #ifndef __TPIE_PIPELINING_PARALLEL_FACTORY_H__
21 #define __TPIE_PIPELINING_PARALLEL_FACTORY_H__
22 
23 #include <tpie/pipelining/factory_base.h>
24 #include <tpie/pipelining/parallel/options.h>
25 #include <tpie/pipelining/parallel/base.h>
26 #include <tpie/pipelining/node.h>
27 
28 namespace tpie::pipelining::parallel_bits {
29 
33 template <typename fact_t>
34 class factory : public factory_base {
35  fact_t fact;
36  const options opts;
37 public:
38 
39  template <typename dest_t>
40  struct constructed {
41  typedef typename push_type<dest_t>::type T2;
42 
43  typedef after<T2> after_t;
44  typedef typename fact_t::template constructed_type<after_t> processor_t;
45  typedef typename push_type<processor_t>::type T1;
46 
47  typedef producer<T1, T2> type;
48  };
49 
50 
51  template <typename dest_t>
52  using constructed_type = typename constructed<dest_t>::type;
53 
54  factory(fact_t && fact, options && opts)
55  : fact(std::move(fact))
56  , opts(std::move(opts))
57  {
58  }
59 
60  template <typename dest_t>
61  constructed_type<dest_t> construct(dest_t && dest) {
62  typedef constructed<dest_t> gen_t;
63 
64  typedef typename gen_t::T1 input_type;
65  typedef typename gen_t::T2 output_type;
66  typedef state<input_type, output_type> state_t;
67 
69 
70  typedef typename gen_t::type producer_t;
71 
72  typename state_t::ptr st(new state_t(opts, std::move(fact)));
73 
74  consumer_t consumer(std::move(dest), st);
75  this->init_node(consumer);
76  producer_t producer(st, std::move(consumer));
77  this->init_node(producer);
78  return producer;
79  }
80 
81  template <typename dest_t>
82  constructed_type<dest_t> construct_copy(dest_t && dest) {
83  return construct(std::forward(dest));
84  }
85 
86 
87 };
88 
89 } // namespace tpie::pipelining::parallel_bits
90 
91 #endif // __TPIE_PIPELINING_PARALLEL_FACTORY_H__
tpie::pipelining::parallel_bits::consumer
Node running in main thread, accepting an output buffer from the managing producer and forwards them ...
Definition: base.h:370
tpie::pipelining::factory_base::init_node
void init_node(node &r)
\Brief Initialize node constructed in a subclass.
tpie::pipelining::parallel_bits::factory
Factory instantiating a parallel multithreaded pipeline.
Definition: factory.h:34
tpie::pipelining::parallel_bits::consumer_impl
Concrete consumer implementation.
Definition: base.h:745
tpie::pipelining::push_type
Class to deduce the item_type of a node of type T.
Definition: node_traits.h:158
tpie::pipelining::parallel_bits::after
Accepts output items and sends them to the main thread.
Definition: base.h:41
tpie::pipelining::parallel_bits::state
State subclass containing the item type specific state, i.e.
Definition: base.h:43
tpie::pipelining::factory_base
Base class of all pipelining factories.
Definition: factory_base.h:73
tpie::pipelining::parallel_bits::producer
Producer, running in main thread, managing the parallel execution.
Definition: base.h:781
tpie::pipelining::parallel_bits::factory::constructed
Definition: factory.h:40
tpie::pipelining::parallel_bits::options
User-supplied options to the parallelism framework.
Definition: options.h:30