TPIE

2362a60
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 {
29 
30 namespace pipelining {
31 
32 namespace parallel_bits {
33 
37 template <typename fact_t>
38 class factory : public factory_base {
39  fact_t fact;
40  const options opts;
41 public:
42 
43  template <typename dest_t>
44  struct constructed {
45  typedef typename push_type<dest_t>::type T2;
46 
47  typedef after<T2> after_t;
48  typedef typename fact_t::template constructed<after_t>::type processor_t;
49  typedef typename push_type<processor_t>::type T1;
50 
51  typedef producer<T1, T2> type;
52  };
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  typename constructed<dest_t>::type
62  construct(dest_t && dest) {
63  typedef constructed<dest_t> gen_t;
64 
65  typedef typename gen_t::T1 input_type;
66  typedef typename gen_t::T2 output_type;
67  typedef state<input_type, output_type> state_t;
68 
70 
71  typedef typename gen_t::type producer_t;
72 
73  typename state_t::ptr st(new state_t(opts, std::move(fact)));
74 
75  consumer_t consumer(std::move(dest), st);
76  this->init_node(consumer);
77  producer_t producer(st, std::move(consumer));
78  this->init_node(producer);
79  return producer;
80  }
81 
82  template <typename dest_t>
83  typename constructed<dest_t>::type
84  construct_copy(dest_t && dest) {
85  return construct(std::forward(dest));
86  }
87 
88 
89 };
90 
91 } // namespace parallel_bits
92 
93 } // namespace pipelining
94 
95 } // namespace tpie
96 
97 #endif // __TPIE_PIPELINING_PARALLEL_FACTORY_H__
Base class of all pipelining factories.
Definition: factory_base.h:73
void init_node(node &r)
Initialize node constructed in a subclass.
Definition: factory_base.h:134
Factory instantiating a parallel multithreaded pipeline.
Definition: factory.h:38
Class to deduce the item_type of a node of type T.
Definition: node_traits.h:152
Accepts output items and sends them to the main thread.
Definition: base.h:44
Node running in main thread, accepting an output buffer from the managing producer and forwards them ...
Definition: base.h:371
User-supplied options to the parallelism framework.
Definition: options.h:34
State subclass containing the item type specific state, i.e.
Definition: base.h:46
Producer, running in main thread, managing the parallel execution.
Definition: base.h:773
Concrete consumer implementation.
Definition: base.h:737